Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • scami
    Member
    • Sep 2010
    • 55

    Help with sam flags

    Hi guys
    I would like to ask you a help with the sam format flag. I am using samtools to extract reads from a bam file. Briefly I need to extract all mapped reads in a certain range which is easy to achieve by using the samtools view command. However I need to extract together with the mapped reads also the eventual corresponding unmapped mates.
    How can I do that?
    thanks for the help!
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    There's no built-in way to do that. If the number of reads in your region of interest is relatively small, then you can "samtools view -F foo.bam region | cut -f 1 > rnames" and then just "samtools view -f 4 foo.bam | grep -f rnames > unmapped_in_region.sam". You could also write a program to do this a bit more efficiently in python (just use a dict of the read names), or just query-sort things and then have the program look for overlaps pair at a time.

    Comment

    • scami
      Member
      • Sep 2010
      • 55

      #3
      Thanks

      Thanks for the answer. Sam files I am using are very large so an ad hoc C or python script would not be the best option for me. I'll work on it anyway, thanks for the advice

      Comment

      • capricy
        Senior Member
        • Apr 2012
        • 125

        #4
        how to extract reads 1 from a sam file

        Hello, there,

        I found that samtools filter function works only for bam file. What if I have a sam file, and I would like to only keep read1 (flag: 64)?

        Do I need to convert this sam file back to bam?

        Thanks!!

        Capricy

        Comment

        • Brian Bushnell
          Super Moderator
          • Jan 2014
          • 2709

          #5
          I'm pretty sure this works with sam input as well.

          samtools view -Sf 64 mapped.sam
          Last edited by Brian Bushnell; 02-27-2015, 03:18 PM. Reason: Added -S

          Comment

          • dpryan
            Devon Ryan
            • Jul 2011
            • 3478

            #6
            Originally posted by Brian Bushnell View Post
            I'm pretty sure this works with sam input as well.

            samtools view -f 64 mapped.sam
            Add a -S and that should work.

            Comment

            • capricy
              Senior Member
              • Apr 2012
              • 125

              #7
              en. My problem seems to be the missing header

              Thanks for all the replies!!

              Comment

              Latest Articles

              Collapse

              • SEQadmin2
                Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                by SEQadmin2



                Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                Today, 05:17 AM
              • GATTACAT
                Reply to Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                by GATTACAT
                Love this - good data definitely starts from good input, and poor input can only give relatively poor data. I particularly like the mention of Nanodrop/absorbance based methods for quantification. It's such a toss up if you'll get an accurate reading or what amounts to a randomly generated number, and a lot of library/sequencing related issues can be traced back to poor quant.
                07-01-2026, 11:43 AM
              • SEQadmin2
                Nine Things a Sample Prep Scientist Thinks About Before Sequencing
                by SEQadmin2


                I’m not a sequencing expert. I’m a purification scientist who uses NGS to evaluate workflows my group develops. With this perspective, we think about the sample first and the NGS workflow second. The sequencer is an exceptionally honest reporter, but it can only report on what you give it, so whether you get clean, interpretable data from an NGS workflow is largely determined before you begin.

                Here are nine questions we think about, in roughly the order they matter, before...
                06-18-2026, 07:11 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by SEQadmin2, Today, 10:08 AM
              0 responses
              5 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, Yesterday, 11:05 AM
              0 responses
              7 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 07-02-2026, 11:08 AM
              0 responses
              29 views
              0 reactions
              Last Post SEQadmin2  
              Started by SEQadmin2, 06-30-2026, 05:37 AM
              0 responses
              28 views
              0 reactions
              Last Post SEQadmin2  
              Working...