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

Annotation of /FigKernelScripts/find_neighbors_using_figfams.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : gdpusch 1.1 # -*- perl -*-
2 :     ########################################################################
3 :     # 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 :     ########################################################################
18 :    
19 :     use strict;
20 :     use warnings;
21 :    
22 :     use FIG;
23 : gdpusch 1.10 my $fig = FIG->new();
24 : gdpusch 1.1
25 : olson 1.11 use FFs;
26 : gdpusch 1.1 use ToCall;
27 :     use NewGenome;
28 :    
29 :     $0 =~ m/([^\/]+)$/o;
30 :     my $self = $1;
31 :     my $usage = "usage: $self [-fams=FigfamsData] To_Call_Dir N FoundFamilies [old] > closest.N.genomes";
32 :    
33 :     if (@ARGV && ($ARGV[0] =~ m/-h(elp)?/)) {
34 :     print STDERR "\n $usage\n\n";
35 :     exit (0);
36 :     }
37 :    
38 :     my ($i, $fam_data, $to_call_dir, $N, $foundF);
39 :    
40 : gdpusch 1.8 #...First, let's determine which FigfamsData directory to use:
41 : gdpusch 1.1 for ($i=0; ($i < @ARGV) && ($ARGV[$i] !~ /^-fams=/); $i++) {}
42 :     if ($i < @ARGV) {
43 :     if ($ARGV[$i] =~ /^-fams=(\S+)/) {
44 :     if (-d $1) {
45 :     $fam_data = $1;
46 :     }
47 :     else {
48 :     die "Nonexistent FIGfams directory $1\n";
49 :     }
50 :     splice(@ARGV,$i,1);
51 :     }
52 :     }
53 :    
54 : olson 1.11 $fam_data = $fig->get_figfams_data($fam_data);
55 :     my $figfams = new FFs($fam_data, $fig);
56 : olson 1.6
57 : gdpusch 1.1 # Now pick up the normal parameters
58 :     (
59 :     ($to_call_dir = shift @ARGV) &&
60 :     ($N = shift @ARGV) &&
61 : gdpusch 1.7 ($foundF = shift @ARGV)
62 : gdpusch 1.1 )
63 :     || die "\n $usage\n\n";
64 :    
65 :    
66 :     ### This is a bit complex. Normally, one uses this program to call genes
67 :     # in a newly-sequenced genome. In this case the functionality of NewGenome.pm
68 :     # is needed. To call genes in an existing genome (to, for example, see how well
69 :     # we are doing) you would use ToCall.pm.
70 :    
71 :     my $to_call;
72 : gdpusch 1.9 my $keep_original_calls = 0;
73 : gdpusch 1.1 if ((@ARGV > 0) && ($ARGV[0] =~ /^old/i)) {
74 : gdpusch 1.9 print STDERR qq(Re-annotating original calls\n) if $ENV{VERBOSE};
75 :     $keep_original_calls = 1;
76 : gdpusch 1.10 $to_call = ToCall->new($to_call_dir);
77 : gdpusch 1.1 }
78 :     else {
79 : gdpusch 1.10 $to_call = NewGenome->new($to_call_dir);
80 : gdpusch 1.1 }
81 :    
82 : gdpusch 1.8
83 : gdpusch 1.9 #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84 :     #...Open auxiliary files (unless "Keep Original Calls" selected)
85 :     #-----------------------------------------------------------------------
86 : gdpusch 1.8 open(FOUNDFAMS, ">>$foundF") || die "Could not append-open $foundF";
87 :    
88 : gdpusch 1.10 my $called_by_file = qq($to_call_dir/called_by);
89 : gdpusch 1.8 open(CALLED_BY, ">>$called_by_file")
90 :     || die "Could not append-open $called_by_file";
91 :    
92 :    
93 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
94 :     #...Get the current ORF-calls if they exist;
95 :     # else, try to call a set of candidate ORFs.
96 :     #-----------------------------------------------------------------------
97 : gdpusch 1.1 my @orf_ids = $to_call->get_fids_for_type('orf');
98 :     if (not @orf_ids) {
99 : gdpusch 1.8 $to_call->possible_orfs();
100 : gdpusch 1.1 @orf_ids = $to_call->get_fids_for_type('orf');
101 :     }
102 :    
103 :     my (%seq_of, %len_of, $orf_len);
104 :     for my $fid (@orf_ids) {
105 : gdpusch 1.2 if (($orf_len = $to_call->get_feature_length($fid)) > 900) {
106 : gdpusch 1.1 $len_of{$fid} = $orf_len;
107 :     $seq_of{$fid} = $to_call->get_feature_sequence($fid);
108 :     }
109 :     }
110 :    
111 : gdpusch 1.7
112 : gdpusch 1.1 my @peg_ids = ();
113 :     my %genomes_hit;
114 :     my %weight_of_hits;
115 :     foreach my $orf_id (sort { $len_of{$b} <=> $len_of{$a} } keys %len_of) {
116 : gdpusch 1.2
117 :     print STDERR "\nChecking $orf_id ($len_of{$orf_id})\n" if $ENV{VERBOSE};
118 : gdpusch 1.1 my ($fam, $sims) = $figfams->place_in_family($seq_of{$orf_id});
119 : gdpusch 1.2 if (not defined($fam)) {
120 :     print STDERR "\tCould not place in family --- skipping\n" if $ENV{VERBOSE};
121 :     next;
122 :     }
123 :     else {
124 : gdpusch 1.1 my $fam_id = $fam->family_id();
125 :     my $func = $fam->family_function();
126 : gdpusch 1.2 print STDERR "\tplaced in $fam_id ("
127 :     , (scalar @$sims)
128 :     , " sims)\t$func\n"
129 :     if $ENV{VERBOSE};
130 : gdpusch 1.1
131 : gdpusch 1.10 my $annot = [ qq(RAST),
132 :     qq($func\nCalled by "$self" using FIGfam $fam_id.)
133 :     ];
134 :    
135 :     my $orf;
136 :     if ($keep_original_calls) {
137 :     $orf = &ToCall::PEG::new( 'ToCall::PEG', $to_call, $orf_id, $seq_of{$orf_id});
138 :     }
139 :     else {
140 :     $orf = &NewGenome::ORF::new('NewGenome::ORF', $to_call, $orf_id);
141 :     }
142 :    
143 :     my $fid = $orf->promote_to_peg($sims, $func, $annot);
144 :    
145 :     if ($fid) {
146 :     print CALLED_BY "$fid\t$self\n";
147 :     print FOUNDFAMS "$fid\t$fam_id\t$func\n";
148 : overbeek 1.3 }
149 : gdpusch 1.10 else {
150 :     die "Could not promote $orf_id";
151 : gdpusch 1.9 }
152 : gdpusch 1.8
153 : gdpusch 1.2 if ($fid) {
154 :     push @peg_ids, $fid;
155 :    
156 :     for ($i=0; ($i < $N) && ($i < @$sims); ++$i) {
157 : gdpusch 1.10 my $org_2 = &FIG::genome_of($sims->[$i]->id2);
158 :     if (not defined($genomes_hit{$org_2})) {
159 :     $genomes_hit{$org_2} = 0;
160 :     $weight_of_hits{$org_2} = 0;
161 :     }
162 :    
163 :     ++$genomes_hit{$org_2};
164 :    
165 :     if ($sims->[$i]->ln2) {
166 :     $weight_of_hits{$org_2} +=
167 :     ($sims->[$i]->bsc() / $sims->[$i]->ln2());
168 :     }
169 : gdpusch 1.2 }
170 :     }
171 :     else {
172 :     die "Could not promote $orf_id";
173 : gdpusch 1.1 }
174 :     }
175 : gdpusch 1.2
176 : gdpusch 1.1 last if (@peg_ids >= $N);
177 :     }
178 :    
179 :     my $num_pegs = @peg_ids;
180 :     warn "Found $num_pegs PEG candidates\n";
181 :    
182 :     if ($num_pegs == 0) {
183 :     die "Could not find any features of sufficient length and in a FIGfam\n";
184 :     }
185 :    
186 :     my @best = sort { $weight_of_hits{$b} <=> $weight_of_hits{$a} } keys(%genomes_hit);
187 :     for ($i=0; ($i < $N) && ($i < @best); ++$i) {
188 : gdpusch 1.10 print STDOUT (join(qq(\t), ($best[$i],
189 :     $genomes_hit{$best[$i]},
190 :     $weight_of_hits{$best[$i]},
191 :     $fig->genus_species($best[$i])
192 :     )
193 :     ),
194 :     qq(\n)
195 :     );
196 : gdpusch 1.1 }
197 : gdpusch 1.10 close(CALLED_BY);
198 :     close(FOUNDFAMS);
199 : gdpusch 1.7
200 :     $to_call->export_features();
201 :    
202 : gdpusch 1.1 exit(0);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3