This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Sra file to bam file error

Hi ,

I am trying to convert SRA file to bam file and I getting these error for some files :

/opt/sratoolkit.2.9.2-centos_linux64/bin/sam-dump /data/SRR31467.sra | data/samtools/bin/samtools view -bS -o /data/sratobam/SRR31467.bam

[E::sam_hrecs_error] Malformed key:value pair at line 86: "@RG ID:PM164 PL:Illumina LB:GA LNID:L001 FCID:H9CB8ADXX DT:2014-04-21T00:00:00-0400 BCID:AGTACAAG SM:PM164_X1_1_Case"

samtools view: failed to add PG line to the header

samtools rna-seq sratoolkit

I think you need a dash after -bS because you are piping.

sam-dump /data/SRR31467.sra | data/samtools/bin/samtools view -bS - -o /data/sratobam/SRR31467.bam

or

sam-dump /data/SRR31467.sra | data/samtools/bin/samtools view -b -S - >  /data/sratobam/SRR31467.bam

I have used both of these command and it does not worked for me . The command i post is only one which successfully gives me the required output but for some file it does not worked.

Is SRR31467 a real SRA number?

nope , I didn't mention the correct SRR number.

Unless submitters have submitted aligned data what you will get is an unaligned BAM file. Which is not going to be useful for any downstream analysis.

submitters have submitted bam file . this is reported in their meta level information .

I have also converted sra to sam file for this particular SRR number file ,it converted successfully but It gives same error as above while converting sam to bam .

Try shorting the headers of your sam file. Remove all the unnecessary info from the header and try again with samtools view -b -s input.sam > output.bam

Can you please advise me , how to short the headers from sam file??

1 answer

Hello, I've experienced similar problems some weeks ago, then I've opened an issue on GitHub. As they made me notice, the most recent version of samtools (1.10) has a more strict behavior with header standards, which means that keys must not exceed two characters in length. To solve it I just shortened the malformed key with the following command:

samtools reheader -c "sed '/^@RG/ s/\([A-Z][A-Z]\)ID/\1/g'" example.bam > example.RGcorrected.bam

Which, inserted in your context, since it looks like you are receiving a sam file from stdin:

/opt/sratoolkit.2.9.2-centos_linux64/bin/sam-dump /data/SRR31467.sra | sed '/^@RG/ s/\([A-Z][A-Z]\)ID/\1/g' | data/samtools/bin/samtools view -bS - -o /data/sratobam/SRR31467.bam

Hope this helps :)

Log in to answer this question.