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
                Recent Advances in Sequencing Analysis Tools
                by seqadmin


                The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
                05-06-2024, 07:48 AM
              • seqadmin
                Essential Discoveries and Tools in Epitranscriptomics
                by seqadmin




                The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
                04-22-2024, 07:01 AM

              ad_right_rmr

              Collapse

              News

              Collapse

              Topics Statistics Last Post
              Started by seqadmin, Today, 06:35 AM
              0 responses
              12 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, Yesterday, 02:46 PM
              0 responses
              18 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 05-07-2024, 06:57 AM
              0 responses
              17 views
              0 likes
              Last Post seqadmin  
              Started by seqadmin, 05-06-2024, 07:17 AM
              0 responses
              19 views
              0 likes
              Last Post seqadmin  
              Working...
              X