0

I have this line

samtools view -h file | awk '$3=="chr$a" || /^@/' | samtools view -S - -b -o output

the dash between the -S and the -b is supposed to indicate to the program that it is from STDIN. I can run it from a perl script on the command line but as soon as I try to move it into a shell script it just creates the file without outputting any data. Any ideas would be greatly appreciated.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
user1234579
  • 179
  • 1
  • 1
  • 7

2 Answers2

0

If you haven't already, have a look at the samtools FAQ. This has examples for doing similar things to what you want to do with your pipeline.

Its been a while since I used samtools, but I would've written your command like this:

samtools view -h file | awk '$3=="chr$a" || /^@/' | samtools view -S -b - > output.bam

Also you mentioned you had moved the command to a shell script. Is the shell script doing anything else? If it still doesn't work, I would post that for us to look at.

MattLBeck
  • 5,701
  • 7
  • 40
  • 56
  • the shell script for a in {1..22} do samtools view -h AD3.sorted.bam | awk '$3=="chr$a" || /^@/' | samtools view -S - -b -o chr$a.bam done – user1234579 Mar 02 '12 at 14:36
0

In a shell script the $a inside single quotes will not be expanded:

for a in {1..22} do 
  samtools view -h AD3.sorted.bam | awk '$3=="chr$a" || /^@/' | samtools view -S - -b -o chr$a.bam 
done 
stark
  • 12,615
  • 3
  • 33
  • 50