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

View of /FigKernelScripts/propagate_subsys_changes_to_figfams.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (download) (as text) (annotate)
Thu Oct 8 18:52:54 2009 UTC (10 years, 1 month ago) by arodri7
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, myrast_rel40, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2010_0526, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, rast_rel_2010_0118, rast_rel_2011_0119, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, rast_rel_2010_0827, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
Changes since 1.11: +56 -12 lines
commit changes

use FIG;
use FigFams;


my $usage = "usage: propagate_subsys_changes_to_figfams NewFigFamsDir";
my $date = `date`;
chomp $date;

while ( $ARGV[0] =~ /^-/ )
{
    $_ = shift @ARGV;
    if    ($_ =~ s/^-f//)       { $ss_file       = ($_ || shift @ARGV) }
    elsif ($_ =~ s/^-log//)     { $log_file      = ($_ || shift @ARGV) }
    elsif ($_ =~ s/^-skipto//)  { $skip_to       = ($_ || shift @ARGV) }
    elsif ($_ =~ s/^-tmp//)     { $tmp_file      = ($_ || shift @ARGV) }
    else                  { print STDERR  "Bad flag: '$_'\n$usage"; exit 1 }
}

if (! $skip_to)
{
    print STDERR "===============FIGfam release update start $date ===================\n";
}
else{
    print STDERR "===============FIGfam release restart at $skip_to $date ============\n";
}

# get the figfam locations (new and old)
my $oldFF;
if (scalar @ARGV > 1){
    $oldFF = &FIG::get_figfams_data(pop @ARGV);
}
else{
    $oldFF = &FIG::get_figfams_data();
}
(($newFF = shift @ARGV)  && ($oldFF ne $newFF))
    || die $usage;


# step 1:
if (! -d $newFF) {
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 1: START copy directory $date\n";
    print STDERR "=command: &copy_figfam_dir($newFF,$oldFF)\n";
#    &FIG::run("cp -L -r $oldFF $newFF");
    &copy_figfam_dir($newFF, $oldFF);
}

# step 2:
if ( (!$skip_to) || ($skip_to eq "update_FIGfams") ){ 
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 2: START update_FIGfams $date\n";

    if (-f $ss_file){
	print STDERR "=command: update_FIGfams -f $ss_file $newFF/families.2c $newFF/family.functions $oldFF\n";
	&FIG::run("update_FIGfams -f $ss_file $newFF/families.2c $newFF/family.functions $oldFF");
    }
    else {
	print STDERR "=command: update_FIGfams $newFF/families.2c $newFF/family.functions $oldFF\n";
	&FIG::run("update_FIGfams $newFF/families.2c $newFF/family.functions $oldFF");
    }
    undef $skip_to;
}

# step 3:
if ( (!$skip_to) || ($skip_to eq "update_version") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 3: START update_versions $date\n";
    &update_version($newFF);
    undef $skip_to;
}

# step 4:
if ( (!$skip_to) || ($skip_to eq "build_new_figfam") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 4: START build new figfam release $date\n";
    print STDERR "=command: build_new_figfam_release $oldFF $newFF > $FIG_Config::temp/FIGfam.ids.$$\n";
    &FIG::run("build_new_figfam_release $oldFF $newFF > $FIG_Config::temp/FIGfam.ids.$$");
    undef $skip_to;
}

# step 5:
if ( (!$skip_to) || ($skip_to eq "initialize_figfams") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 5: START initialize figfams $date\n";
    my $tempoFile;
    if ($skip_to eq "initialize_figfams") {
	$tempoFile = $tmp_file;
    }
    else{
	$tempoFile = "$FIG_Config::temp/FIGfam.ids.$$";
    }
    print STDERR "=command: initialize_figfams $newFF < $tempoFile\n";
    &FIG::run("initialize_figfams $newFF < $tempoFile");
    unlink("$tempoFile");
    undef $skip_to;
}

# step 6: if you input a log_file, it will look where it left off in the process and continue from there
my ($tmpOutput);
if ( (!$skip_to) || ($skip_to eq "generate_partitions") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 6: START generate partitions $date\n";
    if ( $skip_to ne "generate_partitions" ){  # start the generate partitions process
	print STDERR "=command: generate_partitionsP $newFF $FIG_Config::temp/TmpOut.$$ > $FIG_Config::temp/TmpOut.$$/partitions.input.$$\n";
	&FIG::run("mkdir $FIG_Config::temp/TmpOut.$$");
	&FIG::run("generate_partitionsP $newFF $FIG_Config::temp/TmpOut.$$ > $FIG_Config::temp/TmpOut.$$/partitions.input.$$");
    }
    elsif ($skip_to eq "generate_partitions") {       # resume the generate partitions process from where it left off (need a log file for this)
	my $tmpDir = $tmp_file;
	($tmpOutput) = glob ("$tmpDir/partitions.input.*");
	print STDERR "=command: generate_partitionsP $newFF $tmpDir > $tmpOutput\n";
	&FIG::run("generate_partitionsP $newFF $tmpDir > $tmpOutput");
    }
#    undef $skip_to;
}

# step 7:
if ( (!$skip_to) || ($skip_to eq "install_partitions") || ($skip_to eq "generate_partitions")){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 7: START install partitions $date\n";
    if (-d "$newFF/Partitions"){
	&FIG::run("rm -rf $newFF/Partitions $newFF/*partition*");
    }
    if ( ($skip_to eq "install_partitions") ) {
	print STDERR "=command: install_partitions $newFF < $tmp_file\n";
	&FIG::run("install_partitions $newFF < $tmp_file");
    }
    elsif ($skip_to eq "generate_partitions") {
	print STDERR "=command: install_partitions $newFF < $tmpOutput\n";
	&FIG::run("install_partitions $newFF < $tmpOutput");
    }
    else{
	print STDERR "=command: install_partitions $newFF < $FIG_Config::temp/TmpOut.$$/partitions.input.$$\n";
	&FIG::run("install_partitions $newFF < $FIG_Config::temp/TmpOut.$$/partitions.input.$$");
    }
    undef $skip_to;
}

# step 8:
if ( (!$skip_to) || ($skip_to eq "make_partition_reps") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 8: START make partitions reps $date\n";
    if ($skip_to eq "make_partition_reps"){
	print STDERR "=command: make_partition_repsP $newFF $tmp_file\n";
	&FIG::run("make_partition_repsP $newFF $tmp_file");	
    }
    else{
	print STDERR "=command: make_partition_repsP $newFF $FIG_Config::temp/TmpOut2.$$\n";
	&FIG::run("mkdir $FIG_Config::temp/TmpOut2.$$");
	&FIG::run("make_partition_repsP $newFF $FIG_Config::temp/TmpOut2.$$");
    }
    #undef $skip_to;
}

# step 9:
if ( (!$skip_to) || ($skip_to eq "install_partition_reps") || ($skip_to eq "make_partition_reps") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 9: START install partitions reps $date\n";
    if ( ($skip_to eq "install_partition_reps") || ($skip_to eq "make_partition_reps") ){
	print STDERR "=command: install_partition_reps $tmp_file $newFF\n";
	&FIG::run("install_partition_reps $tmp_file $newFF");
    }
    else{
	print STDERR "=command: install_partition_reps $FIG_Config::temp/TmpOut2.$$ $newFF\n";
	&FIG::run("install_partition_reps $FIG_Config::temp/TmpOut2.$$ $newFF");
    }
    undef $skip_to;
}

# step 10:
if ( (!$skip_to) || ($skip_to eq "make_partition_index") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 10: START make partitions index $date\n";
    print STDERR "=command: build_partition_index $newFF\n";
    &FIG::run("build_partition_index $newFF");
    undef $skip_to;
}

# step 11:
if ( (!$skip_to) || ($skip_to eq "pdb_update") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 11: START update PDB $date\n";
    &update_PDB($newFF);
    undef $skip_to;
}

# step 12:
if ( (!$skip_to) || ($skip_to eq "make_trees") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 12: START make figfam trees $date\n";
    if ($tmp_file)
    {
	print STDERR "=command: make_figfam_tree $newFF $tmp_file\n";
	#&FIG::run("make_figfam_tree $newFF $tmp_file");
    }
    else
    {
	print STDERR "=command: make_figfam_tree $newFF\n";
	#&FIG::run("make_figfam_tree $newFF");
    }
    undef $skip_to;
}

# step 13:
if ( (!$skip_to) || ($skip_to eq "quality_control") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 13: START quality control $date\n";
    print STDERR "=command: figfam_quality_control -f $newFF\n";
    FIG::run("figfam_quality_control -f $newFF");
    undef $skip_to;
}

# step 14:
if ( (!$skip_to) || ($skip_to eq "compare_release") ){
    $date = `date`;
    chomp $date;
    print STDERR "===============STEP 14: START compare figfam release $date\n";
    print STDERR "=command: compare_figfam_release_results -o $oldFF -n $newFF -print > $newFF/quality_control/comparison.log\n";
    &FIG::run("compare_figfam_release_results -o $oldFF -n $newFF -print > $newFF/quality_control/comparison.log");
    undef $skip_to;
}

$date = `date`;
chomp $date;
print STDERR "===============FIGfam release update complete $date ===================\n";


sub update_PDB {
    my ($newFF) = @_;

    # get the pdb file
    #&FIG::run("ncftpget ftp://ftp.ncbi.nlm.nih.gov/blast/db/FASTA/pdbaa.gz .");
    &FIG::run("gunzip pdbaa.gz");
    print STDERR "=command: connect_PDB_to_FIGfams $newFF $FIG_Config::temp/TmpOut.$$/pdb_connection.$$ pdbaa > $newFF/PDB.connections\n";
    &FIG::run("connect_PDB_to_FIGfams $newFF $FIG_Config::temp/TmpOut.$$/pdb_connection.$$ pdbaa > $newFF/PDB.connections");
    my $figfams_obj = new FigFams(new FIG, $newFF);
    &FigFams::verify_PDB_connections($newFF);
}

sub update_version {
    my ($newFF) = @_;

    # get the old release name and create the new one
    open (FH, "$newFF/release_history/VERSION");
    my $old_name;
    while (my $line = <FH>){
	chomp ($line);
	if ($line =~ /^version/){
	    ($old_name) = ($line) =~ /version\t(.*)/;
	    last;
	}
    }
    close FH;

    my ($key, $value) = split (/\s+/, $old_name);
    my $old_rel_dir = join ("", ($key, $value));
    my $new_name = join (" ", ($key, $value+1));

    # move the old files to the old release directory
    &FIG::run("mkdir $newFF/release_history/old_releases/$old_rel_dir");
    my @files = glob("$newFF/release_history/*");
    foreach my $file (@files){
	if (-f $file){
	    &FIG::run("mv $file $newFF/release_history/old_releases/$old_rel_dir/.");
	}
    }

    &FIG::run("cp $oldFF/family.functions $newFF/release_history/old_releases/$old_rel_dir/.") if (-f "$oldFF/family.functions");
    &FIG::run("cp $oldFF/families.2c $newFF/release_history/old_releases/$old_rel_dir/.") if (-f "$oldFF/families.2c");

    # make the new VERSION file
    open (FW, ">$newFF/release_history/VERSION");
    print FW "version\t$new_name\n";
    print FW "date\t" . &prettydate() . "\n";
    close FW;
}


# usage: $string = prettydate( [$time_t] );
# omit parameter for current time/date
sub prettydate {
    @_ = localtime(shift || time);
    return(sprintf("%02d:%02d %02d/%02d/%04d", @_[2,1], $_[4]+1, $_[3], $_[5]+1900));
} 


sub copy_figfam_dir {
    my ($newFF, $oldFF) = @_;
    
    &FIG::run("mkdir $newFF");
    my @files = glob ("$oldFF/*");

    my $not_wanted_files = {"partition" => 1, "pdbaa" => 1, "PDB" => 1, "repdb" => 1, "Partitions" => 1, ".db" => 1, "md5" => 1, "relevant" => 1,
			    "fc.scores" => 1, "family.map" => 1};

    foreach my $file (@files){
	my @array = split (/\//, $file);
	my $filename = pop(@array);
	my $skip_flag = 0;
	foreach my $not_wanted (keys %$not_wanted_files){
	    $skip_flag = 1 if ($filename =~ /$not_wanted/);
	    last if ($skip_flag);
	}
	next if ($skip_flag);

	# copy file if file is wanted
	print STDERR "...copying $file to $newFF\n";
	&FIG::run("cp -L -r $file $newFF");

    }
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3