Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • gene feature converter

    Hi guys,
    i hv got a GO file for my differentially expressed genes file, it goes like:

    FBgn00001 GO:0016301 [Name:****(annotation)]
    FBgn00002 GO:0016301 [Name:****(annotation)]
    FBgn00003 GO:0016301 [Name:****(annotation)]
    FBgn00004 GO:0003700 [Name:****(annotation)]
    FBgn00004 GO:0009651 [Name:****(annotation)]
    FBgn00004 GO:0006355 [Name:****(annotation)]
    FBgn00005 GO:0009556 [Name:****(annotation)]
    FBgn00005 GO:0005515 [Name:****(annotation)]
    FBgn00005 GO:0080019 [Name:****(annotation)]
    FBgn00005 GO:0016563 [Name:****(annotation)]
    FBgn00005 GO:0016627 [Name:****(annotation)]
    FBgn00006 GO:0003700 [Name:****(annotation)]
    FBgn00006 GO:0010018 [Name:****(annotation)]

    now i want to use WEGO ,so i need to convert it like:

    FBgn00001 GO:0016301
    FBgn00002 GO:0016301
    FBgn00003 GO:0016301
    FBgn00004 GO:0003700 GO:0009651 GO:0006355
    FBgn00005 GO:0009556 GO:0005515 GO:0080019 GO:0016563 GO:0016627
    FBgn00006 GO:0003700 GO:0010018

    I think this could be solved using a perl script. I am not able to do this since i am a beginner. Can someone help me out? A simple perl script is good enough for me^^

  • #2
    Originally posted by jason_ARGONAUTE View Post
    Hi guys,
    i hv got a GO file for my differentially expressed genes file, it goes like:

    FBgn00001 GO:0016301 [Name:****(annotation)]
    FBgn00002 GO:0016301 [Name:****(annotation)]
    FBgn00003 GO:0016301 [Name:****(annotation)]
    FBgn00004 GO:0003700 [Name:****(annotation)]
    FBgn00004 GO:0009651 [Name:****(annotation)]
    FBgn00004 GO:0006355 [Name:****(annotation)]
    FBgn00005 GO:0009556 [Name:****(annotation)]
    FBgn00005 GO:0005515 [Name:****(annotation)]
    FBgn00005 GO:0080019 [Name:****(annotation)]
    FBgn00005 GO:0016563 [Name:****(annotation)]
    FBgn00005 GO:0016627 [Name:****(annotation)]
    FBgn00006 GO:0003700 [Name:****(annotation)]
    FBgn00006 GO:0010018 [Name:****(annotation)]

    now i want to use WEGO ,so i need to convert it like:

    FBgn00001 GO:0016301
    FBgn00002 GO:0016301
    FBgn00003 GO:0016301
    FBgn00004 GO:0003700 GO:0009651 GO:0006355
    FBgn00005 GO:0009556 GO:0005515 GO:0080019 GO:0016563 GO:0016627
    FBgn00006 GO:0003700 GO:0010018

    I think this could be solved using a perl script. I am not able to do this since i am a beginner. Can someone help me out? A simple perl script is good enough for me^^
    both of files are tab-delemited.

    Comment


    • #3
      This might help

      sed 's/\[.*\]//g' genes_file

      Comment


      • #4
        This python script should work

        import csv
        reader = csv.reader(open("GO.txt","r"), delimiter="\t")
        new={}
        for row in reader:
        if row[0] not in new.keys():
        new[row[0]] = [row[1]]
        else:
        new[row[0]].append(row[1])


        with open("wego.txt","w") as f:
        for key, value in sorted(new.items()):
        f.write(key+"\t"+"\t".join(value)+"\n")
        Last edited by crazyhottommy; 10-18-2013, 10:26 AM.

        Comment


        • #5
          I don't know why the indentation is messed up....

          Originally posted by crazyhottommy View Post
          This python script should work

          import csv
          reader = csv.reader(open("GO.txt","r"), delimiter="\t")
          new={}
          for row in reader:
          if row[0] not in new.keys():
          new[row[0]] = [row[1]]
          else:
          new[row[0]].append(row[1])


          with open("wego.txt","w") as f:
          for key, value in sorted(new.items()):
          f.write(key+"\t"+"\t".join(value)+"\n")

          Comment


          • #6
            Originally posted by crazyhottommy View Post
            I don't know why the indentation is messed up....
            You need to use the "["CODE"]" tags (remove the quotes). If you go to the advanced mode, then click on the hash tag in the toolbar.

            Code:
            I'm in a code block
                and I can be indented to not muck up python

            Comment


            • #7
              [/CODE][/CODE]
              Originally posted by dpryan View Post
              You need to use the "["CODE"]" tags (remove the quotes). If you go to the advanced mode, then click on the hash tag in the toolbar.

              Code:
              I'm in a code block
                  and I can be indented to not muck up python

              Test...


              Code:
              import csv
              reader = csv.reader(open("GO.txt","r"), delimiter="\t")
              new={}
              for row in reader:
                  if row[0] not in new.keys():
                      new[row[0]] = [row[1]]
                  else:
                      new[row[0]].append(row[1])
              
              
              with open("wego.txt","w") as f:
                  for key, value in sorted(new.items()):
                     f.write(key+"\t"+"\t".join(value)+"\n")
              Last edited by crazyhottommy; 10-19-2013, 04:57 AM.

              Comment


              • #8
                This one line awk can do the trick...

                awk '{ if (a[$1]) a[$1]=a[$1]"\t"$2; else a[$1]=$2;} END { for (i in a) print i, a[i]}' OFS="\t" input.txt

                Comment


                • #9
                  i like the simplicity, thank you!

                  Comment


                  • #10
                    Originally posted by Ciaran View Post
                    This might help

                    sed 's/\[.*\]//g' genes_file

                    i like the simplicity of linux commands, thank you!

                    Comment


                    • #11
                      Originally posted by crazyhottommy View Post
                      This one line awk can do the trick...

                      awk '{ if (a[$1]) a[$1]=a[$1]"\t"$2; else a[$1]=$2;} END { for (i in a) print i, a[i]}' OFS="\t" input.txt
                      i'm new to command awk, but thanks anyway^^

                      Comment


                      • #12
                        Originally posted by crazyhottommy View Post
                        [/CODE][/CODE]


                        Test...


                        Code:
                        import csv
                        reader = csv.reader(open("GO.txt","r"), delimiter="\t")
                        new={}
                        for row in reader:
                            if row[0] not in new.keys():
                                new[row[0]] = [row[1]]
                            else:
                                new[row[0]].append(row[1])
                        
                        
                        with open("wego.txt","w") as f:
                            for key, value in sorted(new.items()):
                               f.write(key+"\t"+"\t".join(value)+"\n")
                        many people told me to learn Python instead of Perl, maybe i'll learn python someday^^

                        Comment


                        • #13
                          Originally posted by jason_ARGONAUTE View Post
                          many people told me to learn Python instead of Perl, maybe i'll learn python someday^^
                          A Perl version? Okay, here's something that might work:

                          Code:
                          perl -ane '
                            if($gn ne $F[0]){
                              print ($gn?"\n":"").$gn;
                            }
                            print " ".$F[1];
                            $gn = $F[0];
                            END {
                              print "\n";
                            }'
                          [delimiter can be changed with the -F option, i.e. -F '/\t/']

                          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