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
                                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, Yesterday, 10:52 AM
                              0 responses
                              8 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 10-14-2026, 05:39 AM
                              0 responses
                              19 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 10-13-2026, 09:56 AM
                              0 responses
                              15 views
                              0 reactions
                              Last Post SEQadmin2  
                              Started by SEQadmin2, 10-09-2026, 11:14 AM
                              0 responses
                              27 views
                              0 reactions
                              Last Post SEQadmin2  
                              Working...