[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.4 - (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 : gdpusch 1.2 my $figfams = new FigFams($fig);
27 : gdpusch 1.1
28 :     use ToCall;
29 :     use NewGenome;
30 :    
31 :     $0 =~ m/([^\/]+)$/o;
32 :     my $self = $1;
33 :     my $usage = "usage: $self [-fams=FigfamsData] To_Call_Dir N FoundFamilies [old] > closest.N.genomes";
34 :    
35 :     if (@ARGV && ($ARGV[0] =~ m/-h(elp)?/)) {
36 :     print STDERR "\n $usage\n\n";
37 :     exit (0);
38 :     }
39 :    
40 :     my ($i, $fam_data, $to_call_dir, $N, $foundF);
41 :    
42 :     # First, let's determine which FigfamsData directory to use
43 :     $fam_data = "$FIG_Config::data/FigfamsData";
44 :     for ($i=0; ($i < @ARGV) && ($ARGV[$i] !~ /^-fams=/); $i++) {}
45 :     if ($i < @ARGV) {
46 :     if ($ARGV[$i] =~ /^-fams=(\S+)/) {
47 :     if (-d $1) {
48 :     $fam_data = $1;
49 :     }
50 :     else {
51 :     die "Nonexistent FIGfams directory $1\n";
52 :     }
53 :     splice(@ARGV,$i,1);
54 :     }
55 :     }
56 :    
57 :     # Now pick up the normal parameters
58 :     (
59 :     ($to_call_dir = shift @ARGV) &&
60 :     ($N = shift @ARGV) &&
61 :     ($foundF = shift @ARGV) && open(FOUNDFAMS, ">>$foundF")
62 :     )
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 :     my @peg_ids = ();
97 :     my %genomes_hit;
98 :     my %weight_of_hits;
99 :     foreach my $orf_id (sort { $len_of{$b} <=> $len_of{$a} } keys %len_of) {
100 : gdpusch 1.2
101 :     print STDERR "\nChecking $orf_id ($len_of{$orf_id})\n" if $ENV{VERBOSE};
102 : gdpusch 1.1 my ($fam, $sims) = $figfams->place_in_family($seq_of{$orf_id});
103 : gdpusch 1.2 if (not defined($fam)) {
104 :     print STDERR "\tCould not place in family --- skipping\n" if $ENV{VERBOSE};
105 :     next;
106 :     }
107 :     else {
108 : gdpusch 1.1 my $fam_id = $fam->family_id();
109 :     my $func = $fam->family_function();
110 : gdpusch 1.2 print STDERR "\tplaced in $fam_id ("
111 :     , (scalar @$sims)
112 :     , " sims)\t$func\n"
113 :     if $ENV{VERBOSE};
114 : gdpusch 1.1
115 : overbeek 1.3 my $fid;
116 :     if (! $old)
117 :     {
118 :     my $orf = &NewGenome::ORF::new('NewGenome::ORF', $to_call, $orf_id);
119 :     $fid = $orf->promote_to_peg($sims, $func);
120 :     }
121 :     else
122 :     {
123 :     $fid = $orf_id;
124 :     }
125 :    
126 : gdpusch 1.2 if ($fid) {
127 :     push @peg_ids, $fid;
128 :    
129 :     print FOUNDFAMS "$fid\t$fam_id\t$func\n";
130 :    
131 :     for ($i=0; ($i < $N) && ($i < @$sims); ++$i) {
132 :     ++$genomes_hit{&FIG::genome_of($sims->[$i]->id2)};
133 :     $weight_of_hits{&FIG::genome_of($sims->[$i]->id2)} +=
134 : gdpusch 1.4 ($sims->[$i]->bsc / $sims->[$i]->ln2);
135 : gdpusch 1.2 }
136 :     }
137 :     else {
138 :     die "Could not promote $orf_id";
139 : gdpusch 1.1 }
140 :     }
141 : gdpusch 1.2
142 : gdpusch 1.1 last if (@peg_ids >= $N);
143 :     }
144 :    
145 :     my $num_pegs = @peg_ids;
146 :     warn "Found $num_pegs PEG candidates\n";
147 :    
148 :     if ($num_pegs == 0) {
149 :     die "Could not find any features of sufficient length and in a FIGfam\n";
150 :     }
151 :    
152 :     my @best = sort { $weight_of_hits{$b} <=> $weight_of_hits{$a} } keys(%genomes_hit);
153 :     for ($i=0; ($i < $N) && ($i < @best); ++$i) {
154 :     print "$best[$i]\t$genomes_hit{$best[$i]}\t$weight_of_hits{$best[$i]}\n";
155 :     }
156 :     close(FOUNDFAMS);
157 :     $to_call->export_features;
158 :    
159 :     exit(0);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3