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

View of /FigKernelScripts/install_partition_reps.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Thu Oct 8 18:57:22 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.1: +16 -2 lines
commit change

use strict;

my $usage = "usage: install_partition_reps Dir FigFamsDataDir";

print STDERR "=skipped install_partition_reps. To prevent skipping, take out exit line in install_partition_reps.\n";
exit;

my($reps_dir,$figfams_data);

(
 ($reps_dir     = shift @ARGV) && (-d $reps_dir) &&
 ($figfams_data = shift @ARGV) && (-d $figfams_data)
)
    || die $usage;

use FIG;
use ProtFams;
my $fig = new FIG;
my $protfams = new ProtFams($fig,$figfams_data);

my $rep_idsF = "$figfams_data/partition.representatives";
my $fastaF   = "$figfams_data/partition_reps.fasta";
my $reps_db  = "$figfams_data/partition_reps.db";

&FIG::run("cat $reps_dir/* | sort -u > $rep_idsF");
open(IDS,"<$rep_idsF") || die "could not open $rep_idsF";
open(FASTA,">$fastaF") || die "could not open $fastaF";
my %seen;
my %to_partitions;
my %reps_hash;
use DB_File;

while (defined($_ = <IDS>))
{
    if ($_ =~ /^(\S+)\t(\d+)$/)
    {
	my $peg = $1;
	my $partition = $2;
	push(@{$to_partitions{$peg}},$partition);
	if (! $seen{$peg})
	{
	    $seen{$peg} = 1;
	    my $prot_seq;
	    if ($peg =~ /fig\|/)
	    {
		$prot_seq = $fig->get_translation($peg);
	    }
	    else
	    {
		$prot_seq = $protfams->get_translation($peg);
	    }

	    if ($prot_seq)
	    {
		print FASTA ">$peg\n$prot_seq\n";
	    }
	    else
	    {
		print STDERR "Failed to get translation for $peg\n";
	    }
	}
    }
    else
    {
	print STDERR "Ignored bad input: $_";
    }
}

&FIG::run("$FIG_Config::ext_bin/formatdb -p T -i $fastaF");

my $hash_tie = tie(%reps_hash, 'DB_File', $reps_db, O_RDWR | O_CREAT, 0666, $DB_HASH);
$hash_tie || die qq(Attempt to tie \%reps_hash to "$reps_db" failed: \$\! = "$!");
foreach my $peg (keys(%to_partitions))
{
    my $partitions = join("\t",@{$to_partitions{$peg}});
    $partitions || die "no partitions for $peg";
    $reps_hash{$peg} = $partitions;
}
untie %reps_hash;

    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3