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

Annotation of /FigKernelScripts/make_fam_tabs.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (view) (download) (as text)

1 : olson 1.4 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 : overbeek 1.1
19 :     $usage = "usage: make_fam_tabs Sources Synonyms Dir";
20 :    
21 :     (
22 :     ($sources = shift @ARGV) &&
23 :     ($syn = shift @ARGV) &&
24 :     ($dir = shift @ARGV)
25 :     )
26 :     || die $usage;
27 :    
28 :     open(TAB1,">$dir/localid_cid") || die "could not open $dir/localid_cid";
29 :     open(TAB2,">$dir/localfam_cid") || die "could not open $dir/localfam_cid";
30 :     open(TAB3,">$dir/localfam_function") || die "could not open $dir/localfam_function";
31 :    
32 :     opendir(SOURCES,$sources) || die "could not open $sources";
33 :     @specific = grep { $_ !~ /^\./ } readdir(SOURCES);
34 :     closedir(SOURCES);
35 :    
36 :     open(SYN,"<$syn") || die "could not open $syn";
37 :     $cid = 1;
38 :     while (defined($_ = <SYN>))
39 :     {
40 : overbeek 1.3 chomp;
41 : overbeek 1.1 @prots = split(/\t/,$_);
42 :     foreach $prot (@prots)
43 :     {
44 :     print TAB1 "$prot\t$cid\n";
45 :     $to_cid{$prot} = $cid;
46 :     }
47 :     $cid++;
48 :     }
49 :    
50 :    
51 :     foreach $source (@specific)
52 :     {
53 : overbeek 1.3 next unless (-d "$sources/$source"); # don't try and process it if it is not a directory!
54 : overbeek 1.1 open(IDMAP,"<$sources/$source/id.map") || die "could not open $sources/$source/id.map";
55 :     while (defined($_ = <IDMAP>))
56 :     {
57 : overbeek 1.3 chomp;
58 : overbeek 1.1 ($fam,$lid) = split(/\t/,$_);
59 : overbeek 1.3 if (!$to_cid{$lid})
60 : overbeek 1.1 {
61 : overbeek 1.3 # we don't have a synonym for this protein
62 :     # we can either ignore it or just give it a unique id. Lets do that.
63 :     $to_cid{$lid}=$cid;
64 :     $cid++;
65 :     # and write it to the file
66 :     print TAB1 "$prot\t$cid\n";
67 : overbeek 1.1 }
68 : overbeek 1.3 print TAB2 "$fam\t$to_cid{$lid}\n";
69 : overbeek 1.1 }
70 :     close(IDMAP);
71 :    
72 :     if (open(FAMFUNC,"<$sources/$source/family.funcs"))
73 :     {
74 :     while (defined($_ = <FAMFUNC>))
75 :     {
76 : overbeek 1.3 # ignore things that begin with a # or things that are just white space
77 :     # some files also have the last line with just a | on it. This should just be skipped
78 :     next if (/^\s+$/ || /^\s*\#/ || /^\|/);
79 :     chomp;
80 :     # this was originally written with this regexp
81 :     # but there were problems when the function was not defined and also with some functions
82 :     # that had leading or trailing spaces. These are removed now.
83 :     #if (($_ =~ /^(\S+)\t(\S[^\t]*\S)$/) && (length($2) < 256))
84 :    
85 :     if ($_ !~ /\t/) {print STDERR "Not enough columns in $sources/$source/family.funcs at $_\n"; next}
86 :     my @line=split /\t/;
87 :     if ($#line > 1) {print STDERR "Too many columns in $sources/$source/family.funcs at $_\n"; next}
88 :    
89 :     # trim leading and trailing spaces
90 :     $line[1] =~ s/^\s+//; $line[1] =~ s/\s*$//;
91 :     $line[0] =~ s/^\s+//; $line[0] =~ s/\s*$//;
92 :    
93 :     # define the function if it is unknown
94 :     unless (defined $line[1]) {$line[1] = "unknown"}
95 :     print TAB3 join("\t", @line), "\n";
96 :    
97 : overbeek 1.1 }
98 :     close(FAMFUNC);
99 :     }
100 :     }
101 :    
102 :     close(TAB1);
103 :     close(TAB2);
104 :     close(TAB3);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3