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
                            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...
                            Yesterday, 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, Yesterday, 07:17 AM
                          0 responses
                          11 views
                          0 likes
                          Last Post seqadmin  
                          Started by seqadmin, 05-02-2024, 08:06 AM
                          0 responses
                          19 views
                          0 likes
                          Last Post seqadmin  
                          Started by seqadmin, 04-30-2024, 12:17 PM
                          0 responses
                          20 views
                          0 likes
                          Last Post seqadmin  
                          Started by seqadmin, 04-29-2024, 10:49 AM
                          0 responses
                          28 views
                          0 likes
                          Last Post seqadmin  
                          Working...
                          X