I want to use SamToFastq in Picard tools to convert 100 bam files to fastq (pair-end). I wrote a loop, but it does not work. Anyone can help me to look at the code. I have no idea what's going on. Appreciate ahead.
#!/bin/bash
bamfolder="/path/to/folder/*"
for b in $bamfolder
do   
    echo $b   
    java -jar picard.jar SamToFastq \
    I=$b \
    FASTQ= /path/to/folder/*_R1.fastq \
    SECOND_END_FASTQ= /path/to/folder/*_R2.fastq
done
                    
                
                
Are you getting anything back from
echo $b. There can be no spaces betweenFASTQ=andSECOND_END_FASTQ=and the paths.When I run echo $b done, It listed all bam files in the folder.
This is academic since @Pierre's solution works but the reason yours is not working is because your are passing
$bas the entire file name (with .bam extension intact). So instead if you try the following and see if that works.I have tried. ERROE: Neither file nor parent directory exist.
I think for the "FASTQ=" and "SECOND_END_FASTQ=" I can not use /path/to/folder/${b%.*}, because it shows output=/path/to/folder/path/to/folder/. If only use FASTQ=${b%.bam}_R1.fq.gz, it works.
As is customary with these
/path/to/folder/is a placeholder that needs to be replaced with a real path available on your computer. It is there to show that you can use/write data from/to any other location.Does not work? How it doesn't work? What is the error message?
Anyway, I think there should not be spaces after
FASTQ=andSECOND_END_FASTQ=.erroe msg is INPUT is required. It's kind wired. I think the I=$b is right....