Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gmarco
    Member
    • Oct 2012
    • 36

    #1

    Sort bed file by chr order and not lexicographically

    I've been trying to sort a bed file with bedtools and bedops.

    Both seem to sort the bed file lexicographically.

    That means if my input test file is:

    input:
    Code:
    chr1 10 30
    chr2 30 10
    chr3 10 30
    chr13 30 40
    chr5 10 20
    output:

    Code:
    chr1 10 30
    chr 13 30 40
    chr2 30 10
    chr3 10 30
    chr5 10 20
    and desired output is:

    Code:
    chr1 10 30
    chr2 30 10
    chr3 10 30
    chr5 10 20
    chr13 30 40
    any ideas how to achieve that?
  • Heisman
    Senior Member
    • Dec 2010
    • 534

    #2
    I convert the chrX and chrY to chr23 and chr24 with "sed -e 's,chrX,chr23,' -e 's,chrY,chr24,' input.file" and then pipe that into "sort -k 1.4,1n -k 2,2n" and then change the chr23 and chr24 back. This has to be altered if you have other "chr" values (M and all the small contigs).

    Comment

    • gmarco
      Member
      • Oct 2012
      • 36

      #3
      Don't you have to also remove "chr" from line start to make the sort work?

      Comment

      • GenoMax
        Senior Member
        • Feb 2008
        • 7142

        #4
        More here: http://www.biostars.org/p/64687/

        Comment

        • Heisman
          Senior Member
          • Dec 2010
          • 534

          #5
          Originally posted by gmarco View Post
          Don't you have to also remove "chr" from line start to make the sort work?
          So if you 'sort -k 1.4,1n', the "1.4" tells it to start at the 4th character of the 1st column, so you don't have to remove the "chr". The thread GenoMax linked has other things worth looking at.

          Also I typed this above ("sort -k 1.4,1n -k 2,2n"); it should be ("sort -k 1.4,1n -k 2,2n -k 3,3n").

          Comment

          • gmarco
            Member
            • Oct 2012
            • 36

            #6
            Originally posted by Heisman View Post
            I convert the chrX and chrY to chr23 and chr24 with "sed -e 's,chrX,chr23,' -e 's,chrY,chr24,' input.file" and then pipe that into "sort -k 1.4,1n -k 2,2n" and then change the chr23 and chr24 back. This has to be altered if you have other "chr" values (M and all the small contigs).
            Hello Heisman,

            I'm trying sed command with no success:

            Code:
            sed -e 's,chrX,chr23,' -e 's,chrY,chr24' input.bed
            sed: -e expression #2, char 12: unterminated `s' command
            Fixed missing a comma after chr24 in second sed expression.

            Comment

            • Heisman
              Senior Member
              • Dec 2010
              • 534

              #7
              Yeah, sorry about that. I probably make that typo more than any other.

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