[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.2 - (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 :     if ((@ARGV > 0) && ($ARGV[0] =~ /^old/i)) {
73 :     $to_call = new ToCall($to_call_dir);
74 :     }
75 :     else {
76 :     $to_call = new NewGenome($to_call_dir);
77 :     }
78 :    
79 :     my @orf_ids = $to_call->get_fids_for_type('orf');
80 :     if (not @orf_ids) {
81 :     $to_call->possible_orfs;
82 :     @orf_ids = $to_call->get_fids_for_type('orf');
83 :     }
84 :    
85 :     my (%seq_of, %len_of, $orf_len);
86 :     for my $fid (@orf_ids) {
87 : gdpusch 1.2 if (($orf_len = $to_call->get_feature_length($fid)) > 900) {
88 : gdpusch 1.1 $len_of{$fid} = $orf_len;
89 :     $seq_of{$fid} = $to_call->get_feature_sequence($fid);
90 :     }
91 :     }
92 :    
93 :     my @peg_ids = ();
94 :     my %genomes_hit;
95 :     my %weight_of_hits;
96 :     foreach my $orf_id (sort { $len_of{$b} <=> $len_of{$a} } keys %len_of) {
97 : gdpusch 1.2
98 :     print STDERR "\nChecking $orf_id ($len_of{$orf_id})\n" if $ENV{VERBOSE};
99 : gdpusch 1.1 my ($fam, $sims) = $figfams->place_in_family($seq_of{$orf_id});
100 : gdpusch 1.2 if (not defined($fam)) {
101 :     print STDERR "\tCould not place in family --- skipping\n" if $ENV{VERBOSE};
102 :     next;
103 :     }
104 :     else {
105 : gdpusch 1.1 my $fam_id = $fam->family_id();
106 :     my $func = $fam->family_function();
107 : gdpusch 1.2 print STDERR "\tplaced in $fam_id ("
108 :     , (scalar @$sims)
109 :     , " sims)\t$func\n"
110 :     if $ENV{VERBOSE};
111 : gdpusch 1.1
112 : gdpusch 1.2 my $orf = &NewGenome::ORF::new('NewGenome::ORF', $to_call, $orf_id);
113 :     my $fid = $orf->promote_to_peg($sims, $func);
114 :     if ($fid) {
115 :     push @peg_ids, $fid;
116 :    
117 :     print FOUNDFAMS "$fid\t$fam_id\t$func\n";
118 :    
119 :     for ($i=0; ($i < $N) && ($i < @$sims); ++$i) {
120 :     ++$genomes_hit{&FIG::genome_of($sims->[$i]->id2)};
121 :     $weight_of_hits{&FIG::genome_of($sims->[$i]->id2)} +=
122 :     ($sims->[$i]->bsc / $len_of{$orf_id});
123 :     }
124 :     }
125 :     else {
126 :     die "Could not promote $orf_id";
127 : gdpusch 1.1 }
128 :     }
129 : gdpusch 1.2
130 : gdpusch 1.1 last if (@peg_ids >= $N);
131 :     }
132 :    
133 :     my $num_pegs = @peg_ids;
134 :     warn "Found $num_pegs PEG candidates\n";
135 :    
136 :     if ($num_pegs == 0) {
137 :     die "Could not find any features of sufficient length and in a FIGfam\n";
138 :     }
139 :    
140 :     my @best = sort { $weight_of_hits{$b} <=> $weight_of_hits{$a} } keys(%genomes_hit);
141 :     for ($i=0; ($i < $N) && ($i < @best); ++$i) {
142 :     print "$best[$i]\t$genomes_hit{$best[$i]}\t$weight_of_hits{$best[$i]}\n";
143 :     }
144 :     close(FOUNDFAMS);
145 :     $to_call->export_features;
146 :    
147 :     exit(0);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3