Unconfigured Ad

Collapse
X
 
  • Filter
  • 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.


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

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, 07-24-2026, 12:17 PM
                    0 responses
                    29 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-23-2026, 11:41 AM
                    0 responses
                    21 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-20-2026, 11:10 AM
                    0 responses
                    212 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-13-2026, 10:26 AM
                    0 responses
                    78 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...