[Bio] / WebApplication / scripts / cache_public_metagenome_metadata.pl Repository:
ViewVC logotype

View of /WebApplication/scripts/cache_public_metagenome_metadata.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Fri Sep 10 10:56:44 2010 UTC (9 years, 6 months ago) by paczian
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, rast_rel_2014_0912, mgrast_dev_03052011, mobedac_release_05302012, mgrast_dev_05262011, mgrast_dev_04082011, rast_rel_2010_0928, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, rast_rel_2014_0729, mgrast_dev_02212011, rast_rel_2010_1206, mgrast_release_3_0, mgrast_dev_03252011, 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, myrast_33, rast_rel_2011_0928, mgrast_dev_04052011, mgrast_dev_02222011, mgrast_dev_10262011, HEAD
initial version
caches metadata from public jobs needed for the metagenome select page

#!/usr/bin/env perl
use strict;
use warnings;

use MGRAST::Metadata;
use FIG_Config;
use DBMaster;

# get the data connections
my $mgrast = DBMaster->new( -database => $FIG_Config::mgrast_jobcache_db || 'JobCacheMGRast',
			    -host     => $FIG_Config::mgrast_jobcache_host,
			    -user     => $FIG_Config::mgrast_jobcache_user,
			    -password => $FIG_Config::mgrast_jobcache_password );

my $metadata = MGRAST::Metadata->new()->{_handle};

# extract the initial data
my $public_projects = $mgrast->Project->get_objects( { public => 1 } );
my $jobs = [];
foreach my $project (@$public_projects) {
  my $pjobs = $mgrast->ProjectJob->get_objects( { project => $project } );
  foreach my $pj (@$pjobs) {
    push(@$jobs, $pj->job);
    $jobs->[scalar(@$jobs) - 1]->{pname} = $project->{name};
    $jobs->[scalar(@$jobs) - 1]->{project} = $project;
  }
}
my $md_list = { 'biome-information_envo_lite' => 4,
		'sample-origin_altitude' => 5,
		'sample-origin_depth' => 6,
		'sample-origin_location' => 7,
		'sample-origin_ph' => 8,
		'sample-origin_country' => 9,
		'sample-origin_temperature' => 10,
		'sequencing_sequencing_method' => 11,
		'PI_lastname' => 12 };
my $data = [];
foreach my $job (@$jobs) {
  $job->{genome_name} =~ s/'//g;
  $job->{pname} =~ s/'//g;
  my $row = [ [ $job->{_id} ], [ $job->{genome_name} ], [ $job->{genome_id} ], [ $job->{pname} ], [ ], [ ], [ ], [ ], [ ], [ ], [ ], [ ], [ ] ];
  my $md = $metadata->MetaDataEntry->get_objects( { job => $job } );
  push(@$md, @{$metadata->ProjectMD->get_objects( { project => $job->{project} } )});
  foreach my $m (@$md) {
    if ($m->{value} ne "") {
      if ($md_list->{$m->{tag}}) {
	if (! defined($row->[$md_list->{$m->{tag}}])) {
	  $row->[$md_list->{$m->{tag}}] = [];
	}
	push(@{$row->[$md_list->{$m->{tag}}]}, $m->{value});
      }
    }
  }
  push(@$data, $row);
}

my $string_data = "";
my $rows = [];
foreach my $row (@$data) {
  push(@$rows, join('||', map { join("\*\*", @$_) } @$row));
}
$string_data = join('##', @$rows);

$self->{data} = $string_data;

if (open(FH, ">".$FIG_Config::temp."/mgs_temp_data")) {
  print FH $string_data;
  close FH;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3