annotate downloader_bank_hmdb.pl @ 0:7c9269bded0e draft

Init repository for [downloader_bank_hmdb]
author fgiacomoni
date Tue, 14 Jan 2020 05:21:23 -0500
parents
children be504ccbc41c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
1 #!perl
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
2
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
3 ## script : downloader_bank_hmdb.pl
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
4 #=============================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
5 # Included modules and versions
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
6 #=============================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
7 ## Perl modules
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
8 use strict ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
9 use warnings ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
10 use Carp qw (cluck croak carp) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
11
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
12 use Data::Dumper ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
13 use Getopt::Long ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
14 use File::Basename ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
15 use FindBin ; ## Allows you to locate the directory of original perl script
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
16
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
17 ## Specific Perl Modules (PFEM)
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
18 use lib $FindBin::Bin.'/lib' ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
19 my $binPath = $FindBin::Bin ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
20
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
21 ## Dedicate Perl Modules (Home made...)
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
22 use hmdb_api qw( :ALL ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
23 use utils qw( :ALL ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
24 use conf qw( :ALL ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
25 use csv qw( :ALL ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
26
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
27 ## Initialized values
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
28 my $OptHelp ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
29 my $VERBOSE = 3 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
30 my ($bankName, $format, $outTab, $outJson) = (undef, undef, undef, undef) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
31
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
32 #=============================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
33 # Manage EXCEPTIONS
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
34 #=============================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
35 &GetOptions ( "h" => \$OptHelp, # HELP
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
36 "bank|b:s" => \$bankName, # bank name to get the rigth url
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
37 "format|f:s"=> \$format, # output format
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
38 "outTab:s" => \$outTab, # tabular output
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
39 "outJson:s" => \$outJson, # Json output
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
40 "verbose:i" => \$VERBOSE, # level of scriptt verbose [should be 1 or 3]
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
41
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
42
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
43 ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
44
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
45 ## if you put the option -help or -h function help is started
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
46 if ( defined($OptHelp) ){ &help ; }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
47
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
48 #=============================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
49 # MAIN SCRIPT
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
50 #=============================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
51
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
52
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
53 # get conf informations
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
54 my ( $CONF ) = ( undef ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
55 foreach my $conf ( <$binPath/*.cfg> ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
56 my $oConf = conf::new() ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
57 $CONF = $oConf->as_conf($conf) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
58 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
59
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
60 # MAIN SCRIPT :
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
61
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
62 if ( (defined $bankName) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
63
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
64 my ( $bankUrl, $bankVersion, $bankSuffixe ) = (undef, undef, undef) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
65 my ( $bankOutputTabularFile, $bankOutputJsonFile ) = (undef, undef) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
66
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
67 print "** Get version information from Wishart server databases (Canada)\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
68
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
69 # get information from conf
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
70 if ($CONF->{$bankName.'_URL'}) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
71 $bankUrl = $CONF->{$bankName.'_URL'} ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
72 # get version of the http resource
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
73 my $oUtils = utils->new() ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
74 ($bankVersion) = $oUtils->getHttpFileVersion($bankUrl) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
75
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
76 print "\tThe current version is: $bankVersion\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
77 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
78 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
79 croak "the given bank name ($bankName) doesn't match with any configuration parameters -- database downloading stopped" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
80 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
81
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
82 # manage if needed to download or not the bank (get or not the last version)
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
83 my ($bankFileExist, $bankFilePath, $bankFileDir) = (undef, undef, undef) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
84
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
85 if ($CONF->{$bankName.'_HTTP_FORMAT'}) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
86 $bankSuffixe = $CONF->{$bankName.'_HTTP_FORMAT'} ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
87 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
88 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
89 croak "[ERROR] the given bank suffixe doesn't exist! please check your configuration parameters -- database download stopped" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
90 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
91
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
92 print "** Manage bank environment\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
93 my $bankDir = $binPath.'/'.$CONF->{'LOCALBANK_PATH'} ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
94 if ( !-d $bankDir ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
95 print "\tdir creation of $bankDir\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
96 mkdir $bankDir ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
97 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
98
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
99
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
100 print "** Manage the download of the last version of the bank\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
101
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
102 if ( ( defined $bankUrl ) and ( defined $bankVersion ) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
103 if(-d $binPath.'/'.$CONF->{'LOCALBANK_PATH'}.'/'.$bankName.'_'.$bankVersion) { $bankFileExist = 'TRUE' ; }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
104 else { $bankFileExist = 'FALSE' ; }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
105 # Init the bank file name
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
106 $bankFileDir = $binPath.'/'.$CONF->{'LOCALBANK_PATH'}.'/'.$bankName.'_'.$bankVersion ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
107 $bankFilePath = $bankFileDir.'/'.$bankName.'_'.$bankVersion.'.'.lc($bankSuffixe) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
108 # For final files (tabular/json)
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
109 $bankOutputTabularFile = $binPath.'/'.$CONF->{'LOCALBANK_PATH'}.'/'.$bankName.'_'.$bankVersion.'/'.$bankName.'_'.$bankVersion.'.tabular' ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
110 $bankOutputJsonFile = $binPath.'/'.$CONF->{'LOCALBANK_PATH'}.'/'.$bankName.'_'.$bankVersion.'/'.$bankName.'_'.$bankVersion.'.json' ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
111
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
112 print "\tBuilding bank file dir: $bankFileDir\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
113 print "\tBuilding bank file name: $bankFilePath\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
114
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
115 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
116 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
117 croak "the given bank url ($bankUrl) and the detected version ar undef -- database download stopped" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
118 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
119
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
120 my $bankFile = $bankFileDir.'/'.$CONF->{$bankName.'_FILE_NAME'} ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
121
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
122 # dowload the bank if does not exist !
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
123 if ( $bankFileExist eq 'FALSE' ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
124
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
125 print "\t/!\\ The asked bank does not still exist /!\\\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
126 if (!-d $bankFileDir) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
127 print "\tdir creation of $bankFileDir\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
128 mkdir $bankFileDir ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
129 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
130
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
131 if (-d $bankFileDir) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
132 print "\tDownload of the asked bank ($bankName)...\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
133 print "\tFrom...$bankUrl\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
134 my $oDownloader = utils->new() ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
135 my ($fileZip) = $oDownloader->getHttpFile($bankUrl, $bankFilePath) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
136
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
137 print "\tUnzip the download archive ($bankFilePath) and clean env ...\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
138
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
139 my $oUnzip = utils->new() ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
140 # if archive is a zip
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
141 if ($bankSuffixe eq 'ZIP') {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
142 $oUnzip->unzipFile($bankFilePath, $bankFileDir.'/'.$CONF->{$bankName.'_FILE_NAME'}, $CONF->{$bankName.'_FILE_NAME'}) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
143 $oUnzip->cleanUnzip($bankFilePath, $bankFileDir.'/'.$CONF->{$bankName.'_FILE_NAME'} ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
144 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
145 # elsif archive is a gz
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
146 elsif ($bankSuffixe eq 'GZ') {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
147 $oUnzip->gunzipFile($bankFilePath, $bankFileDir.'/'.$CONF->{$bankName.'_FILE_NAME'}, $CONF->{$bankName.'_FILE_NAME'}) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
148 $oUnzip->cleanUnzip($bankFilePath, $bankFileDir.'/'.$CONF->{$bankName.'_FILE_NAME'} ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
149 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
150 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
151 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
152 croak "the given bank dir doesn't ($bankFileDir) exist or cannot be created - No download started\n" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
153 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
154 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
155 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
156 print "\t/!\\ $bankName Bank is already present on the disk... /!\\\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
157 print "\t/!\\ ...in $bankFile /!\\\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
158 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
159
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
160 ##
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
161 if (-e $bankOutputTabularFile) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
162 # copy the ref file into the user history/session
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
163 my $ocsv = csv->new( ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
164 my $csv = $ocsv->get_csv_object("\t") ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
165 my ($refEntries, $status) = $ocsv->parse_allcsv_object($csv, \$bankOutputTabularFile, 'y') ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
166 $ocsv->write_csv_from_arrays($csv, $outTab, $refEntries) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
167 print "\t/!\\ copy the ref file $bankOutputTabularFile into your session ($outTab)... /!\\\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
168 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
169 ## the final tabular file does not exists - need to be created from xml
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
170 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
171
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
172 ## Build a HASH with all metabolites from downloaded xml
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
173 my ($handler, $metabolites, $nbEntries) = (undef, undef) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
174
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
175 if (-e $bankFile) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
176 my $oHandler = hmdb_api->new ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
177
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
178 # in case the download file is in XML or Metabocard or SDF...
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
179 if ($CONF->{$bankName.'_DB_FORMAT'} eq 'XML') {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
180 ($metabolites, $nbEntries) = $oHandler->getMetaboliteFeatures($bankFile) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
181 print "\tExtraction of $nbEntries metabolites from $bankName XML file\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
182 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
183 elsif ( ($CONF->{$bankName.'_DB_FORMAT'} eq 'CARD') ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
184 ($handler, $nbEntries) = $oHandler->cowmetdb_handle($bankFile) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
185 ($metabolites) = $oHandler->cowmetdb_hash($handler) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
186 print "\tExtraction of $$nbEntries metabolites from $bankName CARD file\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
187 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
188 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
189 #TODO...
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
190 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
191 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
192 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
193 print "\t/!\\ The bank does not exist: $bankFile\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
194 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
195
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
196 ## Write outputs !
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
197 print "** Write outputs from HMDB in BiH and Json formats\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
198
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
199 if ( (defined $metabolites) and (defined $format) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
200
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
201 ## Generation of M+H and M-H masses
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
202 my $ometmz = hmdb_api->new ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
203 my $completedMetabolites = undef ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
204 $completedMetabolites = $ometmz->setMetaboliteAcurrateMzToModesMz($CONF->{$bankName.'_DB_FORMAT'}, $metabolites, $CONF->{'PROTON_MASS'}, $CONF->{'ELECTRON_MASS'}, 1) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
205
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
206 # print Dumper $completedMetabolites ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
207
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
208 ## tabular output
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
209 if ( ( $format eq 'tabular') and (defined $outTab) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
210 print "\tThe tabular output ($outTab) is created...\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
211 # print Dumper $metabolites ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
212 # sort metabolites
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
213 my $omet = hmdb_api->new ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
214 my $sortedMetabolites = undef ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
215
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
216 if ($CONF->{$bankName.'_DB_FORMAT'} eq 'XML') {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
217 $sortedMetabolites = $omet->buildMetabolitesArray($completedMetabolites) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
218 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
219 elsif ( ($CONF->{$bankName.'_DB_FORMAT'} eq 'CARD') ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
220 $sortedMetabolites= $omet->cowmetdb_hash_to_inhouse_format($completedMetabolites) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
221 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
222
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
223 # print Dumper $sortedMetabolites ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
224 my $ocsv = csv->new( ) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
225 my $csv = $ocsv->get_csv_object("\t") ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
226 # create the ref file for ./bank repo
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
227 $ocsv->write_csv_from_arrays($csv, $bankOutputTabularFile, $sortedMetabolites) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
228 # generate also a copy for user history
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
229 $ocsv->write_csv_from_arrays($csv, $outTab, $sortedMetabolites) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
230
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
231 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
232 elsif ( (defined $format) and (defined $outJson) ) {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
233 #TODO...
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
234 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
235 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
236 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
237 croak "No metabolites are extracted from the $bankName bank file\n" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
238 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
239 ## Clean local envt
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
240 unlink $bankFile if (-e $bankFile) ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
241 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
242 } ## END IF defined $bankName
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
243 else {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
244 &help ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
245 croak "No bank name and format are defined - Please set one" ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
246 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
247
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
248 print "\n*************!!End of the job ;-). Thank you for using W4M!!****************\n" if $VERBOSE > 1 ;
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
249 ### END of main script
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
250
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
251
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
252
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
253
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
254
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
255 #====================================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
256 # Help subroutine called with -h option
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
257 # number of arguments : 0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
258 # Argument(s) :
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
259 # Return : 1
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
260 #====================================================================================
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
261 sub help {
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
262 print STDERR "
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
263 downloader_bank_hmdb.pl
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
264
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
265 # downloader_bank_hmdb is a script to export specific tissue/matrix bank from HMDB source.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
266 # Input : N/A
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
267 # Author : Franck Giacomoni
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
268 # Email : fgiacomoni\@inra.fr
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
269 # Version : 1.0
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
270 # Created : 21/11/2018
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
271 USAGE :
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
272 downloader_bank_hmdb.pl -bank [SERUM|URINE|CSF|...] -format [tabular|json] -outTab [tabular file name]
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
273
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
274 ";
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
275 exit(1);
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
276 }
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
277
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
278 ## END of script - F Giacomoni
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
279
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
280 __END__
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
281
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
282 =head1 NAME
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
283
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
284 downloader_bank_hmdb.pl is a script to export specific tissue/matrix bank from HMDB source.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
285
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
286 =head1 USAGE
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
287
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
288 downloader_bank_hmdb.pl -bank [serum|urine|...] -format [tabular|json]
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
289 or downloader_bank_hmdb.pl -help
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
290
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
291 =head1 SYNOPSIS
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
292
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
293 This script export specific tissue/matrix bank from HMDB source.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
294
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
295 =head1 DESCRIPTION
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
296
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
297 This main program is a galaxy tool (W4M) allowing the export specific tissue/matrix bank from HMDB source in a tabular format.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
298
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
299 =over 4
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
300
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
301 =item B<function01>
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
302
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
303 =item B<function02>
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
304
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
305 =back
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
306
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
307 =head1 AUTHOR
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
308
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
309 Franck Giacomoni E<lt>franck.giacomoni@inra.frE<gt>
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
310
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
311 =head1 LICENSE
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
312
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
313 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
314
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
315 =head1 VERSION
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
316
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
317 version 1 : 21 / 11 / 2018
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
318
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
319 version 2 : ??
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
320
7c9269bded0e Init repository for [downloader_bank_hmdb]
fgiacomoni
parents:
diff changeset
321 =cut