How to execute one command on all files within a directory
1
0
Entering edit mode
4 weeks ago
Kumar ▴ 120

Hi, I have several .fastq (R1 and R2) files in a directory. For example files: 9-Lmm05-P1413070_S9_L001_R1_001.fastq.gz, 9-Lm05-P1413070_S9_L001_R2_001.fastq.gz. I want to run the following command for the all fastq files in the directory and generate separate output directories for each pair (R1 and R2) by their prefix name (e.g. 9-Lmm05-P1413070).

$spades.py -k 21,33,55,77 -1 file1_R1_001.fastq.gz -2 file2_R2_001.fastq.gz -o Assembly  Could you please help to suggest a perl/python script to perform that. Thank you, Python FASTQ Perl • 346 views ADD COMMENT 0 Entering edit mode What have you tried? ADD REPLY 0 Entering edit mode I was trying as following but I think it was not correct. I see where it was wrong as asalimih suggesting. for f in /home/R* do spades.py -k 21,33,55,77 -1$f -2 $f -o${f/_R1*/\/Assembly}
done


0
Entering edit mode
4 weeks ago
asalimih ▴ 30

Here is a bash solution. I assume the Assembly in your example is actually the output file so I replaced it according to your explanation.

for f in *_R1_*
do
$spades.py -k 21,33,55,77 -1$f -2 ${f/R1/R2} -o${f/_R1*/\/Assembly}
done


\${f/R1/R2} is equivalent to replacing R1 with R2 in the name of the file.

0
Entering edit mode

Thank you very much for you help.