convert multiple files simultaneously using samtools
1
0
Entering edit mode
3.8 years ago
vanessagpds ▴ 10

Hello everyone, I am new to bioinformatics. I have several files in BAM format and I want to convert them to fastq using samtools.

Is there any way to convert them all at once?

I tried : samtools fastq * .bam > * .fastq but it was failure.

RNA-Seq samtools • 1.8k views
ADD COMMENT
2
Entering edit mode
3.8 years ago
e.ortiz.v ▴ 20

To process one after another:

for file in *.bam; do samtools fastq $file > ${file//.bam/.fastq}; done

If you want to run them simultaneously (let's say 8 at a time) you need to install the program parallel, then:

for file in *.bam; do echo samtools fastq $file ">" ${file//.bam/.fastq} >> tasks.txt; done
parallel -j 8 -a tasks.txt
ADD COMMENT
0
Entering edit mode

try this with parallel: parallel --dry-run 'samtools fastq {} > {.}.fastq' ::: *.bam

ADD REPLY
0
Entering edit mode

Hi e.ortiz.v

Your answer is so helpful. I have a question that

if I have abc.bam and I would like to remove .bam and add nothing and get abs. after that, I will add abs to the string of is it ok to write it in this way

if I just remove and keep the file name

A= test_1.fq.gz -R "@RG\tID:1\tSM:${A[i]//_1.fq.gz}"

result is

-R "@RG\tID:1\tSM: test"

is it correct?

ADD REPLY
0
Entering edit mode

Hi E. Ortiz,

I would like to ask you, please, if would it be possible a similar code for simultaneously to convert many fastq files to respective bam files?. Could you write that code ?. I was trying the above code changing fastq by bam and vice versa, but it doesn't work for me.

Thank you very much.

ADD REPLY

Login before adding your answer.

Traffic: 2466 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6