[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.7 - (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 :     my $fig = new FIG;
24 :    
25 :     use FigFams;
26 :     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 :     # First, let's determine which FigfamsData directory to use
41 : olson 1.6
42 : gdpusch 1.1 for ($i=0; ($i < @ARGV) && ($ARGV[$i] !~ /^-fams=/); $i++) {}
43 :     if ($i < @ARGV) {
44 :     if ($ARGV[$i] =~ /^-fams=(\S+)/) {
45 :     if (-d $1) {
46 :     $fam_data = $1;
47 :     }
48 :     else {
49 :     die "Nonexistent FIGfams directory $1\n";
50 :     }
51 :     splice(@ARGV,$i,1);
52 :     }
53 :     }
54 :    
55 : olson 1.6 my $figfams = new FigFams($fig, $fam_data);
56 :    
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 : overbeek 1.3 my $old;
73 :    
74 : gdpusch 1.1 if ((@ARGV > 0) && ($ARGV[0] =~ /^old/i)) {
75 : overbeek 1.3 $old = 1;
76 : gdpusch 1.1 $to_call = new ToCall($to_call_dir);
77 :     }
78 :     else {
79 :     $to_call = new NewGenome($to_call_dir);
80 :     }
81 :    
82 :     my @orf_ids = $to_call->get_fids_for_type('orf');
83 :     if (not @orf_ids) {
84 :     $to_call->possible_orfs;
85 :     @orf_ids = $to_call->get_fids_for_type('orf');
86 :     }
87 :    
88 :     my (%seq_of, %len_of, $orf_len);
89 :     for my $fid (@orf_ids) {
90 : gdpusch 1.2 if (($orf_len = $to_call->get_feature_length($fid)) > 900) {
91 : gdpusch 1.1 $len_of{$fid} = $orf_len;
92 :     $seq_of{$fid} = $to_call->get_feature_sequence($fid);
93 :     }
94 :     }
95 :    
96 : gdpusch 1.7 open(FOUNDFAMS, ">>$foundF") || die "Could not append-open $foundF";
97 :    
98 :     my $called_by_file = "$to_call_dir/called_by";
99 :     open(CALLED_BY, ">>$called_by_file")
100 :     || die "Could not append-open $called_by_file";
101 :    
102 : gdpusch 1.1 my @peg_ids = ();
103 :     my %genomes_hit;
104 :     my %weight_of_hits;
105 :     foreach my $orf_id (sort { $len_of{$b} <=> $len_of{$a} } keys %len_of) {
106 : gdpusch 1.2
107 :     print STDERR "\nChecking $orf_id ($len_of{$orf_id})\n" if $ENV{VERBOSE};
108 : gdpusch 1.1 my ($fam, $sims) = $figfams->place_in_family($seq_of{$orf_id});
109 : gdpusch 1.2 if (not defined($fam)) {
110 :     print STDERR "\tCould not place in family --- skipping\n" if $ENV{VERBOSE};
111 :     next;
112 :     }
113 :     else {
114 : gdpusch 1.1 my $fam_id = $fam->family_id();
115 :     my $func = $fam->family_function();
116 : gdpusch 1.2 print STDERR "\tplaced in $fam_id ("
117 :     , (scalar @$sims)
118 :     , " sims)\t$func\n"
119 :     if $ENV{VERBOSE};
120 : gdpusch 1.1
121 : overbeek 1.3 my $fid;
122 :     if (! $old)
123 :     {
124 : gdpusch 1.7 my $annot = [ qq(RAST),
125 :     qq($func\nCalled by "$self" using FIGfam $fam_id.)
126 :     ];
127 :     my $orf = &NewGenome::ORF::new('NewGenome::ORF', $to_call, $orf_id);
128 :     $fid = $orf->promote_to_peg($sims, $func, $annot);
129 : overbeek 1.3 }
130 :     else
131 :     {
132 :     $fid = $orf_id;
133 :     }
134 :    
135 : gdpusch 1.2 if ($fid) {
136 :     push @peg_ids, $fid;
137 :    
138 : gdpusch 1.7 print CALLED_BY "$fid\t$self\n";
139 : gdpusch 1.2 print FOUNDFAMS "$fid\t$fam_id\t$func\n";
140 :    
141 :     for ($i=0; ($i < $N) && ($i < @$sims); ++$i) {
142 :     ++$genomes_hit{&FIG::genome_of($sims->[$i]->id2)};
143 :     $weight_of_hits{&FIG::genome_of($sims->[$i]->id2)} +=
144 : gdpusch 1.4 ($sims->[$i]->bsc / $sims->[$i]->ln2);
145 : gdpusch 1.2 }
146 :     }
147 :     else {
148 :     die "Could not promote $orf_id";
149 : gdpusch 1.1 }
150 :     }
151 : gdpusch 1.2
152 : gdpusch 1.1 last if (@peg_ids >= $N);
153 :     }
154 :    
155 :     my $num_pegs = @peg_ids;
156 :     warn "Found $num_pegs PEG candidates\n";
157 :    
158 :     if ($num_pegs == 0) {
159 :     die "Could not find any features of sufficient length and in a FIGfam\n";
160 :     }
161 :    
162 :     my @best = sort { $weight_of_hits{$b} <=> $weight_of_hits{$a} } keys(%genomes_hit);
163 :     for ($i=0; ($i < $N) && ($i < @best); ++$i) {
164 :     print "$best[$i]\t$genomes_hit{$best[$i]}\t$weight_of_hits{$best[$i]}\n";
165 :     }
166 : gdpusch 1.7
167 :     $to_call->export_features();
168 :    
169 :     close(CALLED_BY);
170 : gdpusch 1.1 close(FOUNDFAMS);
171 :    
172 :     exit(0);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3