use FIG; my $fig = new FIG; $usage = "usage: make_timestamps SubsystemAssignments SubsystemConnections"; ( ($assignF = shift @ARGV) && open(ASSIGN,">$assignF") && ($connF = shift @ARGV) && open(CONN,">$connF") ) || die $usage; foreach $sub (grep { $fig->usable_subsystem($_) } $fig ->all_subsystems) { undef %pegH; my $genomes = $fig->subsystem_genomes($sub); foreach $role ($fig->subsystem_to_roles($sub)) { foreach $genome (map { $_->[0] } @$genomes) { foreach $peg ($fig->pegs_in_subsystem_cell($sub,$genome,$role)) { $pegH{$peg} = 1; $curr_func = $fig->function_of($peg); @annotations = $fig->feature_annotations($peg,"raw"); for ($i=$#annotations; ($i >= 0) && ($annotations[$i]->[3] !~ /^Set /); $i--) {} if (($i >= 0) && ($annotations[$i]->[3] =~ /^Set master function to\n(\S.*\S)/s)) { $ann_func = $1; if (($curr_func eq $ann_func) && ($annotations[$i]->[2] !~ /auto|assign|repair|last|saved|cleanup/i)) { $annotations[$i]->[2] =~ s/^master://; print ASSIGN join("\t",$annotations[$i]->[0],$annotations[$i]->[1],$annotations[$i]->[2],"assigned",$ann_func),"\n"; } } } } } &process_ss($fig,$sub,\%pegH); } sub process_ss { my($fig,$sub,$pegH) = @_; opendir(BACKUP,"$FIG_Config::data/Subsystems/$sub/Backup") || return (); my $curator = $fig->subsystem_curator($sub); $curator =~ s/^master://; my @spreadsheets = sort { $b <=> $a } map { $_ =~ /^spreadsheet.(\d+)/; $1 } grep { $_ =~ /^spreadsheet/ } readdir(BACKUP); closedir(BACKUP); my $ts_last = time; foreach my $ts (@spreadsheets) { my $hash = {}; my $file = "$FIG_Config::data/Subsystems/$sub/Backup/spreadsheet.$ts"; if (open(SS,"<$file")) { $/ = "//\n"; $_ = ; $_ = ; if (defined($_ = )) { chomp; @lines = split(/\n/,$_); foreach $_ (@lines) { if ($_ =~ /^(\S+)\t\S+\t(.*)/) { my $genome = $1; my @cells = split(/\t/,$2); foreach my $cell (@cells) { foreach my $pegN (split(/,/,$cell)) { my $peg = "fig|$genome.peg.$pegN"; if ($pegH->{$peg}) { $hash->{$peg} = 1; } } } } } } foreach $peg_in (keys(%$pegH)) { if (! $hash->{$peg_in}) { print CONN join("\t",($peg_in,$ts_last,$curator,"connected",$sub)),"\n"; delete($pegH->{$peg_in}); } } close(SS); } $ts_last = $ts; } foreach $peg_in (keys(%$pegH)) { print CONN join("\t",($peg_in,$ts_last,$curator,"connected",$sub)),"\n"; } }