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

Annotation of /WebApplication/scripts/cache_public_metagenome_metadata.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (view) (download) (as text)

1 : paczian 1.1 #!/usr/bin/env perl
2 :     use strict;
3 :     use warnings;
4 :    
5 :     use MGRAST::Metadata;
6 :     use FIG_Config;
7 :     use DBMaster;
8 :    
9 :     # get the data connections
10 :     my $mgrast = DBMaster->new( -database => $FIG_Config::mgrast_jobcache_db || 'JobCacheMGRast',
11 :     -host => $FIG_Config::mgrast_jobcache_host,
12 :     -user => $FIG_Config::mgrast_jobcache_user,
13 :     -password => $FIG_Config::mgrast_jobcache_password );
14 :    
15 :     my $metadata = MGRAST::Metadata->new()->{_handle};
16 :    
17 :     # extract the initial data
18 :     my $public_projects = $mgrast->Project->get_objects( { public => 1 } );
19 :     my $jobs = [];
20 :     foreach my $project (@$public_projects) {
21 :     my $pjobs = $mgrast->ProjectJob->get_objects( { project => $project } );
22 :     foreach my $pj (@$pjobs) {
23 :     push(@$jobs, $pj->job);
24 :     $jobs->[scalar(@$jobs) - 1]->{pname} = $project->{name};
25 :     $jobs->[scalar(@$jobs) - 1]->{project} = $project;
26 :     }
27 :     }
28 :     my $md_list = { 'biome-information_envo_lite' => 4,
29 :     'sample-origin_altitude' => 5,
30 :     'sample-origin_depth' => 6,
31 :     'sample-origin_location' => 7,
32 :     'sample-origin_ph' => 8,
33 :     'sample-origin_country' => 9,
34 :     'sample-origin_temperature' => 10,
35 :     'sequencing_sequencing_method' => 11,
36 :     'PI_lastname' => 12 };
37 :     my $data = [];
38 :     foreach my $job (@$jobs) {
39 :     $job->{genome_name} =~ s/'//g;
40 :     $job->{pname} =~ s/'//g;
41 :     my $row = [ [ $job->{_id} ], [ $job->{genome_name} ], [ $job->{genome_id} ], [ $job->{pname} ], [ ], [ ], [ ], [ ], [ ], [ ], [ ], [ ], [ ] ];
42 :     my $md = $metadata->MetaDataEntry->get_objects( { job => $job } );
43 :     push(@$md, @{$metadata->ProjectMD->get_objects( { project => $job->{project} } )});
44 :     foreach my $m (@$md) {
45 :     if ($m->{value} ne "") {
46 :     if ($md_list->{$m->{tag}}) {
47 :     if (! defined($row->[$md_list->{$m->{tag}}])) {
48 :     $row->[$md_list->{$m->{tag}}] = [];
49 :     }
50 :     push(@{$row->[$md_list->{$m->{tag}}]}, $m->{value});
51 :     }
52 :     }
53 :     }
54 :     push(@$data, $row);
55 :     }
56 :    
57 :     my $string_data = "";
58 :     my $rows = [];
59 :     foreach my $row (@$data) {
60 :     push(@$rows, join('||', map { join("\*\*", @$_) } @$row));
61 :     }
62 :     $string_data = join('##', @$rows);
63 :    
64 :     $self->{data} = $string_data;
65 :    
66 :     if (open(FH, ">".$FIG_Config::temp."/mgs_temp_data")) {
67 :     print FH $string_data;
68 :     close FH;
69 :     }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3