Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SDPA_Pet
    Senior Member
    • Apr 2013
    • 222

    #1

    awk help

    Can any one help me with awk.

    The attached file is an example. I have 10 functions and 6 comparsions. The first column is the function name and column 2- 7 are p value.

    I need to write a awk command to keep the functions which have five out of six p value less than 0.05

    I want to select functions like this

    function1 0.01 0.01 0.01 0.01 0.01 0.1

    Thanks
    Ben
    Attached Files
    Last edited by SDPA_Pet; 03-26-2014, 02:20 PM.
  • Richard Finney
    Senior Member
    • Feb 2009
    • 701

    #2
    cat file | awk '{n=0;if($2<0.05)n++; if($3<0.05)n++; if($4<0.05)n++; if($5<0.05)n++; if($6<0.05)n++; if($7<0.05)n++; if (n==5) print $0}'

    Note this only picks if 5, if you want >= 5 change "==" to ">="

    Comment

    • GenoMax
      Senior Member
      • Feb 2008
      • 7142

      #3
      If you need 5 out of 6 then the following should work:

      Code:
      $ awk '{count = 0; for (i=2; i<=NF; i++) if ($i < 0.05) count++; if (count == 5) print $0}' data.txt
      Note: Richard beat me to it but I will leave this here since as always more than one way of doing things.
      Last edited by GenoMax; 03-27-2014, 04:14 AM.

      Comment

      • SDPA_Pet
        Senior Member
        • Apr 2013
        • 222

        #4
        Originally posted by GenoMax View Post
        If you need 5 out of 6 then the following should work:

        Code:
        $ awk '{count = 0; for (i=2; i<=NF; i++) if ($i < 0.05) count++; if (count == 5) print $0}' data.txt
        Note: Richard beat me to it but I will leave this here since as always more than one way of doing things.
        Hi GEnoMax

        "i<NF", What does NF mean?

        Thanks

        Comment

        • SDPA_Pet
          Senior Member
          • Apr 2013
          • 222

          #5
          Originally posted by GenoMax View Post
          If you need 5 out of 6 then the following should work:

          Code:
          $ awk '{count = 0; for (i=2; i<=NF; i++) if ($i < 0.05) count++; if (count == 5) print $0}' data.txt
          Note: Richard beat me to it but I will leave this here since as always more than one way of doing things.
          Hi GenoMax,

          Can you help me the attached dataset. I want to extract all the data meet these conditions:

          either column4 or column 6 data >=1

          I try this but it doesn't work

          awk '{n=0;if($4>=1)n++; if($6>=1)n++; if (n>=1) print $0}' t-test-story.txt

          Thank you.
          Attached Files
          Last edited by SDPA_Pet; 03-29-2014, 12:50 PM.

          Comment

          • GenoMax
            Senior Member
            • Feb 2008
            • 7142

            #6
            Originally posted by SDPA_Pet View Post
            Hi GEnoMax

            "i<NF", What does NF mean?

            Thanks
            NF is total number of fields in a record (a line).

            Comment

            • SDPA_Pet
              Senior Member
              • Apr 2013
              • 222

              #7
              Hi GenoMax,

              Can you help me with the new file? I don't know why my script doesn't work.

              Comment

              • GenoMax
                Senior Member
                • Feb 2008
                • 7142

                #8
                Originally posted by SDPA_Pet View Post
                Hi GenoMax,

                Can you help me the attached dataset. I want to extract all the data meet these conditions:

                either column4 or column 6 data >=1

                Thank you.
                Try this:

                Code:
                $ awk '{FS="\t"; if ($4 > 1 || $6 > 1 ) print $0}' t-test-story.txt

                Comment

                • musta1234
                  Member
                  • Jun 2013
                  • 10

                  #9
                  Need help converting tab to fasta

                  Hello all!! I need help converting tab to fasta... I am a newbie and know only a little bash scripting. I need to convert a tab delimited SNP file into either a single fasta file or a multiple fasta files for each column using a the first line as identifier.

                  The closest I got was a script that enters a loop and can only be stopped by ctrl-C


                  #!/bin/bash


                  echo ">" > carat.txt

                  counter=1
                  #My tab file has 64 columns
                  while : [ $counter -lt 64]
                  do

                  less <SNP.txt |awk "{print$"$counter"}"| cat carat.txt - >$counter.fa
                  counter=$(($counter +1))

                  done

                  exit



                  SNP_001 SNP_002 SNP_003....
                  T T T T
                  C C C C
                  C C C C
                  C C C C
                  A A A A
                  A A A A
                  T T T T
                  T T T T
                  C C C C
                  G G G G
                  G G G G
                  C C C C

                  Comment

                  • musta1234
                    Member
                    • Jun 2013
                    • 10

                    #10
                    Moved

                    this post is also copied to a new thread to increase exposure... thanks

                    Comment

                    • GenoMax
                      Senior Member
                      • Feb 2008
                      • 7142

                      #11
                      Originally posted by musta1234 View Post
                      this post is also copied to a new thread to increase exposure... thanks
                      Are you basically looking to transpose the matrix your posted and covert it to a multi-fasta file?

                      Comment

                      Latest Articles

                      Collapse

                      • 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
                      • SEQadmin2
                        How Immunogenomics Decodes Immunity’s Genetic Blueprint
                        by SEQadmin2




                        The immune system’s power comes from its genetic diversity, allowing myriad threats to be neutralized through first recognizing foreign antigens. That diversity is also what makes the immune system so difficult to study. Recent advances in sequencing technology and computational biology, however, are giving researchers new tools to understand immune responses and immune-related diseases in greater detail.

                        This convergence of genetics, immunology, and computation...
                        09-01-2026, 05:41 AM

                      ad_right_rmr

                      Collapse

                      News

                      Collapse

                      Topics Statistics Last Post
                      Started by SEQadmin2, Yesterday, 09:51 AM
                      0 responses
                      11 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 09-25-2026, 09:06 AM
                      0 responses
                      34 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 09-23-2026, 11:05 AM
                      0 responses
                      28 views
                      0 reactions
                      Last Post SEQadmin2  
                      Started by SEQadmin2, 09-18-2026, 11:37 AM
                      1 response
                      48 views
                      0 reactions
                      Last Post pekgio
                      by pekgio
                       
                      Working...