Error in samtools view
2
0
Entering edit mode
6.7 years ago
Bella_p ▴ 70

Hi,

As part of my chip seq analysis, I tried to run a script to convert fastq file into .bam file without the creation of a .sam file (using piping). This is the script:

${bowtie2_source} -x ${ref_genome} -U ${fastq_file} -S | ${samtools} view -bS - ${target_dir}/${sample_name}.bam

unfortunately, I recieved the following error: [main_samview] random alignment retrieval only works for indexed BAM or CRAM files. How can I fix this?

samtools ChIP-Seq bash bowtie2 • 5.0k views
ADD COMMENT
0
Entering edit mode

If an answer was helpful you should upvote it, if the answer resolved your question you should mark it as accepted. Please do the same for your previous posts as well.

Upvote|Bookmark|Accept

ADD REPLY
1
Entering edit mode

Pierre has the right answer. The way you have written it, the software thinks that you want to look at all entries in the bam that have the chromosome name ${target_dir}/${sample_name}. This can't be done unless the sam/bam has an index, so the software is complaining.

ADD REPLY
3
Entering edit mode
6.7 years ago

you wrote:

 ${samtools} view -bS - ${target_dir}/${sample_name}.bam

you want

 ${samtools} view -bS -o ${target_dir}/${sample_name}.bam -
ADD COMMENT
0
Entering edit mode

Great, that works perfectly. Excuse me but I'm a begginer and trying to write a pipeline for ChipSeq using Bowtie2. I'm trying to convert fastq file into sorted bam file, without duplicates. I wrote the following command:

${bowtie2_source} -x ${indexed_hg18} -U ${fastq_file} -S | ${samtools} view -bS | ${samtools} sort | ${samtools} rmdup -S ${target_dir}/${sample_name}.bam

Is it Ok in your opinion? or do I need to add at the end also -o ?

ADD REPLY
1
Entering edit mode

samtools view is not necessary, you can pipe directly to samtools sort, if your samtools version is reasonably recent.

Also, do you need to use hg18? It's quite old.

ADD REPLY
0
Entering edit mode

Yes, I'm using hg18 on porpuse, thanks! Tried both my script, and the one without samtools view, it didn't raised any error, but also didn't created any bam file in the target directory. Any idea what could go wrong?

ADD REPLY
0
Entering edit mode

Which samtools version are you using?

ADD REPLY
0
Entering edit mode

samtools version 1.7

ADD REPLY
0
Entering edit mode

Should be okay. I'm not sure if this would matter, but I tend to add in a - to tell samtools we're piping and has to read from stdin.

Oh, and maybe you should add -O BAM to samtools sort. Usually samtools sort is the end of my piping chain, but you continue with rmdup.

ADD REPLY
0
Entering edit mode

I think that up to samtools sort it works fine. The problem is with samtools rmdup, just not sure what... I ran the following command:

${bowtie2_source} -x ${ref_genome} -U ${fastq_file} -S | ${samtools} sort | ${samtools} rmdup -S - ${target_dir}/${sample_name}.bam

and received the error: [bam_rmdup] input SAM does not have header. Abort!

ADD REPLY
0
Entering edit mode

Then you probably need samtools sort -h

ADD REPLY
0
Entering edit mode

This question has been posted in a new thread so any discussion should be moved there for this specific question: Error with samtools rmdup

ADD REPLY
0
Entering edit mode
6.7 years ago

Use GATK: How to generate an unmapped BAM from FASTQ

Use BBMap: Reformat User Guide

EDIT: or use @Pierre's solution.

ADD COMMENT

Login before adding your answer.

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