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
                            The Impact of AI in Genomic Medicine
                            by seqadmin



                            Artificial intelligence (AI) has evolved from a futuristic vision to a mainstream technology, highlighted by the introduction of tools like OpenAI's ChatGPT and Google's Gemini. In recent years, AI has become increasingly integrated into the field of genomics. This integration has enabled new scientific discoveries while simultaneously raising important ethical questions1. Interviews with two researchers at the center of this intersection provide insightful perspectives into...
                            02-26-2024, 02:07 PM
                          • seqadmin
                            Multiomics Techniques Advancing Disease Research
                            by seqadmin


                            New and advanced multiomics tools and technologies have opened new avenues of research and markedly enhanced various disciplines such as disease research and precision medicine1. The practice of merging diverse data from various ‘omes increasingly provides a more holistic understanding of biological systems. As Maddison Masaeli, Co-Founder and CEO at Deepcell, aptly noted, “You can't explain biology in its complex form with one modality.”

                            A major leap in the field has
                            ...
                            02-08-2024, 06:33 AM

                          ad_right_rmr

                          Collapse

                          News

                          Collapse

                          Topics Statistics Last Post
                          Started by seqadmin, Today, 06:12 AM
                          0 responses
                          13 views
                          0 likes
                          Last Post seqadmin  
                          Started by seqadmin, 02-23-2024, 04:11 PM
                          0 responses
                          67 views
                          0 likes
                          Last Post seqadmin  
                          Started by seqadmin, 02-21-2024, 08:52 AM
                          0 responses
                          70 views
                          0 likes
                          Last Post seqadmin  
                          Started by seqadmin, 02-20-2024, 08:57 AM
                          0 responses
                          61 views
                          0 likes
                          Last Post seqadmin  
                          Working...
                          X