[Bio] / FigMetagenomeTools / parse_phage.pl Repository:
ViewVC logotype

View of /FigMetagenomeTools/parse_phage.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (download) (as text) (annotate) (vendor branch)
Mon Feb 19 17:15:26 2007 UTC (12 years, 9 months ago) by olson
Branch: x, MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, mgrast_dev_05262011, mgrast_dev_04082011, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, mgrast_rel_2008_0806, mgrast_dev_10262011, mgrast_dev_02212011, mgrast_rel_2008_0923, mgrast_release_3_0, mgrast_dev_03252011, mgrast_rel_2008_0924, mgrast_rel_2008_1110_v2, mgrast_rel_2008_0625, 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, mgrast_rel_2008_0919, mgrast_rel_2008_1110, myrast_33, mgrast_rel_2008_0917, mgrast_dev_04052011, mgrast_dev_02222011, y, HEAD
Changes since 1.1: +0 -0 lines
Initial import

#!/usr/bin/perl -w

use strict;
use DBI;
use Bio::SearchIO;

my $dbh = DBI->connect('DBI:mysql:phage:n0000', 'rob', 'forestry') or die "Can't connect to database\n";

my ($indir, $outdir)=@ARGV;
unless ($indir && $outdir) {die "$0 <input directory of blasts> <output directory>"}

die "$outdir is not a directory" unless (-d $outdir);
die "$indir is not a directory" unless (-d $indir);
$indir =~ s/\/$//;
$outdir =~ s/\/$//;


my $outfile=$indir; $outfile =~ s/^.*\///;

my %details;
open(OUT, ">$outdir/$outfile") || die "can't opne $outdir/$outfile";
opendir(DIR, $indir) || die "Can't open $indir";
foreach my $file (grep {$_ !~ /^\./} readdir(DIR))
{
 my $sio=Bio::SearchIO->new(-file=>"$indir/$file", -format=>"blast");
 while (my $res=$sio->next_result)
 { 
  my $id = $res->query_name();
  while (my $hit=$res->next_hit)
  {
   my $hitname=$hit->name;
   my ($protein, $org);
   if ($hitname =~ /\_/) {($protein, $org)=split /\_/, $hitname}
   elsif ($hitname =~ /^\d+$/) {$org=$hitname}
   else {print STDERR "NOT SURE WHAT ORGANISM TO PARSE FROM $hitname\n"; next}
   unless ($details{$org})
   {
    my $exc=$dbh->prepare("select accession, locus, family, organism, count, genbankname from phage where count=$org") || die $dbh->errstr;
    $exc->execute|| die $dbh->errstr;
    my @ret=$exc->fetchrow_array;
    splice(@ret, 2, 0, "", "phage");
    $details{$org}=\@ret;
   }
   print OUT join("\t", $id, @{$details{$org}}, $hit->raw_score, $hit->significance), "\n";
  }
 }
} 


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3