[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.1 - (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 :     my $genomesH = $sapO->all_genomes(-complete => 1);
33 :     open(CLOSE,">$gdir/closest.genomes") || die "could not open closest.genomes";
34 :     foreach my $g2 (@reference)
35 :     {
36 :     &generate_correspondence_table($g2,$gdir);
37 :     print CLOSE join("\t",($g2,$genomesH->{$g2})),"\n";
38 :     }
39 :     close(CLOSE);
40 :    
41 :     sub generate_correspondence_table {
42 :     my($g2,$gdir) = @_;
43 :    
44 :     ($gdir =~ /(\d+\.\d+)$/) || die "Invalid Genome Directory: $gdir";
45 :     my $g1 = $1;
46 :     system "svr_corresponding_genes -d $gdir $g1 $g2 > $gdir/CorrToReferenceGenomes/$g2";
47 :     }
48 :    
49 :     sub prioritize_pegs_used_to_find_neighbors {
50 :     my($gdir) = @_;
51 :    
52 :     my %by_func;
53 :     (-s "$gdir/assigned_functions") || die "$gdir contains no assigned_functions";
54 :    
55 :     foreach my $line (`cat $gdir/assigned_functions`)
56 :     {
57 :     if ($line =~ /^(fig\|\d+\.\d+\.peg\.\d+)\t(\S[^\#]+\S)/)
58 :     {
59 :     my($peg,$func) = ($1,$2);
60 :     $func =~ s/\s*\#$//;
61 :     push(@{$by_func{$2}},$1);
62 :     }
63 :     }
64 :     my @synthetases = map {[$_,$by_func{$_}->[0]] } grep { @{$by_func{$_}} == 1 } grep { $_ =~ /tRNA synthetase/ } keys(%by_func);
65 :     my @ribosomal_proteins = map {[$_,$by_func{$_}->[0]] } grep { @{$by_func{$_}} == 1 } grep { $_ =~ /ribosomal protein/ } keys(%by_func);
66 :     my @ok_pegs = map {[$_,$by_func{$_}->[0]] } grep { @{$by_func{$_}} == 1 } keys(%by_func);
67 :     my @prioritized = ();
68 :     my %seen;
69 :     foreach my $tuple (@synthetases,@ribosomal_proteins,@ok_pegs)
70 :     {
71 :     if (! $seen{$tuple->[0]})
72 :     {
73 :     $seen{$tuple->[0]} = 1;
74 :     push(@prioritized,$tuple);
75 :     }
76 :     }
77 :     return @prioritized;
78 :     }
79 :    
80 :     sub compute_hits_and_set_best {
81 :     my($tuple,$id2seqH,$counts,$bestP) = @_;
82 :    
83 :     my($role,$peg) = @$tuple;
84 :     my $figfam_pegs = &figfam_pegs_for_role($role);
85 :    
86 :     my @sims = &ProtSims::blastP([[$peg,'',$id2seqH->{$peg}]],$figfam_pegs,10);
87 :     my $i;
88 :     for ($i=0; (($i < @sims) && ($i < 50)); $i++)
89 :     {
90 :     my $g2 = &SeedUtils::genome_of($sims[$i]->id2);
91 :     $counts->{$g2} += 50 - $i;
92 :     if ($counts->{$g2} > $$bestP) { $$bestP = $counts->{$g2} }
93 :     }
94 :     }
95 :    
96 :     #### MUST update ###
97 :     sub figfam_pegs_for_role {
98 :     my($role) = @_;
99 :    
100 :     my %figfams;
101 :     foreach $_ (`cat /Users/rossoverbeek/FIGdisk/FIG/Data/FigfamsData/family.functions`)
102 :     {
103 :     if ((index($_,$role) >= 0) && ($_ =~ /^(FIG\d{6})/))
104 :     {
105 :     $figfams{$1} = 1;
106 :     }
107 :     }
108 :     my $sapO = SAPserver->new;
109 :     my $genomesH = $sapO->all_genomes(-complete => 1);
110 :     my @ids = grep { $genomesH->{&SeedUtils::genome_of($_)} }
111 :     map { (($_ =~ /^(\S+)\t(\S+)/) && $figfams{$1}) ? $2 : () }
112 :     `cat /Users/rossoverbeek/FIGdisk/FIG/Data/FigfamsData/families.2c`;
113 :     my $sapO = SAPserver->new;
114 :     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