7 test_begin(-tests => 61);
9 use_ok('DBTestHarness');
13 $biosql = DBTestHarness->new("biosql");
14 $db = $biosql->get_DBAdaptor();
17 my $seqio = Bio::SeqIO->new('-format' => 'genbank',
18 '-file' => test_input_file('test.genbank'));
26 while($seq = $seqio->next_seq()) {
27 $pseq = $db->create_persistent($seq);
28 $pseq->namespace("mytestnamespace");
30 ok $pseq->primary_key();
31 cmp_ok $pseq->primary_key(), '!=', $pk;
32 $pk = $pseq->primary_key();
35 is (scalar(@seqs), 4);
36 $pseq = $seqs[@seqs-1];
38 $seqadp = $db->get_object_adaptor("Bio::SeqI");
41 # re-fetch from database
42 $pseq = $seqadp->find_by_primary_key($pseq->primary_key());
45 @arr = $pseq->top_SeqFeatures();
46 is (scalar(@arr), 26);
49 @arr = $pseq->annotation()->get_Annotations("reference");
52 # all feature qualifier/value pairs
54 foreach my $feat ($pseq->top_SeqFeatures()) {
55 foreach ($feat->get_all_tags()) {
56 push(@arr, $feat->each_tag_value($_));
59 is (scalar(@arr), 38);
62 foreach my $feat ($pseq->top_SeqFeatures()) {
63 is ($feat->remove(), 1);
66 # delete all references
67 foreach my $ref ($pseq->annotation()->get_Annotations("reference")) {
68 is ($ref->remove(), 1);
71 # re-fetch sequence and retest
72 $pseq = $seqadp->find_by_primary_key($pseq->primary_key());
75 @arr = $pseq->top_SeqFeatures();
79 @arr = $pseq->annotation()->get_Annotations("reference");
82 # test removing associations:
84 # add the same comment to both seq0 and seq1
85 my $cmt = Bio::Annotation::Comment->new(
86 -tagname => "comment",
87 -text => "this is a simple comment");
88 # add the same simple value to both seq0 and seq1
89 my $sv = Bio::Annotation::SimpleValue->new(-tagname => "Fancy",
90 -value => "a simple value");
91 $seqs[0]->annotation->add_Annotation($cmt);
92 $seqs[0]->annotation->add_Annotation($sv);
93 $seqs[1]->annotation->add_Annotation($cmt);
94 $seqs[1]->annotation->add_Annotation($sv);
97 # delete all annotation from seq0 (also shares a reference with seq1)
98 ok $seqs[0]->annotation->remove(-fkobjs => [$seqs[0]]);
100 # now re-fetch seq0 and seq1 by primary key
101 $pseq = $seqadp->find_by_primary_key($seqs[0]->primary_key);
102 my $pseq1 = $seqadp->find_by_primary_key($seqs[1]->primary_key);
103 # test annotation counts and whether seq1 was unaffected
104 is (scalar($pseq->annotation->get_Annotations()), 0);
105 is (scalar($pseq1->annotation->get_Annotations("reference")), 3);
106 is (scalar($pseq1->annotation->get_Annotations("comment")), 1);
107 my ($cmt1) = $pseq1->annotation->get_Annotations("comment");
108 is ($cmt1->text, $cmt->text);
109 is (scalar($pseq1->annotation->get_Annotations("Fancy")), 1);
110 my ($sv1) = $pseq1->annotation->get_Annotations("Fancy");
111 is ($sv1->value, $sv->value);
114 print STDERR $@ if $@;
117 foreach $pseq (@seqs) {
118 is ($pseq->remove(), 1);
120 my $ns = Bio::DB::Persistent::BioNamespace->new(-identifiable => $pseq);
121 ok $ns = $db->get_object_adaptor($ns)->find_by_unique_key($ns);
122 ok $ns->primary_key();
123 is ($ns->remove(), 1);