Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dustar1986
    Junior Member
    • Sep 2011
    • 8

    #1

    Query bam file and assemble reads

    Hi,

    I am quite a newbie in Bioinformatic and maybe asking something stupid.

    I am trying to generate a four-column file for assembling overlapped sequencing reads into longer contigs from a sorted bam file. The file needs to contain the following information in this format:

    chr#: start position of alignment - stop position of alignment: strand (+/-)

    Currently I am trying to awk the bam files to obtain the information, my code is here:

    samtools mpileup input.sorted.bam |\
    cut -d '\t' -f 1,2 |\
    awk -F '\t' 'BEGIN {chr="";start=-1;end=-1} {if(chr!=$1 || int($2)!=end+1) { if(chr!="") {printf("%s:%d-%d\n",chr,start,end);} chr=$1;start=int($2);end=int($2);} else { end=end+1;}} END {if(chr!="") {printf("%s:%d-%d\n",chr,start,end); } }'>output.txt

    It can work except with strand info. Actually, it ignores the strand info. If a read from + strand overlapped with a read from - strand, it will form a contig and that's not what I want. I want to assemble contigs in the same strand.

    How can I improve my code to take in strand info and make the assembly according to strand?

    Please help. Thank you very much.

    Dadi Gao
  • macrowave
    Member
    • May 2010
    • 13

    #2
    I think Bio:B::Sam is the way to go, if you know a bit perl programming. You can use its methods to access sam/bam for any information, including map positions and strands.

    Comment

    • dustar1986
      Junior Member
      • Sep 2011
      • 8

      #3
      Originally posted by macrowave View Post
      I think Bio:B::Sam is the way to go, if you know a bit perl programming. You can use its methods to access sam/bam for any information, including map positions and strands.
      Unfortunately I know nothing about perl
      Is there another way to do it directly from linux shell?

      Comment

      • nilshomer
        Nils Homer
        • Nov 2008
        • 1283

        #4
        Originally posted by dustar1986 View Post
        Unfortunately I know nothing about perl
        Is there another way to do it directly from linux shell?
        This would be a great time to learn perl/python/a-scripting-language.

        Comment

        • macrowave
          Member
          • May 2010
          • 13

          #5
          Maybe you can dig something out from the sam bitwise flags, I'm sure the strand information would be encoded there. For details, you can see the sam specifications here:
          http://samtools.sourceforge.net/SAM1.pdf. And there is an easy tool to explain the flags here: http://picard.sourceforge.net/explain-flags.html

          Comment

          • cbeck
            Junior Member
            • Sep 2011
            • 6

            #6
            You might also try the bedtools suite - bamtobed and then mergebed. Not sure if that will deal with the strands,you might be able to filter the two strands at the bam output level.

            Comment

            • dustar1986
              Junior Member
              • Sep 2011
              • 8

              #7
              Originally posted by nilshomer View Post
              This would be a great time to learn perl/python/a-scripting-language.
              I can use python actually...

              Comment

              • dustar1986
                Junior Member
                • Sep 2011
                • 8

                #8
                Originally posted by macrowave View Post
                Maybe you can dig something out from the sam bitwise flags, I'm sure the strand information would be encoded there. For details, you can see the sam specifications here:
                http://samtools.sourceforge.net/SAM1.pdf. And there is an easy tool to explain the flags here: http://picard.sourceforge.net/explain-flags.html
                Thanks. But the flag only appear in samtools -view not in samtools -mpileup.
                I want to use the latter one coz it's easier for assembly.

                Comment

                • dustar1986
                  Junior Member
                  • Sep 2011
                  • 8

                  #9
                  Originally posted by cbeck View Post
                  You might also try the bedtools suite - bamtobed and then mergebed. Not sure if that will deal with the strands,you might be able to filter the two strands at the bam output level.
                  Thanks, I'll have a look at that.

                  Comment

                  • quinlana
                    Senior Member
                    • Sep 2008
                    • 119

                    #10
                    If you install bedtools, you could use the "mergeBed" program to merge overlapping reads on the same strand as follows:
                    Code:
                    bamToBed -i aln.bam | mergeBed -i stdin -s > merged.intervals.bed
                    Alternatively, you could use the "genomeCoverageBed" tool to create strand-specific BEDGRAPH files, one for each strand. You could then combine them into a single file.
                    Code:
                    bamToBed -i aln.bam | \
                              awk '$6=="+" | \
                              genomeCoverageBed -i stdin -g chrom.sizes -bg \
                              > merged.intervals.fwd.bedg
                    
                    bamToBed -i aln.bam | \
                              awk '$6=="-" | \
                              genomeCoverageBed -i stdin -g chrom.sizes -bg \
                              > merged.intervals.rev.bedg
                    
                    cat merged.intervals.fwd.bedg merged.intervals.rev.bedg > merged.intervals.both.bedg

                    Comment

                    • cgjkjk
                      Member
                      • Oct 2008
                      • 15

                      #11
                      BAM file is compressed, you need do "samtools view -u -bh aln.bam > my.bam" first.

                      Comment

                      Latest Articles

                      Collapse

                      • SEQadmin2
                        New Genomics Technologies Take Aim at Long-Standing Limits
                        by SEQadmin2


                        Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

                        We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
                        ...
                        Today, 10:25 AM
                      • SEQadmin2
                        How Immunogenomics Decodes Immunity’s Genetic Blueprint
                        by SEQadmin2




                        The immune system’s power comes from its genetic diversity, allowing myriad threats to be neutralized through first recognizing foreign antigens. That diversity is also what makes the immune system so difficult to study. Recent advances in sequencing technology and computational biology, however, are giving researchers new tools to understand immune responses and immune-related diseases in greater detail.

                        This convergence of genetics, immunology, and computation...
                        09-01-2026, 05:41 AM

                      ad_right_rmr

                      Collapse

                      News

                      Collapse

                      Topics Statistics Last Post
                      Started by SEQadmin2, 09-25-2026, 09:06 AM
                      0 responses
                      26 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 09-23-2026, 11:05 AM
                      0 responses
                      22 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 09-18-2026, 11:37 AM
                      1 response
                      45 views
                      0 reactions
                      Last Post pekgio
                      by pekgio
                       
                      Started by SEQadmin2, 09-16-2026, 10:23 AM
                      1 response
                      55 views
                      0 reactions
                      Last Post pekgio
                      by pekgio
                       
                      Working...