[Bio] / FigKernelScripts / load_attributes.pl Repository:
ViewVC logotype

Diff of /FigKernelScripts/load_attributes.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7, Sun Mar 13 17:51:28 2005 UTC revision 1.8, Tue Mar 22 03:13:30 2005 UTC
# Line 4  Line 4 
4  # there are several hidden utilities here. If you call the file:  # there are several hidden utilities here. If you call the file:
5  # Filename              Output  # Filename              Output
6  # load_attributes       nothing  # load_attributes       nothing
7  # load_attributes -v    information about those organisms that we add information about  # -v            information about those organisms that we add information about
8  # load_attributes -vv   information about all organisms  # -vv           information about all organisms
9    # -flush        remove any "assigned attributes" file, so that only the base attributes are loaded.
10  # load_attributes -flush   it will remove any "assigned attributes" file, so that only the base attributes are loaded. This is something I use while writing code as I am changing things all the time.  # -link         take the links from proteins and store them as attributes
11    
12    my ($verbose, $flush, $links)=(0,0,0);
13    while (@ARGV)
14    {
15     my $try=shift(@ARGV);
16     if ($try eq "-v") {$verbose=1}
17     if ($try eq "-vv") {$verbose=2}
18     if ($try eq "-flush") {$flush=1}
19     if ($try eq "-link") {$link=1}
20    }
21    
22    
 my $verbose=shift; # a hidden command.  
23    
24  my $dbf = $fig->{_dbf};  my $dbf = $fig->{_dbf};
25  $dbf->drop_table( tbl => "attribute" );  $dbf->drop_table( tbl => "attribute" );
# Line 43  Line 51 
51         $stderr .= "\tFound ". (scalar @files) . " genome attributes >" . (join "<>", @files) . "<\n";         $stderr .= "\tFound ". (scalar @files) . " genome attributes >" . (join "<>", @files) . "<\n";
52         closedir(ATTR);         closedir(ATTR);
53    
54         if ($verbose eq "-flush") {         if ($flush) {
55           if (-e "$dir/assigned_attributes") {`rm -f $dir/assigned_attributes`}           if (-e "$dir/assigned_attributes") {`rm -f $dir/assigned_attributes`}
56         }         }
57         # here is an alternate way of making assigned_attributes at the end of the list if the file exists         # here is an alternate way of making assigned_attributes at the end of the list if the file exists
# Line 58  Line 66 
66      opendir(FEATURES, "$FIG_Config::organisms/$genome/Features") || die "Can't open dir $FIG_Config::organisms/$genome/Features/";      opendir(FEATURES, "$FIG_Config::organisms/$genome/Features") || die "Can't open dir $FIG_Config::organisms/$genome/Features/";
67      foreach my $dir (readdir(FEATURES)) {      foreach my $dir (readdir(FEATURES)) {
68       next if ($dir =~ /^\./);       next if ($dir =~ /^\./);
69       if ($verbose eq "-flush") {       if ($flush) {
70         if (-e "$FIG_Config::organisms/$genome/Features/$dir/Attributes/assigned_attributes") {         if (-e "$FIG_Config::organisms/$genome/Features/$dir/Attributes/assigned_attributes") {
71           `rm -f $FIG_Config::organisms/$genome/Features/$dir/Attributes/assigned_attributes`;           `rm -f $FIG_Config::organisms/$genome/Features/$dir/Attributes/assigned_attributes`;
72         }         }
# Line 83  Line 91 
91           {           {
92               while (defined($_ = <TMPATTR>))               while (defined($_ = <TMPATTR>))
93               {               {
94                   if ($_ =~ /^(\S+)\t(\S+)\t(.*)$/)                   # allow comments
95                     next if (/^\s*\#/);
96                     my ($id, $tag, $val, $url)=split /\t/; # we can allow spaces in the elements
97                     if ($id && $tag)
98                   {                   {
   
                      my ($id, $tag, $val)=($1, $2, $3);  
99                       $tag =~ s/^\s+//; $tag =~ s/\s+$//; $tag=uc($tag);                       $tag =~ s/^\s+//; $tag =~ s/\s+$//; $tag=uc($tag);
100                       if ($val)                       if ($val)
101                       {                       {
102                           $kv{"$id\t$tag"} = $val;                           $kv{"$id\t$tag"} = "$val\t$url";
103                       }                       }
104                       else                       else
105                       {                       {
106                           delete $kv{"$id\t$tag"};                           delete $kv{"$id\t$tag"};
107                       }                       }
108                   }                   }
109                     else
110                     {
111                         print STDERR "There was an error parsing $_ from $file\n";
112                         next;
113                     }
114               }               }
115               close(TMPATTR);               close(TMPATTR);
116           }           }
117      }      }
118      if ($verbose eq "-v" && scalar keys %kv)      if ($verbose == 1 && scalar keys %kv)
119      {      {
120       print "$stderr\tWe have ", scalar keys %kv, " attributes to add for ", $fig->genus_species($genome), " ($genome)\n";       print "$stderr\tWe have ", scalar keys %kv, " attributes to add for ", $fig->genus_species($genome), " ($genome)\n";
121      }      }
122      elsif ($verbose eq "-vv") {      elsif ($verbose == 2) {
123       print "$stderr\tWe have ", scalar keys %kv, " attributes to add for ", $fig->genus_species($genome), " ($genome)\n";       print "$stderr\tWe have ", scalar keys %kv, " attributes to add for ", $fig->genus_species($genome), " ($genome)\n";
124      }      }
125    
# Line 116  Line 130 
130              {              {
131                  ($peg,$k) = split(/\t/,$pegK);                  ($peg,$k) = split(/\t/,$pegK);
132                  $v = $kv{$pegK};                  $v = $kv{$pegK};
                 unless ($v=~ /\t/) {$v .= "\t"}  
133                  print TMPATTR "$peg\t$k\t$v\n";                  print TMPATTR "$peg\t$k\t$v\n";
134              }              }
135              close(TMPATTR);              close(TMPATTR);

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3