Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

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


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

      Comment


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

        Comment


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


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


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

              Comment

              Latest Articles

              Collapse

              • seqadmin
                Strategies for Sequencing Challenging Samples
                by seqadmin


                Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                03-22-2024, 06:39 AM
              • seqadmin
                Techniques and Challenges in Conservation Genomics
                by seqadmin



                The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

                Avian Conservation
                Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
                03-08-2024, 10:41 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Yesterday, 06:37 PM
              0 responses
              8 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Yesterday, 06:07 PM
              0 responses
              8 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 03-22-2024, 10:03 AM
              0 responses
              49 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 03-21-2024, 07:32 AM
              0 responses
              66 views
              0 likes
              Last Post seqadmin  
              Working...
              X