2017-02-09 62 views
0

我想重写一个for循环(这很好用)并将其作为并行运行,但我有各种各样的问题。这里是我的循环重写一个for循环与“并行”一起使用

function no_sam { 
    filename=$(basename "$file") 
    extension="${file##*.}" 

    if [ $extension = "sam" ]; 
     then 
     filename="${filename%.*}" 
     feat_out=$filename.out 
     htseq-count -f $types -r "$pos" -m "$mode" -i "$attribute" -s "$strand" -t "$feature" -a "$qual" "$file" "$input_gff" > "$feat_out" 
     grep -v "_" "$feat_out" > temp && mv temp "$feat_out" 
     mv "$feat_out" "$counts_folder" 
    elif [ $extension = "bam" ]; 
     then 
     filename="${filename%.*}" 
     feat_out=$filename.out 
     htseq-count -f $types -r "$pos" -m "$mode" -i "$attribute" -s "$strand" -t "$feature" -a "$qual" "$file" "$input_gff" > "$feat_out" 
     grep -v "_" "$feat_out" > temp && mv temp "$feat_out" 
     mv "$feat_out" "$counts_folder" 
    fi  
} 

for file in "${multi[@]}"; do 
    no_sam 
done 

当我更换了与GNU并行循环,我得到错误

"${multi[@]}" no_sam | parallel 

testfile.sam: command not found 
+0

通过shellcheck.net和'bash -x'运行你的脚本。 – codeforester

+0

我已经做了。这是我如何运行“并行”软件的问题。 – upendra

+0

您是否解决了shellcheck报告的问题? – codeforester

回答

0

试试这个(基于https://www.gnu.org/software/parallel/man.html#EXAMPLE:-Using-shell-variableshttps://www.gnu.org/software/parallel/man.html#EXAMPLE:-Calling-Bash-functions):

function no_sam { 
    file="$1" 
    filename=$(basename "$file") 
    extension="${file##*.}" 

    if [ $extension = "sam" ]; 
     then 
     filename="${filename%.*}" 
     feat_out=$filename.out 
     htseq-count -f $types -r "$pos" -m "$mode" -i "$attribute" -s "$strand" -t "$feature" -a "$qual" "$file" "$input_gff" > "$feat_out" 
     grep -v "_" "$feat_out" > temp && mv temp "$feat_out" 
     mv "$feat_out" "$counts_folder" 
    elif [ $extension = "bam" ]; 
     then 
     filename="${filename%.*}" 
     feat_out=$filename.out 
     htseq-count -f $types -r "$pos" -m "$mode" -i "$attribute" -s "$strand" -t "$feature" -a "$qual" "$file" "$input_gff" > "$feat_out" 
     grep -v "_" "$feat_out" > temp && mv temp "$feat_out" 
     mv "$feat_out" "$counts_folder" 
    fi  
} 
export -f no_sam 

parallel no_sam ::: "${multi[@]}" 

从您尝试使用GNU Parallel的方式来看,我认为您将从步行穿过man parallel_tutorial花费一个小时获益。 你的命令行会爱你。