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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3