From 99a7ad8744d0fc3235b7e3338a90f1926f24fe28 Mon Sep 17 00:00:00 2001 From: arangrhie Date: Mon, 23 Mar 2020 21:41:24 -0400 Subject: [PATCH] use module only when available --- eval/spectra-cn.sh | 12 +++++++----- trio/block_n_stats.sh | 13 ++++++++++--- trio/hap_blob.sh | 7 ++++++- trio/hapmers.sh | 12 ++++++++---- trio/phase_block.sh | 9 +++++++-- trio/spectra-hap.sh | 11 ++++++++--- trio/switch_error.sh | 9 ++++++++- util/util.sh | 5 +++++ 8 files changed, 59 insertions(+), 19 deletions(-) mode change 100644 => 100755 util/util.sh diff --git a/eval/spectra-cn.sh b/eval/spectra-cn.sh index cdf9866..1224cbf 100755 --- a/eval/spectra-cn.sh +++ b/eval/spectra-cn.sh @@ -38,11 +38,13 @@ if [ -s $name ]; then fi -## Comment this line if R is properly installed ## -echo "Load R" -module load R # -################################################# -echo +has_module=$(check_module) +if [[ $has_module -gt 0 ]]; then + echo "No modules available.." +else + module load R +fi + asm1=`echo $asm1_fa | sed 's/.fasta$//g' | sed 's/.fa$//g' | sed 's/.fasta.gz$//g' | sed 's/.fa.gz$//g'` diff --git a/trio/block_n_stats.sh b/trio/block_n_stats.sh index 893957a..ae7eadb 100755 --- a/trio/block_n_stats.sh +++ b/trio/block_n_stats.sh @@ -31,9 +31,16 @@ else g_size=$4 fi -module load bedtools -module load samtools -module load R +source $MERQURY/util/util.sh + +has_module=$(check_module) +if [[ $has_module -gt 0 ]]; then + echo "No modules available.." +else + module load bedtools + module load samtools + module load R +fi for asm in $asm1 $asm2 do diff --git a/trio/hap_blob.sh b/trio/hap_blob.sh index 1528be4..d62b9b3 100755 --- a/trio/hap_blob.sh +++ b/trio/hap_blob.sh @@ -67,7 +67,12 @@ done echo " Plot hap-mer blob plots" -module load R +has_module=$(check_module) +if [[ $has_module -gt 0 ]]; then + echo "No modules available.." +else + module load R +fi echo " Rscript $MERQURY/plot/plot_blob.R -f $count -o $out.hapmers.blob" diff --git a/trio/hapmers.sh b/trio/hapmers.sh index 934ac04..6e4551c 100755 --- a/trio/hapmers.sh +++ b/trio/hapmers.sh @@ -112,10 +112,14 @@ meryl histogram shrd.inherited.meryl | awk -v kmer="shared" '{print kmer"\t"$1"\ echo echo "# Plot $hist" -## Comment this line if R is properly installed ## -echo "Load R" # -module load R # -################################################## +source $MERQURY/util/util.sh + +has_module=$(check_module) +if [[ $has_module -gt 0 ]]; then + echo "No modules available.." +else + module load R +fi echo Rscript $MERQURY/plot/plot_spectra_cn.R -f $hist -o ${hist/.hist/} -l cutoffs.txt diff --git a/trio/phase_block.sh b/trio/phase_block.sh index 2950891..fc14930 100755 --- a/trio/phase_block.sh +++ b/trio/phase_block.sh @@ -15,8 +15,13 @@ hap1=`link $2` hap2=`link $3` out=$4 -module load bedtools -module load samtools +has_module=$(check_module) +if [[ $has_module -gt 0 ]]; then + echo "No modules available.." +else + module load bedtools + module load samtools +fi k=`meryl print $hap1 | head -n 2 | tail -n 1 | awk '{print length($1)}'` echo "Detected k-mer size: $k" diff --git a/trio/spectra-hap.sh b/trio/spectra-hap.sh index 279ddd8..b2f4cf0 100755 --- a/trio/spectra-hap.sh +++ b/trio/spectra-hap.sh @@ -33,9 +33,14 @@ k=`meryl print $read | head -n 2 | tail -n 1 | awk '{print length($1)}'` echo "Detected k-mer size $k" ## Remove this line if R is properly installed ## -echo "Load R" -module load R # -################################################# +source $MERQURY/util/util.sh + +has_module=$(check_module) +if [[ $has_module -gt 0 ]]; then + echo "No modules available.." +else + module load R +fi read=${read/.meryl/} # all read counts read_hap1=${read_hap1/.meryl/} # pat specific mers with read counts diff --git a/trio/switch_error.sh b/trio/switch_error.sh index fdfb902..f7abf64 100755 --- a/trio/switch_error.sh +++ b/trio/switch_error.sh @@ -48,7 +48,14 @@ echo "Count $hap1 and $hap2 hap-mers per block to $count" echo -e "Block\tRange\t$hap1\t$hap2\tSize" > $count awk -v hap1=$hap1 -v hap2=$hap2 '{ swi=$(NF-1); phase=$NF; {if ($4==hap1) { hap1_cnt=phase; hap2_cnt=swi; } else if ($4==hap2) { hap1_cnt=swi; hap2_cnt=phase; }} {print $4"\t"$1"_"$2"_"$3"\t"hap1_cnt"\t"hap2_cnt"\t"($3-$2)}}' $out.phased_block.bed >> $count -module load R +source $MERQURY/util/util.sh + +has_module=$(check_module) +if [[ $has_module -gt 0 ]]; then + echo "No modules available.." +else + module load R +fi echo " Rscript $MERQURY/plot/plot_blob.R -f $count -o $out.phased_block.blob" diff --git a/util/util.sh b/util/util.sh old mode 100644 new mode 100755 index e757933..9ac618e --- a/util/util.sh +++ b/util/util.sh @@ -9,3 +9,8 @@ function link() echo $db_name } +function check_module() +{ + module -v 1> /dev/null 2> /dev/null + echo $? +}