Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • bash help

    Hi there,

    I cant figure it out how to solve a problem in unix, so a little help would be appritiated.

    So, I want to delete a line (or swap the two column) only if the column3 is greater then column4. Its a tab delimited bed file. The expected output would be the same as the original file, but swapped coordinates if start is greater then stop. Maybe awk, sed?

    x1 I 139154 139256 y1 +
    x2 I 166268 166340 y2 +
    x3 I 181135 181248 y3 +
    x4 I 182597 182516 y4 +

    Thanks a lot!
    L

  • #2
    Code:
    awk '$4>$3{print}' file > output
    Only prints lines where column4 > column3

    Code:
    awk '$3>$4{print $1" "$2" "$4" "$3" "$5}' file > output
    Only print lines where column3 > column4, but print them as "column1<space>column2<space>column4<space>column3<space>column5"
    Last edited by rhinoceros; 01-28-2014, 06:15 AM.
    savetherhino.org

    Comment


    • #3
      Originally posted by rhinoceros View Post
      Code:
      awk '$4>$3{print}' file > output
      Only prints lines where column4 > column3

      Code:
      awk '$3>$4{print $1" "$2" "$4" "$3" "$5}' file > output
      Only print lines where column3 > column4, but print them as "column1<space>column2<space>column4<space>column3<space>column5"
      I suggest doing both of these except using ">>" instead of ">" when sending to the output file and then sorting the output file if you need to.

      Comment


      • #4
        Since Liy wants to keep the file otherwise unchanged, building on rhinoceros's code.
        Code:
        BEGIN   { RS = "\n"}{
                if ($4 > $3) {
                print $0
                }
                else    {
                 #OFS = "\t" (uncomment if you need the output to be tab separated, your example above seems to have spaces)
                print $1, $2, $4, $3, $5, $6
                }
        }
        Code:
        $ cat file | awk -f code_above.awk > save_to_a_new_file
        Last edited by GenoMax; 01-28-2014, 07:02 AM. Reason: Clarification about output

        Comment


        • #5
          You could also try:
          Code:
          awk '{if ($3>$4) {print $1,$2,$4,$3,$5,$6} else {print}}' file.bed > new_file.bed

          Comment


          • #6
            Thank you very much, all of you!

            Comment

            Latest Articles

            Collapse

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

            ad_right_rmr

            Collapse

            News

            Collapse

            Topics Statistics Last Post
            Started by seqadmin, Yesterday, 08:47 AM
            0 responses
            13 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-11-2024, 12:08 PM
            0 responses
            60 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-10-2024, 10:19 PM
            0 responses
            60 views
            0 likes
            Last Post seqadmin  
            Started by seqadmin, 04-10-2024, 09:21 AM
            0 responses
            54 views
            0 likes
            Last Post seqadmin  
            Working...
            X