How To Combine Two Samtools Commands.
2
2
Entering edit mode
13.1 years ago
dustar1986 ▴ 380

Hi,

I think this is a stupid question. But please help.

I want to do mpileup on the strand specific reads. I currently use two commands to achieve that. The first one is like this:

samtools view -b -o output.bam -f 0x10 input.sorted.bam

This generates a temporary file, say "output.bam". Then mpileup is applied on it like:

samtools mpileup output.bam|cut -d ' ' -f 1,2 |awk -F '      ' 'BEGIN... END ...'

Is there a solution to combine the two command without creating the temporary file "output.bam"?

I've tried this:

samtools view -f 0x10 input.sorted.bam|samtools mpileup|cut -d ' ' -f 1,2 |awk -F '      ' 'BEGIN... END ...'

But it returns an error coz samtools mpileup needs an input statement.

Please help. Thank you very much.

Dadi

samtools • 19k views
ADD COMMENT
0
Entering edit mode

Hi all,

I am also having the same problem.

I want to pipe the samtools view(sam to bam converter) ,samtools sort and samtools index.

samtools view -S file1.sam -b > file1.bam |  samtools sort - - | samtools index file1.bam

But I am getting error like following:

[bam_header_read] invalid BAM binary header (this is not a BAM file).
[bam_header_read] bgzf_check_EOF: Invalid argument
[bam_header_read] invalid BAM binary header (this is not a BAM file).
[sort_blocks] fail to create file -.bam.
[samopen] SAM header is present: 11692 sequences.
Segmentation fault

Commands working fine without the piping. When I checked I can see the output bam file generated by samtools view.

Please help....

Thanks,
Deeps

ADD REPLY
0
Entering edit mode

Next time please make a seperate question instead of posting your question as an answer. Try to understand what the commands do before putting them together.

samtools view -S file1.sam -b | samtools sort - file1; samtools index file1.bam
ADD REPLY
0
Entering edit mode

Hi All

I have a question. I wish to run bowtie over 3 cores and get an output of aligned sorted and indexed bam files.

bowtie2 -p 3 -x ../genomes/hg38/hg38 -1 tg/1/S1R1_val_1.fq.gz -2 tg/1/S1R2_val_2.fq.gz | samtools view -Shu - | samtools sort - - | samtools index > bam/S1_srt.bam

The above command just foes till sorted how can I also include a index via the pipe such that I get a sorted aligned bam and also the index in the same pipe?

I look forward for your help.

Thanks,
Yaseen

ADD REPLY
1
Entering edit mode

Maybe try posting a new question next time. To answer, try:

bowtie2 -p 3 -x ../genomes/hg38/hg38 -1 tg/1/S1R1_val_1.fq.gz -2 tg/1/S1R2_val_2.fq.gz | samtools view -Sb - | samtools sort - bam/S1_srt; samtools index bam/S1_srt.bam
ADD REPLY
1
Entering edit mode

this is not an answer. ask this as as new question please.

ADD REPLY
8
Entering edit mode
13.1 years ago

try

samtools view -f 0x10 -b input.sorted.bam|samtools mpileup -

instead of

samtools view -f 0x10 input.sorted.bam|samtools mpileup -
ADD COMMENT
2
Entering edit mode

So basically, my answer but with a -b switch ;)

ADD REPLY
0
Entering edit mode

That works! Thank you very much indeed.

ADD REPLY
0
Entering edit mode

I'm sorry Neil ;-)

ADD REPLY
1
Entering edit mode
13.1 years ago
Neilfws 49k

I have not tried it, but the manual states:

Samtools is designed to work on a stream. It regards an input file ‘-’ as the standard input (stdin) and an output file ‘-’ as the standard output (stdout). Several commands can thus be combined with Unix pipes. Samtools always output warning and error messages to the standard error output (stderr).

So you could try inserting "-" to represent the input for mpileup like so:

samtools view -f 0x10 input.sorted.bam | samtools mpileup - | cut -d ' ' -f 1,2 | awk -F '      ' 'BEGIN... END ...'
ADD COMMENT
0
Entering edit mode

Thank you. But actually I've tried -. The bash said [bam_header_read] invalid BAM binary header (this is not a BAM file). I think it recognized - as the filename and gave this error.

ADD REPLY

Login before adding your answer.

Traffic: 1744 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