[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.3 - (view) (download) (as text)

1 : overbeek 1.1
2 :     $usage = "usage: make_fam_tabs Sources Synonyms Dir";
3 :    
4 :     (
5 :     ($sources = shift @ARGV) &&
6 :     ($syn = shift @ARGV) &&
7 :     ($dir = shift @ARGV)
8 :     )
9 :     || die $usage;
10 :    
11 :     open(TAB1,">$dir/localid_cid") || die "could not open $dir/localid_cid";
12 :     open(TAB2,">$dir/localfam_cid") || die "could not open $dir/localfam_cid";
13 :     open(TAB3,">$dir/localfam_function") || die "could not open $dir/localfam_function";
14 :    
15 :     opendir(SOURCES,$sources) || die "could not open $sources";
16 :     @specific = grep { $_ !~ /^\./ } readdir(SOURCES);
17 :     closedir(SOURCES);
18 :    
19 :     open(SYN,"<$syn") || die "could not open $syn";
20 :     $cid = 1;
21 :     while (defined($_ = <SYN>))
22 :     {
23 : overbeek 1.3 chomp;
24 : overbeek 1.1 @prots = split(/\t/,$_);
25 :     foreach $prot (@prots)
26 :     {
27 :     print TAB1 "$prot\t$cid\n";
28 :     $to_cid{$prot} = $cid;
29 :     }
30 :     $cid++;
31 :     }
32 :    
33 :    
34 :     foreach $source (@specific)
35 :     {
36 : overbeek 1.3 next unless (-d "$sources/$source"); # don't try and process it if it is not a directory!
37 : overbeek 1.1 open(IDMAP,"<$sources/$source/id.map") || die "could not open $sources/$source/id.map";
38 :     while (defined($_ = <IDMAP>))
39 :     {
40 : overbeek 1.3 chomp;
41 : overbeek 1.1 ($fam,$lid) = split(/\t/,$_);
42 : overbeek 1.3 if (!$to_cid{$lid})
43 : overbeek 1.1 {
44 : overbeek 1.3 # we don't have a synonym for this protein
45 :     # we can either ignore it or just give it a unique id. Lets do that.
46 :     $to_cid{$lid}=$cid;
47 :     $cid++;
48 :     # and write it to the file
49 :     print TAB1 "$prot\t$cid\n";
50 : overbeek 1.1 }
51 : overbeek 1.3 print TAB2 "$fam\t$to_cid{$lid}\n";
52 : overbeek 1.1 }
53 :     close(IDMAP);
54 :    
55 :     if (open(FAMFUNC,"<$sources/$source/family.funcs"))
56 :     {
57 :     while (defined($_ = <FAMFUNC>))
58 :     {
59 : overbeek 1.3 # ignore things that begin with a # or things that are just white space
60 :     # some files also have the last line with just a | on it. This should just be skipped
61 :     next if (/^\s+$/ || /^\s*\#/ || /^\|/);
62 :     chomp;
63 :     # this was originally written with this regexp
64 :     # but there were problems when the function was not defined and also with some functions
65 :     # that had leading or trailing spaces. These are removed now.
66 :     #if (($_ =~ /^(\S+)\t(\S[^\t]*\S)$/) && (length($2) < 256))
67 :    
68 :     if ($_ !~ /\t/) {print STDERR "Not enough columns in $sources/$source/family.funcs at $_\n"; next}
69 :     my @line=split /\t/;
70 :     if ($#line > 1) {print STDERR "Too many columns in $sources/$source/family.funcs at $_\n"; next}
71 :    
72 :     # trim leading and trailing spaces
73 :     $line[1] =~ s/^\s+//; $line[1] =~ s/\s*$//;
74 :     $line[0] =~ s/^\s+//; $line[0] =~ s/\s*$//;
75 :    
76 :     # define the function if it is unknown
77 :     unless (defined $line[1]) {$line[1] = "unknown"}
78 :     print TAB3 join("\t", @line), "\n";
79 :    
80 : overbeek 1.1 }
81 :     close(FAMFUNC);
82 :     }
83 :     }
84 :    
85 :     close(TAB1);
86 :     close(TAB2);
87 :     close(TAB3);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3