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

View of /FigMetagenomeTools/metagenome_sims.pl

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.2 - (download) (as text) (annotate)
Fri Jul 24 01:59:06 2009 UTC (10 years, 7 months ago) by redwards
Branch: 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_dev_10262011, mgrast_dev_02212011, mgrast_release_3_0, mgrast_dev_03252011, 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, myrast_33, mgrast_dev_04052011, mgrast_dev_02222011, HEAD
Changes since 1.1: +1 -1 lines
changing output



=head1 metagenome_sims.pl

This program accesses the sims database and gets the sims out for any given metagenome job.

It will print out the database name, the taxonomy of the hits, and the number of hits. You should probably limit the output to a single type of search:


metagenome_sims -d greengenes:gg_taxonomy -j 1593

You can list all available databases using the -l flag:

metagenome_sims -l


Rob Edwards, November, 2008


use strict;
use DBMaster;
use MGRAST::MetagenomeAnalysis;
use MGRAST::MGRAST qw/dataset_is_phylo/;
use FortyEightMeta::SimDB;
use Getopt::Std;

# These are some pieces that I stole from other code.

# check for job directory
unless(defined($FIG_Config::mgrast_jobs)) {
  die "No job directory found in FIG_Config.pm.";

# check for web application db settings in FIG_Config
unless(defined($FIG_Config::webapplication_db) and
       defined($FIG_Config::webapplication_backend)) {
  die "No webapplication db settings found in FIG_Config.pm.";

# init PPO 
my $backend  = 'MySQL';
my $database = $FIG_Config::mgrast_jobcache_db || 'jobcache.db';
my $dbmaster = DBMaster->new(-database => $database,
                             -backend  => $backend,
                             -host     => $FIG_Config::mgrast_jobcache_host,
                             -user     => $FIG_Config::mgrast_jobcache_user,
                             -password => $FIG_Config::mgrast_jobcache_password

# initialize the sims database connection
my $db = FortyEightMeta::SimDB->new();
my @dbs = $db->databases();
my @analyses = map { $db->get_analyses($_->{name}, $_->{version}) } @dbs;

# get some options from the user
my %opts;
getopts('ld:j:', \%opts);
unless ($opts{l} || $opts{j}) {
	die "$0\n-j job id number\n-d restrict to a single database\n-l list all databases (and exit)";

if ($opts{l}) {
	print "Available databases:\n";
	foreach my $anal (@analyses) {
		print $anal->{'db_name'}, ":", $anal->{name}, "\n";

# convert the id to a job
my $job;
eval { $job = $dbmaster->Job->init({ id => $opts{j}}) };
if ($@) {die "Error: $@"}
unless (defined $job) {die "Job not defined"}

# now get the analysis that we will use to retrieve the data
my $mgdb = MGRAST::MetagenomeAnalysis->new($job);

#analyses is all the available similarities etc
foreach my $anal (@analyses) {
	# don't do if we want to limit to one database
	next if ($opts{d} && $opts{d} ne $anal->{'db_name'}.":".$anal->{'name'} );

	# get the counts from this analysis and database
	my $tax=$mgdb->get_taxa_counts( $anal->{'db_name'}.":".$anal->{'name'} ); 

	foreach my $arr (@$tax) {
	# convert from the taxonomy key to the taxonomy string
		my $t = join("; ", map {$mgdb->key2taxa($_)} @{$mgdb->split_taxstr($arr->[0])});
	# print out the results
		print join("\t", $t, $arr->[1]), "\n";

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3