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

Annotation of /FigKernelScripts/check_and_extend_all_subsystems.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : overbeek 1.1 ########################################################################
2 :    
3 :     use FIG;
4 :     my $fig = new FIG;
5 : overbeek 1.3 use Subsystem;
6 : overbeek 1.1
7 :     use strict;
8 :    
9 : overbeek 1.3 # usage: check_and_extend_all_subsyst [-i] [-norebuild] # use -i to actually install';
10 :     # # use -norebuild to suppress recomputing
11 :     # # Subsystem directories;
12 :    
13 :     my $install = 0;
14 :     my $rebuild = 1;
15 :    
16 :     foreach my $arg (@ARGV)
17 :     {
18 :     if ($arg eq "-i") { $install = 1 }
19 :     elsif ($arg = "-norebuild") { $rebuild = 0 }
20 :     }
21 : overbeek 1.1 if ($install) { print STDERR "this run will install additions to extendable genomes\n" }
22 : overbeek 1.3 if ($rebuild) { print STDERR "this run will rebuild the Subsystems directories\n" }
23 : overbeek 1.1
24 : overbeek 1.3 my $has = &build_current_subsystem_data($fig,$rebuild);
25 : overbeek 1.1 &what_needs_to_be_done($fig,$has,$install);
26 :    
27 :     sub build_current_subsystem_data {
28 : overbeek 1.3 my($fig,$rebuild) = @_;
29 : overbeek 1.1
30 :     my($genome);
31 :     my $has = {};
32 :     foreach $genome (sort { $a <=> $b } $fig->genomes('complete'))
33 :     {
34 :     my $tmpF = "$FIG_Config::organisms/$genome/Subsystems";
35 : overbeek 1.3 if ((-d $tmpF) && $rebuild)
36 : overbeek 1.1 {
37 :     system "rm -rf $tmpF";
38 :     }
39 : overbeek 1.3 if ($rebuild || (! -d $tmpF))
40 :     {
41 : overbeek 1.7 system "rapid_subsystem_inference $tmpF < $FIG_Config::organisms/$genome/assigned_functions";
42 : overbeek 1.3 print STDERR "Finished updating Subsystems for $genome\n";
43 :     }
44 : overbeek 1.1
45 :     if (open(SUBS,"<$tmpF/subsystems"))
46 :     {
47 :     while (defined($_ = <SUBS>))
48 :     {
49 :     if ($_ =~ /^([^\t]+)\t(\S+)/)
50 :     {
51 :     $has->{$1}->{$genome} = "\*$2";
52 :     }
53 :     }
54 :     close(SUBS);
55 :     }
56 :     }
57 :     return $has;
58 :     }
59 :    
60 :     sub what_needs_to_be_done {
61 :     my($fig,$has,$install) = @_;
62 :    
63 : overbeek 1.2 foreach my $sub (grep { $fig->ok_to_auto_update_subsys($_) } $fig->all_subsystems)
64 : overbeek 1.1 {
65 : overbeek 1.5 my $altered = 0;
66 : overbeek 1.2 if (my $hasH = $has->{$sub})
67 : overbeek 1.1 {
68 : overbeek 1.3 my $subsys = new Subsystem($sub,$fig);
69 :     my %genomes_in = map { $_ => 1 } $subsys->get_genomes;
70 : overbeek 1.6 foreach my $genome (grep { (! $genomes_in{$_}) && $fig->is_prokaryotic($_) } sort { $a <=> $b } keys(%$hasH))
71 : overbeek 1.1 {
72 :     my $curator = $subsys->get_curator;
73 :     my $var = $hasH->{$genome};
74 : overbeek 1.4 print STDERR join("\t",($sub,$curator,$genome,$var,$fig->genus_species($genome))),"\n";
75 : overbeek 1.1 if ($install && open(BINDINGS,"<$FIG_Config::organisms/$genome/Subsystems/bindings"))
76 :     {
77 :     my %by_role;
78 :     while (defined($_ = <BINDINGS>))
79 :     {
80 :     chop;
81 :     my($sub_name,$role,$peg) = split(/\t/,$_);
82 :     if ($sub_name eq $sub)
83 :     {
84 :     push(@{$by_role{$role}},$peg);
85 :     }
86 :     }
87 :     close(BINDINGS);
88 :    
89 :     $subsys->add_genome($genome);
90 : overbeek 1.5 $altered = 1;
91 :     $subsys->set_variant_code($subsys->get_genome_index($genome),$var);
92 : overbeek 1.1 foreach my $role ($subsys->get_roles)
93 :     {
94 :     if (my $pegs = $by_role{$role})
95 :     {
96 :     $subsys->set_pegs_in_cell($genome,$role,$pegs);
97 :     }
98 :     }
99 :     }
100 :     }
101 : overbeek 1.5
102 :     if ($install && $altered)
103 : overbeek 1.1 {
104 :     $subsys->write_subsystem;
105 :     }
106 :     }
107 :     }
108 :     }
109 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3