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

Diff of /FigKernelScripts/FFB2_build_updated_FF.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Mon Nov 16 21:56:22 2009 UTC revision 1.10, Mon Jul 12 20:04:03 2010 UTC
# Line 1  Line 1 
1  ########################################################################  ########################################################################
2    
3    use strict;
4  use FIG;  use FIG;
5    use IPC::Run qw(start finish);
6    use Cache::Memcached::Fast;
7    
8  my $usage = "usage: FFB2_build_updated_FF OldReleaseDir NewReleaseDir";  my $usage = "usage: FFB2_build_updated_FF OldReleaseDir NewReleaseDir memcache-host memcache-port [ssfam]";
9    
10  my($oldD,$newD);  my($oldD,$newD,$mchost, $mcport);
11    
12  (  (
13   ($oldD = shift @ARGV) && (-d $oldD) &&   ($oldD = shift @ARGV) && (-d $oldD) &&
14   ($newD = shift @ARGV)   ($newD = shift @ARGV) &&
15     ($mchost = shift @ARGV) &&
16     ($mcport = shift @ARGV)
17  )  )
18      || die $usage;      || die $usage;
19    
20    my $in_ssfam = shift;
21    
22    my $sort_args = "-T $FIG_Config::temp -S 4G";
23    
24  mkdir($newD,0777) || die "You have an existing $newD; remove it and try again";  mkdir($newD,0777) || die "You have an existing $newD; remove it and try again";
 &FIG::run("FFB2_update_FIGfams $newD/families.2c $newD/family.functions $oldD");  
 &FIG::run("FFB2_get_oligos $newD/families.2c $newD/family.functions 2> $newD/function.index |" .  
           "sort -T . | FFB2_usable_motifs $newD/Kmers");  
25    
26  &FIG::run("FFB2_get_prots $newD/ProtsByGenomeSet $newD/setI");  my $mc = new Cache::Memcached::Fast({ servers => ["$mchost:$mcport"] } );
27  &FIG::run("FFB2_get_prot_gs_oligos $newD/ProtsByGenomeSet 12 | sort -T . | FFB2_usable_motifs $newD/PhyloSigs");  $mc or die "Could not connect to memcached at $mchost:$mcport\n";
28    
29    $mc->flush_all();
30    
31    #
32    # Do some work up front to ensure we can load the memcache with all the data we need.
33    #
34    
35    my $ssfam;
36    if (-f $in_ssfam)
37    {
38        $ssfam = $in_ssfam;
39    }
40    else
41    {
42        $ssfam = "$FIG_Config::temp/subsys.based.families.$$";
43        &FIG::run("FFB2_make_subsys_based_families > $ssfam");
44    }
45    
46    print "Loading memcache\n";
47    &FIG::run("FFB2_load_memcache $ssfam $oldD/families.2c $mchost $mcport");
48    print "Done\n";
49    
50    my $parallel = 1;
51    my $child_pid;
52    if ($parallel)
53    {
54        #
55        # Run the FF update in a child process while we manage getting the phylo oligos here.
56        #
57    
58        $child_pid = fork;
59    
60        if ($child_pid == 0)
61        {
62            figfam_processing();
63            exit;
64        }
65    }
66    else
67    {
68        figfam_processing();
69    }
70    
71    #
72    # Run the new parallel get-prots
73    #
74    my $n_get_prots = 3;
75    
76    my @handles;
77    for my $i (0..$n_get_prots - 1)
78    {
79        my $outfile = "$FIG_Config::temp/ffb2_xx.$$.$i";
80    
81        my $h = start(['FFB2_xx', 12,  "$newD/setI", $n_get_prots, $i, $mchost, $mcport],
82                      "<", "/dev/null", ">", $outfile);
83        push(@handles, [$i, $h, $outfile]);
84    }
85    for my $e (@handles)
86    {
87        my($i, $h, $file) = @$e;
88        print "Wait for finish $i $file\n";
89        $h->finish();
90    }
91    
92    my @files = map { $_->[2] } @handles;
93    print STDERR "Merging phylo @files\n";
94    &FIG::run("sort -m @files | FFB2_usable_motifs $newD/PhyloSigs");
95    
96    #&FIG::run("FFB2_get_prots $newD/ProtsByGenomeSet $newD/setI");
97    #&FIG::run("FFB2_get_prot_gs_oligos $newD/ProtsByGenomeSet 12 | sort $sort_args | FFB2_usable_motifs $newD/PhyloSigs");
98    
99    if ($parallel)
100    {
101        my $rc = waitpid($child_pid, 0);
102        if ($? != 0)
103        {
104            die "Error running parallel child: $?\n";
105        }
106    }
107    
108    
109  mkdir("$newD/Merged",0777) || die "could not make $newD/Merged: $!";  mkdir("$newD/Merged",0777) || die "could not make $newD/Merged: $!";
110    
111    my @merge_handles;
112    
113  foreach my $i (7..12)  foreach my $i (7..12)
114  {  {
115      mkdir("$newD/Merged/$i",0777) || die "could not make $newD/Merged/$i: $!";      mkdir("$newD/Merged/$i",0777) || die "could not make $newD/Merged/$i: $!";
116      &FIG::run("FFB2_merge_oligos $newD/Kmers/$i/good.oligos $newD/PhyloSigs/$i/good.oligos > $newD/Merged/$i/merged.oligos");      my $h = start(["FFB2_merge_oligos", "$newD/Kmers/$i/good.oligos", "$newD/PhyloSigs/$i/good.oligos"], "|",
117                      ["FFB2_create_binary_kmers", "-l", $i, "-s", "4,2", "-", "$newD/Merged/$i/table.binary"]);
118    
119        push(@merge_handles, [$h, $i]);
120    
121    #    &FIG::run("FFB2_merge_oligos $newD/Kmers/$i/good.oligos $newD/PhyloSigs/$i/good.oligos > $newD/Merged/$i/merged.oligos");
122  }  }
 &FIG::run("FFB2_load_oligo_index $newD/function.index $newD/FRI.db");  
 &FIG::run("FFB2_load_oligo_index $newD/setI $newD/setI.db");  
