Dear all, I create a code like this, which solve my problem to separate bam file to each segments, but still time I have one problem and I cannot finish it. I would like to create many outputs (files), which has name, same like variable $h. Than I want one think, if the for cycle for "h" finished, the code create a text fie with same name like $h.txt . I tried this, but it doesnt work:
#!/bin/bash
for h in {1..22..1}
do
for i in {0..249480000..60000}
do
u=$i let "u +=60000"
echo $i"-"$u | samtools view /home/filip/Desktop/Posledni\ NIFTY/019/odfiltrovany019.bam chr$h:$i-$u | awk '{ n=length($10);print gsub(/[GCCgcs]/,"",$10)/n;}'| awk '{s+=$1}END{print NR,s/NR}' > ${h%}.txt
done
done
OTUPUT will be 1.txt, 2.txt, 3.txt, ......., 22.txt. This file will contain information from loop cycle for variable i. Thank you.
1 answer
I would do it using GNU/parallel. See Gnu Parallel - Parallelize Serial Command Line Programs Without Changing Them.
Basically, once you have installed GNU/parallel (not the parallel tool that comes with some linux distributions), you can convert your loop to something like the following:
$: parallel 'chromosome={1}; start={2}; end=$(echo "$start"+60000|bc); echo $chromosome $start $end' ::: $(seq 1 22) ::: $(seq 0 60000 249480000)
1 0 60000
1 60000 120000
1 120000 180000
1 180000 240000
1 240000 300000
1 300000 360000
1 360000 420000
1 420000 480000
1 480000 540000
1 540000 600000
1 600000 660000
1 660000 720000
1 720000 780000
1 780000 840000
.........
Now, you can modify your original command, substituting $h, $i and $u with $chromosome, $start, and $end (if I interpreted your code correctly)
Log in to answer this question.
maybe I am slow this morning but I do not fully understand the question plus the title is somewhat misleading. Could you put an example of the type of output you want ?
I do not know, how could I use > ${h%}.txt , because I want to receive on output txt files, which have name same like variable h. The code i OK, but I do not know how use the output syntax, after each loop (for variable h) I recieve one file with same name (1..22) and it will be filled by loop (for i).
This question is hardly bioinformatics related, apart from the samtools command. Also, I still don't understand what you're asking.