0

I wasn't sure how to word this question but basically I have been using a shell script to process sam data. Here's the shell script.

nano picard_SortandIndex_from_sam.sh

for A in *sam; do ls $A; picard SortSam I=$A O=$A".bam" SO=coordinate CREATE_INDEX=TRUE; done

And this is the command I run where I get only one .out file for all the sam files processed.

nohup sh picard_SortandIndex_from_sam.sh > picard_SortandIndex_from_sam5_26_21.out &

Is there a way to generate .out files within my "picard_SortandIndex_from_sam.sh" script so I can have a summary file for each sam file processed? I tried to put > $A".out" in there but it didn't work...

Many thanks!

Xiu
  • 1

1 Answers1

1

I think you are looking for this:

for A in *sam; do 
  ls "$A"
  picard SortSam I="$A" O="$A".bam SO=coordinate CREATE_INDEX=TRUE > "$A".out
done

Or, more likely, you want both standard error and standard output, so use this:

for A in *sam; do 
  ls "$A"
  picard SortSam I="$A" O="$A".bam SO=coordinate CREATE_INDEX=TRUE > "$A".out 2>&1
done

This will run picard on each of your sam files, and store the output of the command (> "$A".out) and any errors produced (2>&1) in the file $A.out.

As a final note, since this creates files named foo.sam.bam and foo.sam.bam.bai etc., you might want to remove the .sam from the output name:

 for A in *sam; do 
  ls "$A"
  fileName=$(basename "$A" .sam)
  picard SortSam I="$A" O="$fileName".bam SO=coordinate CREATE_INDEX=TRUE > "$fileName".out 2>&1
done

That will create foo.bam from foo.sam instead of foo.sam.bam.

terdon
  • 242,166