123    
124  foreach my $i (7..12)  for my $ent (@merge_handles)
125  {  {
126      &FIG::run("FFB2_create_binary_kmers -s 4,2 $newD/Merged/$i/merged.oligos $newD/Merged/$i/table.binary");      my($h, $k) = @$ent;
127        print "Wait for finish for k=$k\n";
128        my $r = $h->finish();
129        print "done r=$r\n";
130  }  }
131    
132    my $load1 = start(["FFB2_load_oligo_index", "$newD/function.index",  "$newD/FRI.db"]);
133    my $load2 = start(["FFB2_load_oligo_index", "$newD/setI", "$newD/setI.db"]);
134    my $build = start(["build_prok_nonff_fasta", "$newD"],  ">", "$newD/extra_prok_seqs.fasta");
135    
136    
137    #foreach my $i (7..12)
138    #{
139    #    &FIG::run("FFB2_create_binary_kmers -s 4,2 $newD/Merged/$i/merged.oligos $newD/Merged/$i/table.binary");
140    #}
141    
142    system("FFB2_run_tests $newD");
143    system("FFB2_compare_tests $oldD $newD");
144    $build->finish();
145    &FIG::run("formatdb -p T -i $newD/extra_prok_seqs.fasta");
146    
147    $load1->finish();
148    $load2->finish();
149    
150    &FIG::run("FFB2_make_FF_index $newD $newD/fam.func.index $newD/FamFuncBlastD");
151    &FIG::run("FFB2_build_ff_indexes $newD");
152    
153    sub figfam_processing
154    {
155        &FIG::run("FFB2_update_FIGfams -f $ssfam $newD/families.2c $newD/family.functions $oldD");
156        &FIG::run("FFB2_get_oligos $newD/families.2c $newD/family.functions 2> $newD/function.index |" .
157                  "sort $sort_args | FFB2_usable_motifs $newD/Kmers");
158    }
159    
160    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.10

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3