[Bio] / FortyEight / rp_gen_teach_sims.pl Repository:
ViewVC logotype

Annotation of /FortyEight/rp_gen_teach_sims.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : olson 1.1
2 :     #
3 :     # Given the computed glimmer and critica calls from earlier runs of rp_glimmer
4 :     # and rp_critica, use build_nr to compute the mappings between these calls and
5 :     # the peg calls in the genome, extract the sims that we can from the
6 :     # precomputed sims, and compute the remaining sims as needed.
7 :     #
8 :    
9 :     use Data::Dumper;
10 :     use Carp;
11 :     use strict;
12 :     use Job48;
13 :     use FIGV;
14 :     use FIG;
15 :     use FIG_Config;
16 :     use File::Basename;
17 :     use GenomeMeta;
18 :     use Sim;
19 :    
20 :     @ARGV == 1 or die "Usage: $0 job-dir\n";
21 :    
22 :     my $jobdir = shift;
23 :    
24 :     -d $jobdir or die "$0: job dir $jobdir does not exist\n";
25 :    
26 :     my $job = new Job48($jobdir);
27 :     $job or die "cannot create job for $jobdir";
28 :    
29 :     my $hostname = `hostname`;
30 :     chomp $hostname;
31 :    
32 :     my $genome = $job->genome_id();
33 :     my $meta = $job->meta();
34 :    
35 :     $meta->add_log_entry($0, "start teach-sims processing on $hostname in $jobdir");
36 :    
37 :    
38 :     my $work = "$jobdir/teach_sims_work";
39 :     my $orgdir = "$jobdir/rp/$genome";
40 :    
41 :     &FIG::verify_dir($work);
42 :     chdir $work or &fatal("chdir $work failed: $!");
43 :    
44 :     open(SRCS, ">$work/nr.sources") or &fatal("cannot write $work/nr.sources: $!");
45 :    
46 :     for my $type (qw(peg glimmer critica))
47 :     {
48 :     print SRCS "$orgdir/Features/$type/fasta\n";
49 :     }
50 :     close(SRCS);
51 :    
52 :     &run("$FIG_Config::bin/build_nr",
53 :     "-emit-singletons",
54 :     "$work/nr.sources", "/dev/null", "/dev/null",
55 :     "$work/teach.nr", "$work/teach.ps");
56 :    
57 :     #
58 :     # Read the generated peg.synonyms. We are going to build a list
59 :     # @sims_to_compute of xxx ids that do not have peg ids.
60 :     # Also compute the mapping %peg_to_teach of pegid => [id]
61 :     # for the ids that do map to pegs.
62 :     #
63 :    
64 :     my @sims_to_compute;
65 :     my %peg_to_teach;
66 :     my %xxx_to_teach;
67 :    
68 :     open(PULL, "| $FIG_Config::bin/pull_fasta_entries $work/teach.nr > $work/sims.nr") or
69 :     &fatal("cannot open pull pipeline: $!");
70 :    
71 :     open(PS, "<$work/teach.ps") or &fatal("Cannot open $work/teach.ps: $!");
72 :    
73 :     while (<PS>)
74 :     {
75 :     chomp;
76 :     if (/^([^,]+),(\d+)\t(.*)/)
77 :     {
78 :     my $ps = $1;
79 :     my $ps_len = $2;
80 :     my @pairs = map { [ split(/,/, $_) ] } split(/;/, $3);
81 :    
82 :     my @pegs = grep { $_->[0] =~ /^fig\|\d+\.\d+\.peg/ } @pairs;
83 :     my @rest = grep { $_->[0] !~ /^fig\|\d+\.\d+\.peg/ } @pairs;
84 :     # print Dumper(\@pairs, \@pegs, \@rest);
85 :    
86 :     if (@pegs)
87 :     {
88 :     my $rep = $pegs[0]->[0];
89 :     $peg_to_teach{$rep} = [@rest];
90 :     }
91 :     else
92 :     {
93 :     push(@sims_to_compute, $ps);
94 :     $xxx_to_teach{$ps} = [@rest];
95 :     print PULL "$ps\n";
96 :     }
97 :     }
98 :     }
99 :     print Dumper(\@sims_to_compute, \%xxx_to_teach, \%peg_to_teach);
100 :     close(PS);
101 :     if (!close(PULL))
102 :     {
103 :     &fatal("error closing pull pipeline; \$!=$! \$?=$?");
104 :     }
105 :    
106 :     $meta->add_log_entry($0, "finish critica computation on $jobdir");
107 :     $meta->set_metadata("status.critica", "complete");
108 :     exit(0);
109 :    
110 :    
111 :     sub run
112 :     {
113 :     my(@cmd) = @_;
114 :     print "Run @cmd\n";
115 :     my $rc = system(@cmd);
116 :     $rc == 0 or &fatal("Cmd failed with rc=$rc: @cmd");
117 :     }
118 :    
119 :     sub fatal
120 :     {
121 :     my($msg) = @_;
122 :    
123 :     if ($meta)
124 :     {
125 :     $meta->add_log_entry($0, ['fatal error', $msg]);
126 :     $meta->set_metadata("status.bbhs", "error");
127 :     }
128 :    
129 :     croak "$0: $msg";
130 :     }
131 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3