--- pipe_db.pm.ori 2011-02-22 18:08:58.000000000 +0100 +++ pipe_db.pm 2011-02-22 14:48:03.000000000 +0100 @@ -90,29 +90,29 @@ my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database #the location statistics my $st="INSERT INTO pssr_location_view SELECT CASE ((ssr_endorf_end)*2+(ssr_begin>orf_begin && ssr_endorf_end)*2+(ssr_begin>orf_begin && ssr_endfetchrow_array){ @@ -196,11 +196,11 @@ close_st($sth); $st="UPDATE unigene_structure_annotation_view SET max_est=$max,avg_est=$avg"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -213,11 +213,11 @@ #now the annotated unigenes my $st="SELECT COUNT(*) FROM sequence WHERE annotation IS NOT NULL AND (object_type='contig' OR object_type='singleton')"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my @record=$sth->fetchrow_array; @@ -225,22 +225,22 @@ close_st($sth); $st="UPDATE unigene_structure_annotation_view SET n_uni_with_annot=$n_annot"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); #now the full len my $st="SELECT COUNT(*) FROM sequence WHERE full_length IS NOT NULL AND (object_type='contig' OR object_type='singleton')"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); @record=$sth->fetchrow_array; @@ -248,11 +248,11 @@ close_st($sth); $st="UPDATE unigene_structure_annotation_view SET n_uni_with_full_len=$n_annot"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -263,14 +263,14 @@ my $dbh=shift; my $values=shift; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); my $i=1; foreach my $value (@$values){ $sth->bind_param($i,$value); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); $i++; @@ -282,7 +282,7 @@ my $dbh=shift; my $intervals=shift; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); my $bottom; @@ -293,7 +293,7 @@ $sth->bind_param(1,$bottom); $sth->bind_param(2,$top); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my @record=$sth->fetchrow_array; @@ -329,16 +329,16 @@ my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database my $st="INSERT psnp_accessions_view (accession) SELECT DISTINCT accession FROM putative_snp_seq"; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -354,26 +354,26 @@ my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database my $st="CREATE TEMPORARY TABLE psnp_mutations_temp (nucleotides CHAR(10),is_snp BOOL,INDEX(nucleotides,is_snp)) SELECT GROUP_CONCAT(DISTINCT(putative_snp_seq.nucleotide) ORDER BY putative_snp_seq.nucleotide) AS nucleotides,putative_snp.is_snp FROM putative_snp_seq,putative_snp WHERE putative_snp_seq.psnp_id=putative_snp.psnp_id AND putative_snp_seq.nucleotide!='*' AND putative_snp.is_indel=0 GROUP BY putative_snp_seq.psnp_id"; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="INSERT INTO psnp_mutations_view (mutations,is_snp,count) SELECT nucleotides,is_snp,COUNT(*) AS count FROM psnp_mutations_temp WHERE LENGTH(nucleotides)=3 GROUP BY nucleotides,is_snp"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -389,16 +389,16 @@ my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database my $st="INSERT reciprocal_species_view (species,type) SELECT species,type FROM reciprocal_similar_sequences GROUP BY species"; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -416,46 +416,46 @@ my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database my $st="INSERT INTO go_uni_aspect_view (db,aspect,num_unigenes,word) SELECT go.db,go.aspect,count(DISTINCT go.seq_id) AS num_unigenes, CONCAT(go.aspect,go.db) AS word FROM clone,go,est WHERE est.clone=clone.name AND go.seq_id=est.unigene AND go.is_slim=1 GROUP BY word"; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="INSERT INTO go_uni_aspect_library_view (db,aspect,library,num_unigenes,word) SELECT go.db,go.aspect,clone.library,count(DISTINCT go.seq_id) AS num_unigenes, CONCAT(go.aspect,go.db,clone.library) AS word FROM clone,go,est WHERE est.clone=clone.name AND go.seq_id=est.unigene AND go.is_slim=1 GROUP BY word"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="INSERT INTO go_term_aspect_view (db,aspect,go_id,definition,num_go,word) SELECT db,go.aspect,go.go_id,definition,count(DISTINCT go.seq_id) AS num_go, CONCAT(go.go_id,go.aspect,db) AS word FROM go,go_def WHERE is_slim=1 AND go_def.go_id=go.go_id GROUP BY word"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="INSERT INTO go_term_aspect_library_view (db,aspect,go_id,definition,library,num_go,word) SELECT db,go.aspect,go.go_id,definition,clone.library,count(DISTINCT go.seq_id) AS num_go, CONCAT(go.go_id,go.aspect,db,clone.library) AS word FROM go,go_def,est,clone WHERE is_slim=1 AND go_def.go_id=go.go_id AND go.seq_id=est.unigene AND est.clone=clone.name GROUP BY word"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -473,27 +473,27 @@ my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database my $st="CREATE TEMPORARY TABLE super_count (INDEX(type)) SELECT superunigene,count(*)>1 AS type FROM superunigene GROUP BY superunigene"; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="INSERT INTO superunigene_view (type,num_superunigenes) SELECT type,count(*) AS num_superunigenes FROM super_count GROUP BY type"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -510,17 +510,17 @@ my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database my $st="INSERT INTO unigene_view (type,num_unigenes) SELECT object_type,count(*) AS num_unigenes FROM sequence WHERE object_type='contig' OR object_type='singleton' GROUP BY object_type"; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); @@ -539,7 +539,7 @@ clean_tables($config,@table) or return 0; my $db=read_config($config,'db_path',''); #database in the form dbi:$dbi_driver:$db_name:$host my $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database @@ -547,11 +547,11 @@ #clones per library my $st="SELECT clone.library,COUNT(distinct clone.name) AS num_clones FROM clone GROUP BY clone.library"; my $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %clones; @@ -563,11 +563,11 @@ #raw_est per library $st="SELECT clone.library,COUNT(*) AS num_raw_est FROM est,clone WHERE est.clone=clone.name AND raw_seq IS NOT NULL GROUP BY clone.library"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %raw_est; @@ -579,11 +579,11 @@ #clean_est per library $st='SELECT clone.library,COUNT(*) AS num_clean_est,AVG(sequence.length) AS mean_length,STD(sequence.length) AS std_dev FROM est,sequence,clone WHERE est.processed_seq=sequence.name AND est.clone=clone.name GROUP BY clone.library;'; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %clean_est; @@ -599,11 +599,11 @@ #singletons per library $st="SELECT clone.library,COUNT(distinct sequence.name) AS num_singletons FROM clone,sequence,est WHERE sequence.name=est.unigene AND est.clone=clone.name AND sequence.object_type='singleton' GROUP BY clone.library"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %singletons; @@ -615,11 +615,11 @@ #contigs per library $st="SELECT clone.library,COUNT(distinct sequence.name) AS num_contigs FROM clone,sequence,est WHERE sequence.name=est.unigene AND est.clone=clone.name AND sequence.object_type='contig' GROUP BY clone.library"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %contigs; @@ -631,11 +631,11 @@ #unigenes per library $st="SELECT clone.library,COUNT(distinct unigene) AS num_unigenes FROM est,clone WHERE est.clone=clone.name GROUP BY clone.library"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %unigenes; @@ -647,11 +647,11 @@ #full length per library $st="SELECT clone.library,COUNT(distinct sequence.name) AS num_full_len FROM clone,sequence,est WHERE sequence.name=est.unigene AND est.clone=clone.name AND sequence.full_length IS NOT NULL GROUP BY clone.library"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %full_len; @@ -663,21 +663,21 @@ #spec unigenes length per library $st="CREATE TEMPORARY TABLE uni_library_count (PRIMARY KEY(name), INDEX (num_lib))SELECT sequence.name, COUNT(DISTINCT clone.library) AS num_lib, clone.library AS lib_concat FROM sequence,est,clone WHERE sequence.name=est.unigene AND est.clone=clone.name GROUP BY sequence.name"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="SELECT lib_concat as library,COUNT(*) AS num_unigenes_ex FROM uni_library_count WHERE num_lib=1 GROUP BY lib_concat"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %spec_unigenes; @@ -689,21 +689,21 @@ #spec contigs per library $st="CREATE TEMPORARY TABLE contig_library_count (PRIMARY KEY(name), INDEX (num_lib))SELECT sequence.name, COUNT(DISTINCT clone.library) AS num_lib, clone.library AS lib_concat FROM sequence,est,clone WHERE sequence.name=est.unigene AND est.clone=clone.name AND sequence.object_type='contig' GROUP BY sequence.name"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="SELECT lib_concat as library,COUNT(*) AS num_contigs_ex FROM contig_library_count WHERE num_lib=1 GROUP BY lib_concat"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %spec_contigs; @@ -715,21 +715,21 @@ #spec singletons per library $st="CREATE TEMPORARY TABLE singleton_library_count (PRIMARY KEY(name), INDEX (num_lib))SELECT sequence.name, COUNT(DISTINCT clone.library) AS num_lib, clone.library AS lib_concat FROM sequence,est,clone WHERE sequence.name=est.unigene AND est.clone=clone.name AND sequence.object_type='singleton' GROUP BY sequence.name"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); close_st($sth); $st="SELECT lib_concat as library,COUNT(*) AS num_singletons_ex FROM singleton_library_count WHERE num_lib=1 GROUP BY lib_concat"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); my %spec_singletons; @@ -742,7 +742,7 @@ #now we have all the data and we should store it in the view $st="INSERT INTO library_view (library, num_clones, num_raw_est, num_clean_est, num_singletons, num_contigs, num_unigenes, num_full_len, num_spec_singletons, num_spec_contigs, num_spec_unigenes,avg_est_len,std_est_len) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)"; $sth=prepare_st($dbh,$st) or ( - print localtime().": There was a problem preparing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem preparing the statement $st" and return 0 ); foreach my $lib (keys(%libraries)){ @@ -760,7 +760,7 @@ $sth->bind_param(12,$avg_est_len{$lib}); $sth->bind_param(13,$std_est_len{$lib}); execute_st($sth) or ( - print localtime().": There was a problem executing the statement $st: $DBI::errstr\n" and + print localtime().": There was a problem executing the statement $st" and return 0 ); } @@ -776,12 +776,12 @@ my $config=shift; my $dir = $$config{'chromat_dir'}; opendir DIR,$dir or ( - print localtime().": It was not possible to open the chromat directory $dir: $!\n" and + print localtime().": It was not possible to open the chromat directory: $dir\n" and return 0 ); my @libraries = grep {/^[^\.]/} readdir(DIR); if (!$libraries[0]){ - print localtime().": No libraries found in the libraries directory $dir: $!\n"; + print localtime().": No libraries found in the libraries directory: $dir\n"; return 0; } close DIR; @@ -791,18 +791,18 @@ my $db=read_config($config,'db_path',''); my $dbh=open_db($db); unless ($dbh) { - print localtime().": Database $dbh is not reachable: $DBI::errstr\n"; + print localtime().": Database $dbh is not reachable\n"; return 0; } my $sth=prepare_st($dbh,$st) or ( - print localtime().": Unable to prepare statement: $st: $DBI::errstr\n" and + print localtime().": Unable to prepare statement: $st\n" and return 0 ); foreach my $lib (@libraries){ $sth->bind_param(1,$lib); $sth->execute() or ( print localtime().": There was a problem executing the statement:\n" and - print localtime().": $st: : $DBI::errstr\n" and + print localtime().": $st:\n" and print localtime().": with the library $lib:\n" and return 0 ); @@ -818,7 +818,7 @@ my $db=read_config($config,'db_path',''); my $dbh; my $sth; #database and statements handlers $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database my $st="SELECT UNCOMPRESS(COMPRESS('holacaracola'))='holacaracola'"; @@ -841,7 +841,7 @@ if ($version){return $version} my $dbh; my $sth; #database and statements handlers $dbh=open_db($db) or ( - print localtime().": There was a problem opening the database $db: $DBI::errstr\n" and + print localtime().": There was a problem opening the database $db\n" and return 0 ); #we open the database $version=$dbh->get_info(18); @@ -924,11 +924,11 @@ if (!$only_clean){ #nothing more to do because we just should clean if (-r $file){ put_csv_into_db($config,$file,$table) or ( - print localtime().": There was a problem populating the table $table with file $file\n" and + print localtime().": There was a problem populating the table $table with file $file: $!\n" and return 0 ); }else{ - print localtime().": WARNING no database file found, it should be $file\n"; + print localtime().": WARNING no database file found, it should be $file: $!\n"; return 0; } } @@ -945,11 +945,11 @@ if (!$only_clean){ #nothing more to do because we just should clean if (-r $file){ put_csv_into_db($config,$file,$table) or ( - print localtime().": There was a problem populating the table $table with file $file\n" and + print localtime().": There was a problem populating the table $table with file $file: $!\n" and return 0 ); }else{ - print localtime().": WARNING no working on file found, it should be $file\n"; + print localtime().": WARNING no working_on_dat file found, it should be $file: $!\n"; return 0; } } @@ -966,11 +966,11 @@ if (!$only_clean){ #nothing more to do because we just should clean if (-r $file){ put_csv_into_db($config,$file,$table) or ( - print localtime().": There was a problem populating the table $table with file $file\n" and + print localtime().": There was a problem populating the table $table with file $file: $!\n" and return 0 ); }else{ - print localtime().": WARNING no researcher file found, it should be $file\n"; + print localtime().": WARNING no researcher file found, it should be $file: $!\n"; return 0; } } @@ -987,11 +987,11 @@ if (!$only_clean){ #nothing more to do because we just should clean if (-r $file){ put_csv_into_db($config,$file,$table) or ( - print localtime().": There was a problem populating the table $table with file $file\n" and + print localtime().": There was a problem populating the table $table with file $file: $!\n" and return 0 ); }else{ - print localtime().": WARNING no marker-EST file found, it should be $file\n"; + print localtime().": WARNING no marker-EST file found, it should be $file: $!\n"; return 0; } } @@ -1026,11 +1026,11 @@ my $table = 'microarray_extract'; if (-r $file){ put_csv_into_db($config,$file,$table) or ( - print localtime().": There was a problem populating the table $table with file $file\n" and + print localtime().": There was a problem populating the table $table with file $file: $!\n" and return 0 ); }else{ - print localtime().": WARNING no extracts file found, it should be $file\n"; + print localtime().": WARNING no extracts file found, it should be $file: $!\n"; return 0; } #loading extract mixes @@ -1038,11 +1038,11 @@ my $table = 'microarray_extract_mix'; if (-r $file){ put_csv_into_db($config,$file,$table) or ( - print localtime().": There was a problem populating the table $table with file $file\n" and + print localtime().": There was a problem populating the table $table with file $file: $!\n" and return 0 ); }else{ - print localtime().": WARNING no extract mixes file found, it should be $file\n"; + print localtime().": WARNING no extract mixes file found, it should be $file: $!\n"; return 0; } #loading the hybridizations @@ -1050,18 +1050,18 @@ my $table = 'microarray_hybridization'; if (-r $file){ put_csv_into_db($config,$file,$table) or ( - print localtime().": There was a problem populating the table $table with file $file\n" and + print localtime().": There was a problem populating the table $table with file $file: $!\n" and return 0 ); }else{ - print localtime().": WARNING no hybridizations file found, it should be $file\n"; + print localtime().": WARNING no hybridizations file found, it should be $file: $!\n"; return 0; } my $file = read_config($config,'microarray_normalized_dat',''); my $table = 'microarray_normalized_expression'; if (-r $file){ open IN,"<$file" or ( - print localtime().": Imposible to open file: $file\n" and + print localtime().": Imposible to open file: $file: $!\n" and return 0 ); @@ -1099,15 +1099,15 @@ $sth->bind_param(4,$cv); $i_hyb++; $sth->execute or ( - print localtime().": Unable to execute stament: $st: $DBI::errstr\n" and - print localtime().": With line: $line\n" and + print localtime().": Unable to execute stament: $st\n" and + print localtime().": With line: $line: $DBI::errstr\n" and return 0 ); } } close IN; }else{ - print localtime().": WARNING no normalized expression file found, it should be $file\n"; + print localtime().": WARNING no normalized expression file found, it should be $file: $!\n"; return 0; } @@ -1179,7 +1179,7 @@ #print $contents{$table},"\n"; create_table($db,$table,$contents{$table}) or $ok=0; unless ($ok){ - print localtime().": Annotation table: $table from $db can't be created\n"; + print localtime().": Annotation table: $table from $db can't be created: $DBI::errstr\n"; } } } @@ -1200,7 +1200,7 @@ #if the table exist is removed if (check_table($db,$table)) {drop_table($db,$table) or $ok=0} unless ($ok){ - print localtime().": Annotation table: $table from $db can't be dropped\n"; + print localtime().": Annotation table: $table from $db can't be dropped: $DBI::errstr\n"; } } } @@ -1220,7 +1220,7 @@ my $db=read_config($config,'db_path',''); open IN,"<$file" or ( - print localtime().": Imposible to open file $file: $!\n" and + print localtime().": Imposible to open file: $file: $!\n" and return 0 ); @@ -1235,10 +1235,13 @@ return 0; } my $sth=prepare_st($dbh,$st) or ( - print localtime().": Unable to prepare statement $st: $DBI::errstr\n" and + print localtime().": Unable to prepare statement: $st: $DBI::errstr\n" and return 0 ); while ($line = ){ + if ($line =~ /^#/) { + next; + } chomp ($line); $line =~ s/"//g; my @fields=split (',',$line); @@ -1248,8 +1251,8 @@ $i++; } $sth->execute or ( - print localtime().": Unable to execute stament $st: $DBI::errstr\n" and - print localtime().": With line: $line\n" and + print localtime().": Unable to execute stament: $st\n" and + print localtime().": With line: $line: $DBI::errstr\n" and return 0 ); } @@ -1312,7 +1315,7 @@ #here we read all the db structure, the table fields and contigs my %db_structure=read_db_structure ($db_structure_file,$config); unless (%db_structure) { - print localtime().": There was a problem reading the database definition from file $db_structure_file: $!\n"; + print localtime().": There was a problem reading the database definition from file: $db_structure_file"; return 0; } #the table is regenerated @@ -1351,12 +1354,14 @@ #Here we check that the database is reachable and has all the necesary tables $ok=check_db_structure($db_path,%db_structure); } - #print_db_structure(%db_structure); + if (!$ok) { + print_db_structure(%db_structure); + } return $ok; } #Here we check that the database is reachable and has all the necesary tables -#this is not enough becouse fields should be checked too, so TODO +#this is not enough because fields should be checked too, so TODO #(although not a very important thing anyway) sub check_db_structure($\%) { my $db=shift; @@ -1375,6 +1380,8 @@ } } } + } else { + $ok=0; } if ($ok) { print localtime().": Database structure seems ok\n"; @@ -1422,7 +1429,7 @@ print localtime().": Connection to the database server $db_path_no_name has failed: $DBI::errstr\n"; return 0; } - #Now we check if db exists and if does is dropped + #Now we check if db exists and if it does it is dropped if(db_ok($db_path)){ #database exits, we should remove it if(drop_db($db_path,$db_name)) { @@ -1458,13 +1465,23 @@ sub populate_db ($\%) { my $db=shift; my $tables=shift; + my %t = %$tables; my $ok=1; + print "populate_db called with db=$db, tables=$tables\n"; + #foreach my $table(keys(%t)) { + # print "table=$table, $t{$table}\n"; + #} + my $table; foreach $table(keys %$tables) { if ($ok) { - $ok=create_table($db,$table,${%{$tables}}{$table}); + $ok=create_table($db,$table,$t{$table}); # avoid Can't use string ("38/64") as a HASH ref while "strict refs" in use at /opt/est2uni/pipe_db.pm line 1477. + if ($ok) { print localtime().": Table $table created\n"; + } else { + print localtime().": Table $table could not be created under dsn=$db: $DBI::errstr\n"; + } } } return $ok; @@ -1476,7 +1493,7 @@ my $db=shift; my $table_name=shift; my $table_content=shift; #table content in sql format - #first we check that the database is avaliable + #first we check that the database is available my $ok=1; unless (db_ok($db)) { print localtime().": Something went wrong checking database: $db\n"; @@ -1488,9 +1505,13 @@ my $st="CREATE TABLE $table_name ($table_content);"; if($ok) { $sth=prepare_st($dbh,$st) or $ok=0; + } else { + print localtime().": There was a problem preparing a statement: $DBI::errstr\n"; } if ($ok) { execute_st($sth) or $ok=0; + } else { + print localtime().": There was a problem executing a statement: $DBI::errstr\n"; } #print $table; $sth->finish(); @@ -1533,17 +1554,13 @@ #needs a db handler sub close_db ($) { my $dbh=shift; - if ($dbh){ - $dbh->disconnect() or print localtime().": Cannot disconnect from database: $DBI::errstr\n"; - } + if ($dbh){$dbh->disconnect();} } #needs a statement handler sub close_st ($) { my $sth=shift; - if ($sth){ - $sth->finish() or print localtime().": Cannot finish execution over database: $DBI::errstr\n"; - } + if ($sth){$sth->finish();} } @@ -1563,9 +1580,7 @@ } } - if ($dbh){ - $dbh->disconnect() or print localtime().": Cannot disconnect from database: $DBI::errstr\n"; - } + if ($dbh){$dbh->disconnect();} return $ok; } @@ -1581,9 +1596,7 @@ else { $ok=0; } - if ($dbh){ - $dbh->disconnect() or print localtime().": Cannot disconnect from database: $DBI::errstr\n"; - } + if ($dbh){$dbh->disconnect();} return $ok; } @@ -1594,7 +1607,7 @@ my $ok=1; #is the database to remove ok? unless (db_ok($db)) { - print localtime().": Something went wrong checking database $db: $DBI::errstr\n"; + print localtime().": Something went wrong checking database: $db: $DBI::errstr\n"; $ok=0; } #we should open it @@ -1619,7 +1632,7 @@ } } if ($ok) {$sth->finish();} - if ($dbh){$dbh->disconnect() or print localtime().": Cannot disconnect from database: $DBI::errstr\n";} + if ($dbh){$dbh->disconnect();} return $ok; }