Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • tonio100680
    Member
    • Apr 2010
    • 25

    samtools & flagstat & awk

    Hi,
    Here is my command :
    $ samtools merge L002_LBCO1.bam L002_LBCO1_chr*.bam

    $ samtools view L002_LBCO1.bam | awk '$3== "chr1.fa" && $4>= 45787123 && $4<= 45787316 || $3== "chr1.fa" && $4>= 45790335 && $4<= 45790528' > essai_chr1.bam

    $ samtools flagstat L002_LBCO1.bam
    3933498 + 0 in total (QC-passed reads + QC-failed reads)
    0 + 0 duplicates
    3868863 + 0 mapped (98.36%:nan%)
    3933498 + 0 paired in sequencing
    1966749 + 0 read1
    1966749 + 0 read2
    3787076 + 0 properly paired (96.28%:nan%)
    3804228 + 0 with itself and mate mapped
    64635 + 0 singletons (1.64%:nan%)
    7262 + 0 with mate mapped to a different chr
    7121 + 0 with mate mapped to a different chr (mapQ>=5)

    $ samtools flagstat essai_chr1.bam
    [bam_header_read] EOF marker is absent. The input is probably truncated.
    [bam_header_read] invalid BAM binary header (this is not a BAM file).
    [bam_flagstat_core] Truncated file? Continue anyway.
    0 + 0 in total (QC-passed reads + QC-failed reads)
    0 + 0 duplicates
    0 + 0 mapped (nan%:nan%)
    0 + 0 paired in sequencing
    0 + 0 read1
    0 + 0 read2
    0 + 0 properly paired (nan%:nan%)
    0 + 0 with itself and mate mapped
    0 + 0 singletons (nan%:nan%)
    0 + 0 with mate mapped to a different chr
    0 + 0 with mate mapped to a different chr (mapQ>=5)

    I would compare files L002_LBCO1.bam (merge result) with essai_chr1. bam (awk result). Apparently he does not recognize the file essai_chr1.bam as bam file.

    Do you have a solution?

    Best regards
  • chenyao
    Member
    • Jul 2011
    • 74

    #2
    Originally posted by tonio100680 View Post
    Hi,
    Here is my command :
    $ samtools merge L002_LBCO1.bam L002_LBCO1_chr*.bam

    $ samtools view L002_LBCO1.bam | awk '$3== "chr1.fa" && $4>= 45787123 && $4<= 45787316 || $3== "chr1.fa" && $4>= 45790335 && $4<= 45790528' > essai_chr1.bam

    $ samtools flagstat L002_LBCO1.bam
    3933498 + 0 in total (QC-passed reads + QC-failed reads)
    0 + 0 duplicates
    3868863 + 0 mapped (98.36%:nan%)
    3933498 + 0 paired in sequencing
    1966749 + 0 read1
    1966749 + 0 read2
    3787076 + 0 properly paired (96.28%:nan%)
    3804228 + 0 with itself and mate mapped
    64635 + 0 singletons (1.64%:nan%)
    7262 + 0 with mate mapped to a different chr
    7121 + 0 with mate mapped to a different chr (mapQ>=5)

    $ samtools flagstat essai_chr1.bam
    [bam_header_read] EOF marker is absent. The input is probably truncated.
    [bam_header_read] invalid BAM binary header (this is not a BAM file).
    [bam_flagstat_core] Truncated file? Continue anyway.
    0 + 0 in total (QC-passed reads + QC-failed reads)
    0 + 0 duplicates
    0 + 0 mapped (nan%:nan%)
    0 + 0 paired in sequencing
    0 + 0 read1
    0 + 0 read2
    0 + 0 properly paired (nan%:nan%)
    0 + 0 with itself and mate mapped
    0 + 0 singletons (nan%:nan%)
    0 + 0 with mate mapped to a different chr
    0 + 0 with mate mapped to a different chr (mapQ>=5)

    I would compare files L002_LBCO1.bam (merge result) with essai_chr1. bam (awk result). Apparently he does not recognize the file essai_chr1.bam as bam file.

    Do you have a solution?

    Best regards
    truly, the awk command can not generate 'bam' file, you can try making 'san' file then convert to bam file by samtools, but I am not sure it can work.

    Comment

    • kmcarr
      Senior Member
      • May 2008
      • 1181

      #3
      Tonio,

      As chenyao already correctly stated, the output of your samtools view | awk pipe is plain text. You could save that to essai_chr1.sam and then convert that sam file to bam.

      There is an easier way though. You don't need to use awk to filter the alignments you want; samtools can do this for you, and output a bam file directly. You can use region specifiers in your samtools view command. These define regions using chromosome names and coordinates, you can give multiple regions on one command line. They are written in the format
      Code:
      <chromosome_name>:<start_position>-<end_position>
      and should be placed after the input sam/bam file name. Your command pipe above could be rewritten:

      Code:
      samtools view -bh -o essai_chr1.bam  L002_LBCO1.bam chr1:45787123-45787316 chr1:45790335-45790528
      -b tells sammtools to output in bam format
      -h will include the header lines in the output file
      -o gives the name of the output file

      Comment

      Latest Articles

      Collapse

      • SEQadmin2
        Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
        by SEQadmin2



        Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
        ...
        07-09-2026, 11:10 AM
      • 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...
        07-08-2026, 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

      ad_right_rmr

      Collapse

      News

      Collapse

      Topics Statistics Last Post
      Started by SEQadmin2, 07-13-2026, 10:26 AM
      0 responses
      15 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 07-09-2026, 10:04 AM
      0 responses
      29 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 07-08-2026, 10:08 AM
      0 responses
      16 views
      0 reactions
      Last Post SEQadmin2  
      Started by SEQadmin2, 07-07-2026, 11:05 AM
      0 responses
      33 views
      0 reactions
      Last Post SEQadmin2  
      Working...