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

Annotation of /FigKernelScripts/get_neighbors_and_corr_to_ref.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : overbeek 1.1 ########################################################################
2 :    
3 :     use SeedHTML;
4 :     use strict;
5 :     use SeedEnv;
6 :     use ProtSims;
7 :     use gjoseqlib;
8 :    
9 :     my $usage = "usage: get_neighbors_and_corr_to_ref GenomeDir";
10 :     my $gdir;
11 :    
12 :     ($gdir = shift @ARGV)
13 :     || die $usage;
14 :    
15 :     my @fasta = &gjoseqlib::read_fasta("$gdir/Features/peg/fasta");
16 :     my %id2seqH = map { $_->[0] => $_->[2] } @fasta;
17 :    
18 :     &SeedUtils::verify_dir("$gdir/CorrToReferenceGenomes");
19 :     my @poss_pegs = &prioritize_pegs_used_to_find_neighbors($gdir);
20 :    
21 :     my %counts;
22 :     my $best = 0;
23 :     my $tuple;
24 :     while (($best < 500) && ($tuple = shift @poss_pegs))
25 :     {
26 :     &compute_hits_and_set_best($tuple,\%id2seqH,\%counts,\$best);
27 :     }
28 :     if ($best == 0) { die "$gdir describes a genome without enough RAST-called genes to identify neighbors" }
29 :     my @reference = sort { $counts{$b} <=> $counts{$a} } keys(%counts);
30 :     if (@reference > 30) { $#reference = 29 }
31 :    
32 : overbeek 1.2 my $sapO = SAPserver->new;
33 : overbeek 1.1 my $genomesH = $sapO->all_genomes(-complete => 1);
34 :     open(CLOSE,">$gdir/closest.genomes") || die "could not open closest.genomes";
35 :     foreach my $g2 (@reference)
36 :     {
37 :     &generate_correspondence_table($g2,$gdir);
38 :     print CLOSE join("\t",($g2,$genomesH->{$g2})),"\n";
39 :     }
40 :     close(CLOSE);
41 :    
42 :     sub generate_correspondence_table {
43 :     my($g2,$gdir) = @_;
44 :    
45 :     ($gdir =~ /(\d+\.\d+)$/) || die "Invalid Genome Directory: $gdir";
46 :     my $g1 = $1;
47 :     system "svr_corresponding_genes -d $gdir $g1 $g2 > $gdir/CorrToReferenceGenomes/$g2";
48 :     }
49 :    
50 :     sub prioritize_pegs_used_to_find_neighbors {
51 :     my($gdir) = @_;
52 :    
53 :     my %by_func;
54 :     (-s "$gdir/assigned_functions") || die "$gdir contains no assigned_functions";
55 :    
56 :     foreach my $line (`cat $gdir/assigned_functions`)
57 :     {
58 :     if ($line =~ /^(fig\|\d+\.\d+\.peg\.\d+)\t(\S[^\#]+\S)/)
59 :     {
60 :     my($peg,$func) = ($1,$2);
61 :     $func =~ s/\s*\#$//;
62 :     push(@{$by_func{$2}},$1);
63 :     }
64 :     }
65 :     my @synthetases = map {[$_,$by_func{$_}->[0]] } grep { @{$by_func{$_}} == 1 } grep { $_ =~ /tRNA synthetase/ } keys(%by_func);
66 :     my @ribosomal_proteins = map {[$_,$by_func{$_}->[0]] } grep { @{$by_func{$_}} == 1 } grep { $_ =~ /ribosomal protein/ } keys(%by_func);
67 :     my @ok_pegs = map {[$_,$by_func{$_}->[0]] } grep { @{$by_func{$_}} == 1 } keys(%by_func);
68 :     my @prioritized = ();
69 :     my %seen;
70 :     foreach my $tuple (@synthetases,@ribosomal_proteins,@ok_pegs)
71 :     {
72 :     if (! $seen{$tuple->[0]})
73 :     {
74 :     $seen{$tuple->[0]} = 1;
75 :     push(@prioritized,$tuple);
76 :     }
77 :     }
78 :     return @prioritized;
79 :     }
80 :    
81 :     sub compute_hits_and_set_best {
82 :     my($tuple,$id2seqH,$counts,$bestP) = @_;
83 :    
84 :     my($role,$peg) = @$tuple;
85 :     my $figfam_pegs = &figfam_pegs_for_role($role);
86 :    
87 :     my @sims = &ProtSims::blastP([[$peg,'',$id2seqH->{$peg}]],$figfam_pegs,10);
88 :     my $i;
89 :     for ($i=0; (($i < @sims) && ($i < 50)); $i++)
90 :     {
91 :     my $g2 = &SeedUtils::genome_of($sims[$i]->id2);
92 :     $counts->{$g2} += 50 - $i;
93 :     if ($counts->{$g2} > $$bestP) { $$bestP = $counts->{$g2} }
94 :     }
95 :     }
96 :    
97 :     #### MUST update ###
98 :     sub figfam_pegs_for_role {
99 :     my($role) = @_;
100 :    
101 :     my %figfams;
102 : overbeek 1.3 foreach $_ (`cat $FIG_Config::FigfamsData/family.functions`)
103 : overbeek 1.1 {
104 :     if ((index($_,$role) >= 0) && ($_ =~ /^(FIG\d{6})/))
105 :     {
106 :     $figfams{$1} = 1;
107 :     }
108 :     }
109 :     my $sapO = SAPserver->new;
110 :     my $genomesH = $sapO->all_genomes(-complete => 1);
111 :     my @ids = grep { $genomesH->{&SeedUtils::genome_of($_)} }
112 :     map { (($_ =~ /^(\S+)\t(\S+)/) && $figfams{$1}) ? $2 : () }
113 : overbeek 1.3 `cat $FIG_Config::FigfamsData/families.2c`;
114 : overbeek 1.1 my $idsH = $sapO->ids_to_sequences(-ids => \@ids, -protein => 1);
115 :     return [map { my $seq = $idsH->{$_}; $seq ? [$_,'',$seq] : () } keys(%$idsH)];
116 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3