Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bharati
    Member
    • Mar 2012
    • 38

    #16
    Sorting bam file

    How can I sort my bam file according to read headers. Kindly Reply soon.

    Comment

    • gringer
      David Eccles (gringer)
      • May 2011
      • 845

      #17
      using the '-n' option will sort by read name:

      Code:
      samtools sort -n <infile.bam> <out.prefix>
      Run 'samtools sort' without any options to see more help.

      Comment

      • Charitra
        Member
        • Feb 2013
        • 57

        #18
        Is there a single command to sort .bam output of tophat "samtools sort aln.bam aln.sorted"

        or there is a bunch of commands which I have to use... ?

        any idea please ?



        Originally posted by gringer View Post
        using the '-n' option will sort by read name:

        Code:
        samtools sort -n <infile.bam> <out.prefix>
        Run 'samtools sort' without any options to see more help.

        Comment

        • gringer
          David Eccles (gringer)
          • May 2011
          • 845

          #19
          Originally posted by Charitra View Post
          Is there a single command to sort .bam output of tophat "samtools sort aln.bam aln.sorted"
          The tophat output should already be sorted... assuming you meant bowtie/bowtie2, all the samtools programs support piped input using '-' as a file name, so it's quite easy to sort your output without intermediate files using Linux pipes:

          Code:
          bowtie2 <options> | samtools view -S -b - | samtools sort - output.sorted

          Comment

          • yaseen.ladak
            Junior Member
            • Nov 2013
            • 7

            #20
            Hi All

            I have a question. I wish to run bowtie over 3 cores and get an output of aligned sorted and indexed bam files.

            bowtie2 -p 3 -x ../genomes/hg38/hg38 -1 tg/1/S1R1_val_1.fq.gz -2 tg/1/S1R2_val_2.fq.gz | samtools view -Shu - | samtools sort - - | samtools index > bam/S1_srt.bam

            The above command just foes till sorted how can I also include a index via the pipe such that I get a sorted aligned bam and also the index in the same pipe?

            I look forward for your help.

            Thanks,

            Yaseen

            Comment

            • Richard Finney
              Senior Member
              • Feb 2009
              • 701

              #21
              I don't think "samtools index" can handle piped input .

              Comment

              • blancha
                Senior Member
                • May 2013
                • 367

                #22
                It makes no sense to pipe the output of samtools sort to samtools index.
                You want to save the output of samtools sort.
                Just save the output of samtools sort, and then index.
                If you want a one line command, just put a semi-colon after the call to samtools sort, and them call samtools index.

                This is also a duplicate post.
                https://www.biostars.org/p/12747/

                The same answer is posted just above your duplicated post on biostars.

                Comment

                • gringer
                  David Eccles (gringer)
                  • May 2011
                  • 845

                  #23
                  Originally posted by Richard Finney View Post
                  I don't think "samtools index" can handle piped input .
                  Well, you can shoehorn around that by using anonymous files (and tee, where duplicated output is required):

                  Code:
                  samtools index <(samtools view -h ../out.aaa.bam | samtools view -Shu - | samtools sort -T . -O bam -o - | tee out.bam) out.bam.bai
                  Unfortunately, some programs still need to use seek for file processing, and that means code like this won't work. It seems like samtools index is failing for another reason here though:

                  Code:
                  Samtools-htslib-API: bam_index_build2() not yet implemented
                  Aborted

                  Comment

                  • daanum
                    Member
                    • Nov 2015
                    • 24

                    #24
                    How can i sort multiple BAM files using samtools?

                    Hi,

                    Is there any way to sort multiple bam files at the same time using samtools?
                    Thanks.

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