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
                Current Approaches to Protein Sequencing
                by seqadmin


                Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                04-04-2024, 04:25 PM
              • 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

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, 04-11-2024, 12:08 PM
              0 responses
              25 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 10:19 PM
              0 responses
              28 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-10-2024, 09:21 AM
              0 responses
              24 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 04-04-2024, 09:00 AM
              0 responses
              52 views
              0 likes
              Last Post seqadmin  
              Working...
              X