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

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3