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

Annotation of /FigKernelScripts/promote_orfs_to_pegs.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : overbeek 1.1 # -*- perl -*-
2 : gdpusch 1.11 ########################################################################
3 : overbeek 1.1 # Copyright (c) 2003-2006 University of Chicago and Fellowship
4 :     # for Interpretations of Genomes. All Rights Reserved.
5 :     #
6 :     # This file is part of the SEED Toolkit.
7 :     #
8 :     # The SEED Toolkit is free software. You can redistribute
9 :     # it and/or modify it under the terms of the SEED Toolkit
10 :     # Public License.
11 :     #
12 :     # You should have received a copy of the SEED Toolkit Public License
13 :     # along with this program; if not write to the University of Chicago
14 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
15 :     # Genomes at veronika@thefig.info or download a copy from
16 :     # http://www.theseed.org/LICENSE.TXT.
17 : gdpusch 1.11 ########################################################################
18 : overbeek 1.1
19 : olson 1.9 use strict;
20 : gdpusch 1.13 use warnings;
21 :    
22 : overbeek 1.1 use FIG;
23 : gdpusch 1.14 my $fig = FIG->new();
24 : overbeek 1.1
25 :     use NewGenome;
26 :     use ToCall;
27 :    
28 : gdpusch 1.13 $0 =~ m/([^\/]+)$/o;
29 :     my $self = $1;
30 : overbeek 1.5 my $usage = "usage: promote_orfs_to_pegs To_Call_Dir FoundFamiliesFile";
31 : overbeek 1.1
32 :     if (@ARGV && ($ARGV[0] =~ m/-h(elp)?/)) {
33 :     print STDERR "\n $usage\n\n";
34 :     exit (0);
35 :     }
36 :    
37 : overbeek 1.5 my ($to_call_dir, $found_file);
38 : overbeek 1.1
39 :     (
40 :     ($to_call_dir = shift @ARGV)
41 : overbeek 1.5 &&
42 :     ($found_file = shift @ARGV)
43 : overbeek 1.1 )
44 : overbeek 1.2 || die "\n $usage\n\n";
45 : overbeek 1.1
46 : overbeek 1.3 $to_call_dir =~ s/\/$//o;
47 :    
48 : overbeek 1.1 my $to_call;
49 : gdpusch 1.13 $to_call = NewGenome->new($to_call_dir, "all");
50 : overbeek 1.5
51 : gdpusch 1.14
52 :     my @neighbors = ();
53 :     my $neighbors_file;
54 :     if ((-s ($neighbors_file = "$to_call_dir/closest.genomes")) ||
55 :     (-s ($neighbors_file = "$to_call_dir/neighbors"))
56 :     ) {
57 :     @neighbors = map { m/^(\d+\.\d+)/o ? ($1) : () } &FIG::file_read($neighbors_file);
58 :     }
59 :    
60 : overbeek 1.5
61 : gdpusch 1.13 open(CALLED_BY, ">>$to_call_dir/called_by")
62 :     || die "could not open $to_call_dir/called_by";
63 :    
64 : overbeek 1.5 #...Build file of "nearby" PEGs
65 : gdpusch 1.12 if (@neighbors) {
66 :     my $tmp_close = "$FIG_Config::temp/tmp_close_$$.fasta";
67 :     system("/bin/rm -f $tmp_close*");
68 : overbeek 1.5
69 : gdpusch 1.12 foreach my $org (@neighbors) {
70 :     print STDERR "Appending $org to $tmp_close\n" if $ENV{VERBOSE};
71 :     system("cat $FIG_Config::organisms/$org/Features/peg/fasta >> $tmp_close");
72 : overbeek 1.5 }
73 : gdpusch 1.12 &FIG::run("formatdb -i$tmp_close -pT");
74 :    
75 :     my @promoted_fids;
76 :     my $tmp_sims = "$FIG_Config::temp/tmp_sims.$$";
77 :     open(TMP_SIMS, ">$tmp_sims")
78 :     || die "Could not write-open $tmp_sims";
79 :     foreach my $orf_id ($to_call->get_fids_for_type('orf')) {
80 :     if (@neighbors) {
81 :     my $sims = &blast_against($to_call->get_feature_sequence($orf_id), $tmp_close);
82 :    
83 :     if (@$sims) {
84 : gdpusch 1.13 my $num_sims = (scalar @$sims);
85 :     print STDERR "Promoting $orf_id based on $num_sims sims\n" if $ENV{VERBOSE};
86 : gdpusch 1.12
87 :     my $orf = &NewGenome::ORF::new('NewGenome::ORF', $to_call, $orf_id);
88 : gdpusch 1.13 my $annot = [ qq(RAST),
89 :     qq(Called by "$self" based on $num_sims sims.)
90 :     ];
91 :     my $fid = $orf->promote_to_peg($sims, undef, $annot);
92 :     if ($fid) {
93 :     push @promoted_fids, $fid;
94 :     @$sims = map { $_->[0] = $fid; $_ } @$sims;
95 :     print TMP_SIMS map { join("\t", @$_) . qq(\n) } @$sims;
96 :    
97 :     print CALLED_BY "$fid\tpromote_remaining_orfs (with sims)\n";
98 :    
99 :     print STDERR "Succeeded:\t$orf_id --> $fid\n";
100 :     }
101 :     else {
102 :     print STDERR "Could not promote ORF $orf_id to a PEG\n";
103 :     }
104 : gdpusch 1.12 }
105 :     else {
106 :     print STDERR "No sims for $orf_id\n" if $ENV{VERBOSE};
107 :     }
108 :     }
109 : overbeek 1.5 }
110 : gdpusch 1.12 close(TMP_SIMS) || die "Could not close $tmp_sims";
111 : overbeek 1.5
112 : gdpusch 1.12 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
113 : olson 1.8 # Disable the auto assignment of the fids we just called.
114 : gdpusch 1.12 #=======================================================================
115 :     if (0)
116 :     {
117 :     my $tmp_seqs = "$FIG_Config::temp/tmp_seqs.$$";
118 :     open(TMP_SEQS, ">$tmp_seqs")
119 :     || die "Could not write-open $tmp_seqs";
120 :     print TMP_SEQS map { join("\t", ($_, $to_call->get_feature_sequence($_))) . qq(\n) } @promoted_fids;
121 :     close(TMP_SEQS) || die "Could not close $tmp_seqs";
122 :     my @auto_assigns = `cat $tmp_seqs | auto_assign sims=$tmp_sims`;
123 :    
124 :     open(FOUND, ">>$found_file")
125 : gdpusch 1.13 || die "Could not append-open FoundFamiliesFile $found_file";
126 : gdpusch 1.12 foreach my $entry (@auto_assigns) {
127 :     if ($entry =~ m/^(\S+)\t(.*)$/o) {
128 :     if ($to_call->set_function($1, $2)) {
129 :     print FOUND "$1\tCLOSE_SIMS\t$2\n";
130 :     }
131 :     else {
132 :     die "Could not set function of $1 to $2";
133 :     }
134 : olson 1.8 }
135 :     else {
136 : gdpusch 1.12 die "Could not parse auto-assignment: $entry";
137 : olson 1.8 }
138 : overbeek 1.5 }
139 : gdpusch 1.12 close(FOUND) || die "Could not close $found_file";
140 :     unlink($tmp_seqs) || die "Could not remove $tmp_seqs";
141 : overbeek 1.5 }
142 : gdpusch 1.12
143 :     unlink($tmp_sims) || die "Could not remove $tmp_sims";
144 :     unlink($tmp_close) || die "Could not remove $tmp_close";
145 : overbeek 1.5 }
146 : gdpusch 1.12 #-----------------------------------------------------------------------
147 :    
148 : overbeek 1.5
149 : gdpusch 1.12 #...Promote any remaining unpromoted ORFs...
150 : gdpusch 1.13 $to_call->promote_remaining_orfs(\*CALLED_BY);
151 : gdpusch 1.11
152 : gdpusch 1.13 close(CALLED_BY);
153 : gdpusch 1.12
154 :     #...NOTE: export_features also writes assigned_functions
155 : overbeek 1.1 $to_call->export_features;
156 : overbeek 1.2
157 : olson 1.10
158 : overbeek 1.4 if (! -s "$to_call_dir/Features/orf/tbl") {
159 : olson 1.6 # Hrm, weird NFS effects here. There was a failure of this even though the directory
160 :     # was indeed empty.
161 : gdpusch 1.7 if (system("/bin/rm -fRv $to_call_dir/Features/orf")) {
162 : olson 1.6 warn "First remove did not work; sleeping and trying again";
163 : gdpusch 1.7 sleep(30);
164 :     system("/bin/rm -fRv $to_call_dir/Features/orf");
165 : olson 1.6 }
166 : overbeek 1.2 }
167 :     else {
168 :     die "Something is wrong --- $to_call_dir/Features/orf/tbl is non-empty";
169 :     }
170 : gdpusch 1.12 exit(0);
171 : overbeek 1.5
172 :    
173 :    
174 :     sub blast_against {
175 :     my ($seq, $db) = @_;
176 :     my $seq_len = length($seq);
177 :    
178 :     my $tmp_seq = "$FIG_Config::temp/tmp_seq.$$";
179 :     open( TMP, ">$tmp_seq" ) || die "Could not write-open $tmp_seq";
180 :     print TMP ">query\n$seq\n";
181 :     close(TMP) || die "Could not close $tmp_seq";
182 :    
183 :     my $sims = [];
184 :     @$sims = map { chomp $_;
185 : olson 1.9 my @x = split(/\t/, $_);
186 : overbeek 1.5 push @x, ($seq_len, $fig->translation_length($x[1]));
187 :     bless( [@x], "Sim" )
188 :     } `blastall -i $tmp_seq -d $db -p blastp -m8 -e1.0e-10`;
189 :    
190 :     unlink($tmp_seq) || die "Could not unlink $tmp_seq";
191 :     return $sims;
192 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3