This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Piping samtools output to picard

Hi All,

I need some help I want to pipe the output from samtools to picard read group commands but I am failing:

bowtie2 -x bowtie2_index_hg38 -1 R1.fq.gz -2 R2.fq.gz | samtools view -Shb - | samtools sort - output

What I want to achieve is the following is to also add the read groups the output.bam file from above command and also index the output bam file with reads groups. I am failing with the following command and I don't know how to also index the output bam file that has the read group.

bowtie2 \
  -x bowtie2_index_hg38 \
  -1 mrg_sample_1_R1_val_1.fq \
  -2 mrg_sample_1_R2_val_2.fq | \
samtools view -Shb - | \
samtools sort - - | \
picard AddOrReplaceReadGroups \
  I= output.bam \
  O=rg_output.bam \
  RGID=sample_1 \
  RGLB=sample_1 \
  RGPL=illumina_hi-seq \
  RGPU=sample_1 \
  RGSM=sample_1

Can someone please help me?

Thanks,
Yaseen

next-gen-sequencing alignment

Hello yaseen.ladak!

It appears that your post has been cross-posted to another site: Don't cross-post on here and the samtools mailing list.

This is typically not recommended as it runs the risk of annoying people in both communities.

Hi Devon,

MY apologies I am very new to using these forums. I will keep in mind.

Thanks,

Yaseen

Hi Devon and every one,

Thank you very much. it works now. I will also keep in mind not to post in samtools and here as you mentioned. I am very new to this, I thought if someone would reply I will get an email. Is there a setting biostar if someone replies to my post I get an email?

Thanks,

Yaseen

Sorry, just managed to change my setting in my profile about the email. My apologies, I should have looked better for this option in my profile setting.

1 answer

My reply (it's apparently in moderation, not sure why) to the samtools list was:

You can add the read group directly in bowtie2:

bowtie2 -x bowtie2_index_hg38 --rg-id sample1 --rg SM:sample1 ... | samtools view -Su - | samtools sort - output

Picard's BuildBamIndex tool might be able to take input from a pipe (I'm pretty sure this doesn't work with samtools at the moment), in which case:

... | picard SortSam INPUT=/dev/stdin OUTPUT=/dev/stdout | tee output.bam | picard BuildBamIndex INPUT=/dev/stdin OUTPUT=output.bam.bai

Or something along those regards. I really can't recommend doing this, though. Getting the index in an additional step is going to be a minuscule time savings.

one picard cmd should be enough (not tested)

java -jar picard.jar SortSam CREATE_INDEX=true INPUT=/dev/stdin OUTPUT=output.bam SORT_ORDER=coordinate

and I hate the (non standard) way picard handles options.

Ah, I thought I remembered a CREATE_INDEX option, but didn't see it in the documentation when I looked.

It's defined in the 'general options' (with -H)

Log in to answer this question.