Permalink
Browse files

*** empty log message ***

svn path=/bioperl-db/branches/post-capetown/; revision=348
  • Loading branch information...
1 parent 0df75f0 commit d62e8922c9137ab63495d1c44b0da5ce541a87a9 @cmungall cmungall committed Aug 18, 2002
Showing with 186 additions and 6 deletions.
  1. +1 −1 Bio/DB/SQL/ReferenceAdaptor.pm
  2. +45 −3 scripts/load_seqdatabase.pl
  3. +41 −0 t/data/revcomp_mrna.t
  4. +2 −2 t/ensembl.t
  5. +97 −0 t/revcomp_mrna.t
@@ -188,7 +188,7 @@ sub store_if_needed{
$self->insert("reference",
{reference_authors=>$authors,
reference_title=>$title,
- reference_location=>$location,
+ reference_location=>$location || '',
reference_medline=>$med});
return $rid;
}
@@ -52,6 +52,8 @@ =head1 ARGUMENTS
my $driver = 'mysql';
my $dbpass = undef;
my $format = 'genbank';
+my $newonly;
+my $logf;
my $removeflag = '';
my $transactional = 0;
#If safe is turned on, the script doesn't die because of one bad entry..
@@ -64,10 +66,18 @@ =head1 ARGUMENTS
'dbpass:s' => \$dbpass,
'format:s' => \$format,
'safe' => \$safe,
+ 'log:s' => \$log,
'remove' => \$remove,
'transactional' => \$transactional,
+ 'newonly' => \$newonly,
);
+my $logfh = \*STDERR;
+
+if ($log) {
+ $logfh = FileHandle->new(">$log") || die("can't open $log");
+}
+
my $dbname = shift;
my @files = @ARGV;
@@ -79,6 +89,7 @@ =head1 ARGUMENTS
then the whole application must fail, otherwise we risk the cache and the
database being out of sync, which could have very bad consequences
EOM
+ exit 1;
}
if( !defined $dbname || scalar(@files) == 0 ) {
@@ -98,10 +109,24 @@ =head1 ARGUMENTS
foreach $file ( @files ) {
- print STDERR "Reading $file\n";
+ my $t = time;
+ my $ppt = localtime $t;
+ logmsg("Reading:$file");
my $seqio = Bio::SeqIO->new(-file => $file,-format => $format);
while( $seq = $seqio->next_seq ) {
+ logmsg("Got seq: %s [length %d]",
+ $seq->display_id,
+ $seq->length);
+ if ($newonly) {
+ my $oldseq =
+ $seqadp->fetch_by_db_and_accession($dbname, $seq->accession);
+ if ($oldseq) {
+ logmsg("ALREADY HAVE THIS SEQ (bioentry_id=%d) -- SKIPPING",
+ $oldseq->primary_id);
+ next;
+ }
+ }
$dbadaptor->begin_work if $transactional;
if ($removeflag) {
my $oldseq =
@@ -112,18 +137,35 @@ =head1 ARGUMENTS
$seqadp->store($dbid,$seq);
};
if ($@) {
- print STDERR "Could not store ".$seq->accession." because of $@\n";
+ logmsg("Could not store ".$seq->accession." because of $@");
}
}
else {
$seqadp->store($dbid,$seq);
}
$dbadaptor->commit if $transactional;
+ logmsg("loaded seq %s", $seq->display_id);
}
}
-$dbadaptor->disconnect;
+if ($log) {
+ $logfh->close;
+}
+$dbadaptor->disconnect;
+printf $logfh "Done!\n";
+print $logfh "Unixtime:$t\n";
+print $logfh "Date:$ppt\n";
+
+sub logmsg {
+ my $msg = sprintf(shift, @_);
+ my $t = time;
+ my $ppt = localtime $t;
+ print $logfh "\n$msg\n";
+ print $logfh "Unixtime:$t\n";
+ print $logfh "Date:$ppt\n\n";
+
+}
View
@@ -0,0 +1,41 @@
+
+use lib 't';
+
+BEGIN {
+ # to handle systems with no installed Test module
+ # we include the t dir (where a copy of Test.pm is located)
+ # as a fallback
+ eval { require Test; };
+ use Test;
+ plan tests => 14;
+}
+#END { unlink( 't/cjm_test.gb') }
+use DBTestHarness;
+use Bio::DB::SQL::DBAdaptor;
+use Bio::SeqIO;
+use Bio::Root::IO;
+
+$harness = DBTestHarness->new();
+
+ok $harness;
+
+$db = $harness->get_DBAdaptor();
+
+ok $db;
+
+$seqio = Bio::SeqIO->new('-format' => 'GenBank',-file => Bio::Root::IO->catfile('t','data','revcomp_mrna.gb'));
+
+$seq = $seqio->next_seq();
+
+$out = Bio::SeqIO->new( -file => '>t/revcomp_mrna_test.gb' , -"format" => 'GenBank');
+
+
+$out->write_seq($seq);
+
+foreach my $sf ( $seq->top_SeqFeatures ) {
+ use Data::Dumper;
+ print Dumper $sf;
+ die;
+}
+
+ok $out;
View
@@ -9,7 +9,7 @@ BEGIN {
use Test;
plan tests => 14;
}
-END { unlink( 't/ensembl_test.gb') }
+#END { unlink( 't/ensembl_test.gb') }
use DBTestHarness;
use Bio::DB::SQL::DBAdaptor;
use Bio::SeqIO;
@@ -72,5 +72,5 @@ $out = Bio::SeqIO->new( -file => '>t/ensembl_test.gb' , -"format" => 'GenBank');
$out->write_seq($dbseq);
-
+
ok $out;
View
@@ -0,0 +1,97 @@
+
+use lib 't';
+
+BEGIN {
+ # to handle systems with no installed Test module
+ # we include the t dir (where a copy of Test.pm is located)
+ # as a fallback
+ eval { require Test; };
+ use Test;
+ plan tests => 21;
+}
+END { unlink( 't/revomp_mrna_test.gb') }
+use DBTestHarness;
+use Bio::DB::SQL::DBAdaptor;
+use Bio::SeqIO;
+use Bio::Root::IO;
+
+$harness = DBTestHarness->new();
+
+ok $harness;
+
+$db = $harness->get_DBAdaptor();
+
+ok $db;
+
+$seqio = Bio::SeqIO->new('-format' => 'GenBank',-file => Bio::Root::IO->catfile('t','data','revcomp_mrna.gb'));
+
+$seq = $seqio->next_seq();
+
+ok $seq;
+
+$seqadaptor = $db->get_SeqAdaptor;
+
+ok $seqadaptor;
+
+$biodbadaptor = $db->get_BioDatabaseAdaptor;
+
+$id = $biodbadaptor->fetch_by_name_store_if_needed('genbank');
+
+$seqadaptor->store($id,$seq);
+
+# assumme bioentry_id is 1 - probably safe ;)
+$dbseq = $seqadaptor->fetch_by_dbID(1);
+
+ok $dbseq;
+
+ok ($dbseq->display_id eq $seq->display_id);
+
+ok ($dbseq->accession eq $seq->accession);
+
+ok ($dbseq->seq eq $seq->seq);
+
+ok ($dbseq->subseq(3,10) eq $seq->subseq(3,10) );
+
+ok ($dbseq->subseq(1,15) eq $seq->subseq(1,15) );
+
+ok ($dbseq->length == $seq->length);
+
+ok ($dbseq->length == length($dbseq->seq));
+
+my $test_desc = $seq->desc;
+$test_desc =~ s/\s+$//g;
+
+ok ($dbseq->desc eq $test_desc);
+
+my ($sf) = $dbseq->top_SeqFeatures;
+my $location = $sf->location;
+#$location->verbose(-1); # silence the warning of undef seq_id()
+printf "[%d, %d] %s\n",
+ $location->start,
+ $location->end,
+ $location->strand;
+#ok($location->strand, -1);
+#ok($location->start, );
+#ok($location->end, );
+
+my @sublocs = $location->sub_Location();
+
+ok(@sublocs, 4);
+my $loc = shift @sublocs;
+ok($loc->start, 3261);
+ok($loc->end, 4308);
+ok($loc->strand, -1);
+
+$loc = pop @sublocs;
+ok($loc->start, 13603);
+ok($loc->end, 13879);
+ok($loc->strand,-1);
+
+
+#$harness->pause;
+
+$out =
+ Bio::SeqIO->new( -file => '>t/revomp_mrna_test.gb' , -"format" => 'GenBank');
+
+$out->write_seq($dbseq);
+ok $out;

0 comments on commit d62e892

Please sign in to comment.