Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TabeaK
    Member
    • Oct 2012
    • 48

    #1

    Issue with Sam-Bam conversion samtools - how to remove last line of Sam file?

    Hello guys and gals!

    I have a bit of a problem with samtools Sam-bam conversion. I have 8 files containing single read illumina data that I have aligned to my reference genome using bwa samse. No problems. Upon conversion, however, 4 out of 8 Sam files create a problem. The other 4 convert without a hitch.

    I am writing this from my mobile so cannot copy in the error message, but it is the same that has been discussed here before - samtools complains about the sequence and quality information not matching and aborts.

    Funnily, this only happens in the very last line of each Sam file! So I figured I just remove it and try again.

    Any ideas as to how to accomplish this? I have tried opening the file in a simple text editor, but they are too massive (15GB)...
  • dpryan
    Devon Ryan
    • Jul 2011
    • 3478

    #2
    If all you want to do is trim off the last line in a file, I can think of a whole slew of ways. You could count the number of lines in the files (wc -l) and then "head -n X" into a new SAM files, where X is 1 less than the number of lines in the file. Alternatively, you could just grep for everything put the last read name and send that to a new file. Or, you could just tell samtools how many of the reads to convert to a BAM file (the -c switch), giving it all but the last one.

    Of course, this assumes that removing the last line will actually fix things. It'd be helpful to see the last read that seems to be causing the problem and the error message.

    Comment

    • xied75
      Senior Member
      • Feb 2012
      • 129

      #3
      Agree that one line might only be a tip of iceberg.

      Comment

      • TabeaK
        Member
        • Oct 2012
        • 48

        #4
        Thanks for your input!

        I have, however, since sorted and merged all my bam files. Samtools complains about the missing EOF in the 4 bams in question and warns of possibly truncated data, but creates a merged file, which contains all my reads ( I can see that from samtools flagstat) but the 4 last ones from the respective files. The alignment looks absolutely fine when visualized in IGV.

        Anyway, it is of course better to find out where this pesky error is coming from, I'll figure out how to look at those lines tomorrow...read about the bamseek tool, maybe I'll try that.

        Comment

        Latest Articles

        Collapse

        • SEQadmin2
          Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
          by SEQadmin2



          Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

          Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
          ...
          10-14-2026, 09:55 AM
        • 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
          ...
          09-28-2026, 10:25 AM

        ad_right_rmr

        Collapse

        News

        Collapse

        Topics Statistics Last Post
        Started by SEQadmin2, 10-22-2026, 11:13 AM
        0 responses
        48 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-22-2026, 10:48 AM
        0 responses
        37 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-15-2026, 10:52 AM
        0 responses
        46 views
        0 reactions
        Last Post SEQadmin2  
        Started by SEQadmin2, 10-14-2026, 05:39 AM
        0 responses
        46 views
        0 reactions
        Last Post SEQadmin2  
        Working...