Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lv Ray
    Member
    • Jun 2014
    • 42

    #1

    I am mad because of samtools sort command

    I got .sam files from Bowtie2.
    now I want to merge these two files.First ,I run:
    samtools view -bSh ERR1.sam >ERR1.bam
    samtools view -bSh ERR2.sam >ERR2.bam

    and,I got the bam file.(they should have the head)
    However,I run the next:
    samtools sort ERR1.bam ERR1.sorted.bam (here,I got the sorted file,lucky)
    samtools sort ERR2.bam ERR2.sorted.bam
    about the ERR2.bam, I didn't get the sorted file, this was the output:

    [bam_header_read] invalid BAM binary header (this is not a BAM file).
    [bam_sort_core] truncated file. Continue anyway.
    Segmentation fault (core dumped)

    why?Just because the ERR2.sam is too big(about 66G)?
  • Lv Ray
    Member
    • Jun 2014
    • 42

    #2
    supplement:
    I run command: samtools view ERR2.bam |less -S
    and I got this:
    [bam_header_read] invalid BAM binary header (this is not a BAM file).
    [main_samview] fail to read the header from "ERR173170_paired.bam".

    Comment

    • biocomputer
      Member
      • Dec 2013
      • 62

      #3
      If the file is too big for sorting you could split the .sam file on chromosome, sort each, recombine, then convert to .bam.

      Comment

      • Lv Ray
        Member
        • Jun 2014
        • 42

        #4
        Originally posted by biocomputer View Post
        If the file is too big for sorting you could split the .sam file on chromosome, sort each, recombine, then convert to .bam.
        You mean that i got the fault in producing the sam file?but my sam file is okay!

        Comment

        • Lv Ray
          Member
          • Jun 2014
          • 42

          #5
          like your mean, maybe I need to split my big sam file

          Comment

          • dpryan
            Devon Ryan
            • Jul 2011
            • 3478

            #6
            66 gigs isn't too big to sort, the original BAM file was corrupt, likely due to running out of space or a hardware problem. Make sure you have enough space and then remake the BAM file.

            Comment

            • Lv Ray
              Member
              • Jun 2014
              • 42

              #7
              The space is enough, how about the memory?

              Comment

              • dpryan
                Devon Ryan
                • Jul 2011
                • 3478

                #8
                The whole SAM file isn't loaded into memory, it's processed line by line (and compressed in blocks).

                Comment

                • dpryan
                  Devon Ryan
                  • Jul 2011
                  • 3478

                  #9
                  A transient hardware error is the most likely cause of this sort of thing.

                  Comment

                  • arundurvasula
                    Member
                    • Jun 2014
                    • 16

                    #10
                    I recently got an error like that because I switched my reads with my reference sequence while mapping. I.e. my alignment was of my reference to my reads. Maybe that's your problem?

                    Here's a (correct) bash function that I used to map reads to a reference and only grab the mapped reads from the sam. Hopefully this can help guide you:
                    Code:
                    map () {
                    	bwa index -a bwtsw $refseq
                    	bwa bwasw $refseq ../temp/$1/sampled_reads.fasta > ../temp/$1/alignment.sam
                    	samtools view -bS -F 4 ../temp/$1/alignment.sam > ../temp/$1/mapped.alignment.bam
                    	samtools sort ../temp/$1/mapped.alignment.bam ../results/$1/mapped.sorted.alignment
                    	samtools index ../results/$1/mapped.sorted.alignment.bam
                    }

                    Comment

                    • Lv Ray
                      Member
                      • Jun 2014
                      • 42

                      #11
                      Thank you a lot for sparing your beautiful bash.
                      However ,it seems that your bash is suitable for unpaired alignment. I thought that because the command samtools view -bS -F 4 ../temp/$1/alignment.sam > ../temp/$1/mapped.alignment.bam ,you discard the unmapped reads. But how to set the parameter -F In paired alignment reads (.sam) ?
                      Thanks all .

                      Comment

                      • dpryan
                        Devon Ryan
                        • Jul 2011
                        • 3478

                        #12
                        -F 4 will remove unmapped reads in either case. If you want to remove those reads with an unmapped mate then just filter according to that bit in the flag.

                        Comment

                        • Lv Ray
                          Member
                          • Jun 2014
                          • 42

                          #13
                          About the parameter -F of samtools view

                          Originally posted by dpryan View Post
                          -F 4 will remove unmapped reads in either case. If you want to remove those reads with an unmapped mate then just filter according to that bit in the flag.
                          Hi, dpryan. Thank you for your answer. Now I have the similar quetions about -F, . I appreciate and hope you can help me.
                          1) Should I remove the unmapped reads (but its mates mapped) or the unmapped mates(but its reads mapped)
                          2) about the paired reads, if I remove all them above ,should I use -F 12? However , it seems that there's no the value of 12. How about the 77 or 141.

                          Comment

                          • dpryan
                            Devon Ryan
                            • Jul 2011
                            • 3478

                            #14
                            1) It depends on what you want to do with the results.
                            2) -F 12 is correct. There don't have to be any flags with that value since this is a bit comparison.

                            Comment

                            • Lv Ray
                              Member
                              • Jun 2014
                              • 42

                              #15
                              Thank you, dpryan.
                              Today I tested it ,and the result is Consistent with your answer!
                              Thanks, again.

                              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
                              • 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

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by SEQadmin2, Yesterday, 10:13 AM
                              0 responses
                              13 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-31-2026, 02:55 AM
                              0 responses
                              25 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-24-2026, 12:17 PM
                              0 responses
                              19 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 07-23-2026, 11:41 AM
                              0 responses
                              18 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...