Question: How To Combine Two Samtools Commands.
2
gravatar for dustar1986
6.0 years ago by
dustar1986260
USA
dustar1986260 wrote:

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 • 8.6k views
ADD COMMENTlink modified 22 months ago by Yaseen Ladak10 • written 6.0 years ago by dustar1986260
8
gravatar for Pierre Lindenbaum
6.0 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum98k wrote:

try

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

instead of

samtools view -f 0x10 input.sorted.bam|samtools mpileup -
ADD COMMENTlink written 6.0 years ago by Pierre Lindenbaum98k
2

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

ADD REPLYlink written 6.0 years ago by Neilfws47k

That works! Thank you very much indeed.

ADD REPLYlink written 6.0 years ago by dustar1986260

I'm sorry Neil ;-)

ADD REPLYlink written 6.0 years ago by Pierre Lindenbaum98k
0
gravatar for Neilfws
6.0 years ago by
Neilfws47k
Sydney, Australia
Neilfws47k wrote:

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 COMMENTlink written 6.0 years ago by Neilfws47k

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 REPLYlink written 6.0 years ago by dustar1986260
0
gravatar for deepthitheresa
5.4 years ago by
Canada
deepthitheresa20 wrote:

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:

[bamheaderread] invalid BAM binary header (this is not a BAM file). [bamheaderread] bgzfcheckEOF: Invalid argument [bamheaderread] 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 COMMENTlink written 5.4 years ago by deepthitheresa20

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 REPLYlink written 5.3 years ago by Ying W3.6k
0
gravatar for Yaseen Ladak
22 months ago by
Yaseen Ladak10
United Kingdom, London, Imperial College London
Yaseen Ladak10 wrote:

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 COMMENTlink written 22 months ago by Yaseen Ladak10
1

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

ADD REPLYlink written 22 months ago by Pierre Lindenbaum98k

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 REPLYlink written 22 months ago by Adrian Pelin2.0k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 651 users visited in the last hour