Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shoegame2001
    Member
    • Dec 2010
    • 21

    #1

    Mismatch positions in BAM

    Does anyone know of a tool that can output the positions of mismatches for each alignment in a BAM file? I need the coordinates for the mismatch positions within the read as well as the coordinate in the reference sequence to which it aligns. I have found tools that can do one or the other (SAMStat, samtools mpileup, NGSUtils basecall), but they seem to give inconsistent results. Or will I have to extract the information from the CIGAR string or MD tag manually?

    Thanks!
  • swbarnes2
    Senior Member
    • May 2008
    • 910

    #2
    Illumina reads are error-prone; most of the discrepancies you see will be artifacts. Are you trying to count artifacts?

    Comment

    • shoegame2001
      Member
      • Dec 2010
      • 21

      #3
      Yes, exactly. Both artifacts/errors as well as mismatches caused by anything else (e.g. true polymorphism, mapping error, etc.).

      Comment

      • lindenb
        Senior Member
        • Apr 2010
        • 143

        #4
        I wrote a small java program for Biostars ( http://www.biostars.org/p/59647/ ) : see : https://github.com/lindenb/jvarkit/wiki/Biostar59647

        Code:
        $ java -jar dist/biostar59647.jar -r samtools-0.1.18/examples/toy.fa  samtools-0.1.18/examples/toy.bam |\
        xmllint --format - 
        
        <?xml version="1.0" encoding="UTF-8"?>
        <sam ref="/home/lindenb/samtools-0.1.18/examples/toy.bam" bam="/home/lindenb/samtools-0.1.18/examples/toy.fa">
          <!---r /home/lindenb/samtools-0.1.18/examples/toy.fa /home/lindenb/samtools-0.1.18/examples/toy.bam-->
          <read>
            <name>r001</name>
            <sequence>TTAGATAAAGAGGATACTG</sequence>
            <flags READ_PAIRED="true" READ_MAPPED_IN_PROPER_PAIR="true" READ_UNMAPPED="false" MATE_UNMAPPED="false" READ
        _REVERSE_STRAND="false" MATE_REVERSE_STRAND="true" FIRST_IN_PAIR="false" SECOND_IN_PAIR="true" NOT_PRIMARY_ALIGN
        MENT="false" READ_FAILS_VENDOR_QUALITY_CHECK="false" READ_IS_DUPLICATE="false" SUPPLEMENTARY_ALIGNMENT="false">1
        63</flags>
            <qual>30</qual>
            <chrom index="0">ref</chrom>
            <pos>7</pos>
            <cigar>8M4I4M1D3M</cigar>
            <mate-chrom index="0">ref</mate-chrom>
            <mate-pos>37</mate-pos>
            <align>
              <M read-index="1" read-base="T" ref-index="7" ref-base="T"/>
              <M read-index="2" read-base="T" ref-index="8" ref-base="T"/>
              <M read-index="3" read-base="A" ref-index="9" ref-base="A"/>
              <M read-index="4" read-base="G" ref-index="10" ref-base="G"/>
              <M read-index="5" read-base="A" ref-index="11" ref-base="A"/>
              <M read-index="6" read-base="T" ref-index="12" ref-base="T"/>
              <M read-index="7" read-base="A" ref-index="13" ref-base="A"/>
              <M read-index="8" read-base="A" ref-index="14" ref-base="A"/>
              <I read-index="9" read-base="A"/>
              <I read-index="10" read-base="G"/>
              <I read-index="11" read-base="A"/>
              <I read-index="12" read-base="G"/>
              <M read-index="13" read-base="G" ref-index="15" ref-base="G"/>
              <M read-index="14" read-base="A" ref-index="16" ref-base="A"/>
              <M read-index="15" read-base="T" ref-index="17" ref-base="T"/>
              <M read-index="16" read-base="A" ref-index="18" ref-base="A"/>
              <D ref-index="19" ref-base="G"/>
              <M read-index="17" read-base="C" ref-index="20" ref-base="C"/>
              <M read-index="18" read-base="T" ref-index="21" ref-base="T"/>
              <M read-index="19" read-base="G" ref-index="22" ref-base="G"/>
            </align>
          </read>
        (...)

        Comment

        • shoegame2001
          Member
          • Dec 2010
          • 21

          #5
          This is perfect. Thanks so much!

          Comment

          • lindenb
            Senior Member
            • Apr 2010
            • 143

            #6
            if you don't want to parse the XML , you might also like that tool: https://github.com/lindenb/jvarkit/wiki/SAM2Tsv

            Code:
            $ java -jar dist/sam2tsv.jar -A  \
                -r samtools-0.1.18/examples/toy.fa 
                  samtools-0.1.18/examples/toy.sam
            
            r001	ref	0	T	7	T	M
            r001	ref	1	T	8	T	M
            r001	ref	2	A	9	A	M
            r001	ref	3	G	10	G	M
            r001	ref	4	A	11	A	M
            r001	ref	5	T	12	T	M
            r001	ref	6	A	13	A	M
            r001	ref	7	A	14	A	M
            r001	ref	8	A	.	.	I
            r001	ref	9	G	.	.	I
            r001	ref	10	A	.	.	I
            r001	ref	11	G	.	.	I
            r001	ref	12	G	15	G	M
            r001	ref	13	A	16	A	M
            r001	ref	14	T	17	T	M
            r001	ref	15	A	18	A	M
            r001	ref	.	.	19	G	D
            r001	ref	16	C	20	C	M
            r001	ref	17	T	21	T	M
            r001	ref	18	G	22	G	M
            :   ref        7 TTAGATAAAGAGGATA-CTG 22      
            :                ||||||||    |||| |||
            :  r001        1 TTAGATAA----GATAGCTG 19      
            r002	ref	0	A	.	.	S
            r002	ref	1	A	.	.	I
            r002	ref	2	A	.	.	I
            r002	ref	3	A	9	A	M
            r002	ref	4	G	10	G	M

            Comment

            • shoegame2001
              Member
              • Dec 2010
              • 21

              #7
              Great. I was wondering if it is possible for this tool to also extract the location of deletions in the reads. I see that for insertions, it reports the location of the insertion in the read but not in the reference. I realize that if the sequence is not present in the read, then there can't really be an index of that position, but the position after which the deletion occurs would be really helpful. Maybe there is another way to get this information from the CIGAR string?

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                Beyond CRISPR/Cas9: Understand, Choose, and Use the Right Genome Editing Tool
                by SEQadmin2



                CRISPR/Cas9 sparked the gene editing revolution for both research and therapeutics.1 But this system still showed severe issues that limited its applications. The most prominent were the heavy reliance on PAM sequences, delivery limitations, double-stranded breaks that prompt unintended edits and cell death, and editing inefficiency (both in targeting and in knock-in reliability).

                Despite this, “CRISPR helped turn genome editing from a specialized technique into
                ...
                07-31-2026, 11:01 AM
              • SEQadmin2
                Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                by SEQadmin2


                Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                The systematic characterization of the human proteome has
                ...
                07-20-2026, 11:48 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, Today, 10:35 AM
              0 responses
              3 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 08-06-2026, 07:41 AM
              0 responses
              23 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 08-03-2026, 10:13 AM
              0 responses
              40 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-31-2026, 02:55 AM
              0 responses
              46 views
              0 reactions
              Last Post SEQadmin2  
              Working...