This repository has been archived by the owner on Oct 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabases.pm
96 lines (63 loc) · 2.6 KB
/
Databases.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package PGXDB::Databases;
use PGX::Helpers::UtilityLibs;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
pgxdb_get_database_platforms
pgxdb_get_database_samples
pgxdb_filter_platforms
);
################################################################################
sub pgxdb_get_database_platforms {
use MongoDB;
my $pgxdb = shift;
$pgxdb->{platforms}->{existing} = [];
if ($pgxdb->{parameters}->{sel_platforms} =~ /.../i) { return $pgxdb }
if ($pgxdb->{parameters}->{am_platforms} =~ /n/i) { return $pgxdb }
my $dbconn = MongoDB::MongoClient->new()->get_database('arraymap');
my $distincts = $dbconn->run_command([
"distinct"=> 'biosamples',
"key" => 'external_references.type.id',
"query" => { 'external_references.type.id' => qr/GPL/i },
]);
my $ids = $distincts->{values};
$ids = [ grep{ /GPL/ } @$ids ];
s/^\w+?\://g for @$ids;
$pgxdb->{platforms}->{existing} = $ids;
return $pgxdb;
}
################################################################################
sub pgxdb_get_database_samples {
use MongoDB;
my $pgxdb = shift;
$pgxdb->{samples}->{existing} = [];
if ($pgxdb->{parameters}->{am_samples} =~ /y/i) { return $pgxdb }
my $dbconn = MongoDB::MongoClient->new()->get_database('arraymap');
my $distincts = $dbconn->run_command([
"distinct"=> 'biosamples',
"key" => 'external_references.type.id',
"query" => { 'external_references.type.id' => qr/GSM/i },
]);
my $ids = $distincts->{values};
$ids = [ grep{ /GSM/ } @$ids ];
s/^\w+?\://g for @$ids;
$pgxdb->{samples}->{existing} = $ids;
return $pgxdb;
}
################################################################################
sub pgxdb_filter_platforms {
my $pgxdb = shift;
$pgxdb->{platforms}->{selected} = [];
if ($pgxdb->{parameters}->{sel_platforms} =~ /.../i) {
$pgxdb->{platforms}->{selected} = [ split(',', $pgxdb->{parameters}->{sel_platforms} ) ];
return $pgxdb;
}
foreach my $pfId (@{$pgxdb->{platforms}->{existing}}, @{ $pgxdb->{arrayconfig}->{platforms}->{blessed} }) {
if (! grep{ /^$pfId$/ } (@{ $pgxdb->{platforms}->{selected} }, @{ $pgxdb->{arrayconfig}->{platforms}->{excluded} }) ) {
push(@{ $pgxdb->{platforms}->{selected} }, $pfId) }
}
if ($pgxdb->{parameters}->{randpf} > 0) {
$pgxdb->{platforms}->{selected} = RandArr( $pgxdb->{platforms}->{selected}, $pgxdb->{parameters}->{randpf} ) }
return $pgxdb;
}
1;