[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.1 - (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 :     my $figfams = new FigFams;
27 :    
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 :     if ($orf_len = $to_call->get_feature_length($fid) > 900) {
88 :     $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 :     my ($fam, $sims) = $figfams->place_in_family($seq_of{$orf_id});
98 :     if (@$sims >= $N) {
99 :    
100 :     my $fid = $to_call->promote_to_peg($orf_id);
101 :     push @peg_ids, $fid;
102 :    
103 :     my $fam_id = $fam->family_id();
104 :     my $func = $fam->family_function();
105 :     print FOUNDFAMS "$fid\t$fam_id\t$func\n";
106 :    
107 :     for ($i=0; ($i < $N) && ($i < @$sims); ++$i) {
108 :     ++$genomes_hit{&FIG::genome_of($sims->[$i]->id2)};
109 :     $weight_of_hits{&FIG::genome_of($sims->[$i]->id2)} += $sims->[$i]->bsc;
110 :     }
111 :     }
112 :     last if (@peg_ids >= $N);
113 :     }
114 :    
115 :     my $num_pegs = @peg_ids;
116 :     warn "Found $num_pegs PEG candidates\n";
117 :    
118 :     if ($num_pegs == 0) {
119 :     die "Could not find any features of sufficient length and in a FIGfam\n";
120 :     }
121 :    
122 :     my @best = sort { $weight_of_hits{$b} <=> $weight_of_hits{$a} } keys(%genomes_hit);
123 :     for ($i=0; ($i < $N) && ($i < @best); ++$i) {
124 :     print "$best[$i]\t$genomes_hit{$best[$i]}\t$weight_of_hits{$best[$i]}\n";
125 :     }
126 :     close(FOUNDFAMS);
127 :     $to_call->export_features;
128 :    
129 :     exit(0);

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3