This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Can I get AddOrReplaceReadGroups working for multiple files?

I have a dataset of 81 samples that are missing read group information. This leads to problems when trying to use GATK commands. I've found picard tools' AddOrReplaceReadGroups to be a helpful tool for adding read group to a SAM file. But I'm having trouble trying to loop through this command for all my files.

I've been able to come up with this, but there seems to be an issue with my notation in my variables;

while read f1
do 
  FileName=$(echo $f1 | cut -d"," -f1)
  SampleID=$(echo $f1 | cut -d"," -f3)
  RowNum=$(grep -n $FileName.bam)
  java -jar picard.jar AddOrReplaceReadGroups \
     I=$FileName.bam \
     O=$FileName"_sort.bam" \
     SORT_ORDER=coordinate \
     RGID=$SampleID \
     RGLB=WGS \
     RGPL=illumina \
     RGPU=$RowNum \
     RGSM=$FileName
done < file_with_sample_information.csv

Note: the input file file_with_sample_information.csv has 4 columns, the 1st has the sample name and the 3rd has the database (ENA) ascension number.

How can I get this too work? I'd like to avoid manually doing this for 81 files.

picard tools bash
grep -n $FileName.bam

will not produce anything. You're grepping stdin

1 answer

while read a b c d; do 
...
...
done < file_with_sample_information.csv

$a is column 1, $b is column 2 and so on.

Just separate a b c d with a space.

Is it trouble assigning variables to filenames? or trouble assigning multiple variables (a, b, c, d)..? Show me the first line of your file

I was trying to assign multiple variables. I figured it out from your example, thanks.

Log in to answer this question.