7 test_begin(-tests => 115);
9 use_ok('Bio::Matrix::PSM::IO');
10 use_ok('Bio::DB::TFBS');
11 use_ok('Bio::DB::Taxonomy');
14 #*** need to test getting all ids of a certain kind, like $db->get_matrix_ids();
15 # but hard to do without a complete tax dump
17 my $temp_dir = test_output_dir();
18 my $tax_db = Bio::DB::Taxonomy->new(-source => 'flatfile',
19 -directory => $temp_dir,
20 -nodesfile => test_input_file('taxdump', 'nodes.dmp'),
21 -namesfile => test_input_file('taxdump', 'names.dmp'));
23 # test transfac pro (local flat files)
25 ok my $db = Bio::DB::TFBS->new(-source => 'transfac_pro',
26 -index_dir => $temp_dir,
27 -dat_dir => test_input_file('transfac_pro'),
33 ok my ($ref_id) = $db->get_reference_ids(-pubmed => 16574738);
34 is $ref_id, 'RE0047775';
35 ok my $ref = $db->get_reference($ref_id);
36 isa_ok $ref, 'Bio::Annotation::Reference';
37 is $ref->primary_id, 16574738;
38 is $ref->pubmed, $ref->primary_id;
39 is $ref->database, 'PUBMED';
40 is $ref->authors, '..Bet S . ,.u i rMeK ,,d. vWeWk KaS.ee.nyNk mJMMih. a, i P';
41 is $ref->location, 'Mc (o0o.. 0n)lnir.do 2E:6l';
42 is $ref->title, 'INDD VDGT C1AALEBEI.EIT IYIHLA6ITTE E ANV ITSL MTRTANYE TM NISP TNBAUTPOIORSL I- NVTOD,MHIRRLINSDX TRPY NO CAELUAOA SNMMNT CED5CTH NII TERTOI2IMTVPEH3DSAI';
44 my @sites = $db->get_site_ids(-reference => $ref_id);
45 is join(' ', sort @sites), 'R19310 R19311 R19312 R19313 R19314 R19315 R19316';
46 my @genes = $db->get_gene_ids(-reference => $ref_id);
47 is "@genes", 'G036757';
48 my @ref_ids = $db->get_reference_ids(-site => 'R19310');
49 is "@ref_ids", $ref_id;
50 @ref_ids = $db->get_reference_ids(-gene => 'G036757');
51 is "@ref_ids", $ref_id;
53 $ref_id = 'RE0047531';
54 my @matrices = $db->get_matrix_ids(-reference => $ref_id);
55 is join(' ', sort @matrices), 'M01123 M01124 M01125';
56 my @factors = $db->get_factor_ids(-reference => $ref_id);
57 like "@factors", qr/T08800/;
58 @ref_ids = $db->get_reference_ids(-matrix => 'M01123');
59 is join(' ', sort @ref_ids), "$ref_id RE0047626";
60 @ref_ids = $db->get_reference_ids(-factor => 'T08800');
61 is join(' ', sort @ref_ids), "$ref_id RE0047634 RE0047637 RE0047645";
63 $ref_id = 'RE0023998';
64 my %fragments = map { $_ => 1 } $db->get_fragment_ids(-reference => $ref_id);
65 ok $fragments{'FR0002267'};
66 @ref_ids = $db->get_reference_ids(-fragment => 'FR0002267');
67 is "@ref_ids", $ref_id;
72 ok my ($gene_id) = $db->get_gene_ids(-name => 'P5');
73 is $gene_id, 'G000001';
75 #*** get_genemap with ensembl lookup being fantastically slow
76 #ok defined Bio::Map::Gene->set_from_db; # will try and do ensembl lookups for gene info
77 #ok my $gene_map = $db->get_genemap($gene_id, 1000);
78 #Bio::Tools::Run::Ensembl->_stats;
79 #ok $gene_map->isa('Bio::Map::GeneMap');
80 #ok $gene_map->unique_id, 'G000001';
81 #ok $gene_map->universal_name, 'P5';
82 #ok $gene_map->species->scientific_name, 'Adeno-associated virus';
83 #my @factors = grep { $_->isa("Bio::Map::TranscriptionFactor") } $gene_map->get_elements;
86 ($gene_id) = $db->get_gene_ids(-id => 'AAV$P5');
87 is $gene_id, 'G000001';
88 my @gene_ids = $db->get_gene_ids(-species => '9606');
90 is [sort @gene_ids]->[0], 'G000060'; # in real data this would be G000174, but since our taxdump doesn't have chicken in it, G000060 was changed to human
91 ($gene_id) = $db->get_gene_ids(-site => 'R03174');
92 is $gene_id, 'G000001';
93 ($gene_id) = $db->get_gene_ids(-factor => 'T00267');
94 is $gene_id, 'G000060';
95 my %gene_ids = map { $_ => 1 } $db->get_gene_ids(-fragment => 'FR0002267');
96 ok $gene_ids{'G020751'};
97 # get_gene_ids(-reference => ...) already tested
99 my @site_ids = $db->get_site_ids(-gene => 'G000001');
100 is join(' ', sort @site_ids), 'R03174 R03175 R03176';
101 my @factor_ids = $db->get_factor_ids(-gene => 'G000060');
102 is join(' ', sort @factor_ids), 'T00267 T08293'; # only found for genes that encode factors
103 my %fragment_ids = map { $_ => 1 } $db->get_fragment_ids(-gene => 'G020751');
104 ok $fragment_ids{'FR0002267'};
105 # get_reference_ids(-gene => ...) already tested
110 ok my ($site_id) = $db->get_site_ids(-id => 'HS$IFI616_01');
111 is $site_id, 'R00001';
112 ok my $seq = $db->get_seq($site_id);
113 isa_ok $seq, 'Bio::Seq';
114 is $seq->id, 'HS$IFI616_01';
115 is $seq->accession_number, 'R00001';
116 is $seq->seq, 'aGAGACATAAGTgA';
117 my $annot = $seq->annotation;
118 is [$annot->get_Annotations('relative_start')]->[0]->value, -172;
119 is [$annot->get_Annotations('relative_end')]->[0]->value, -98;
120 is [$annot->get_Annotations('relative_type')]->[0]->value, 'TSS';
121 is [$annot->get_Annotations('relative_to')]->[0]->value, 'G000176';
122 is $seq->species, 9606;
124 my @site_ids = $db->get_site_ids(-species => '9606');
126 is [sort @site_ids]->[0], 'R00001';
127 # get_site_ids(-gene => ...) already tested
128 ($site_id) = $db->get_site_ids(-matrix => 'M00972');
129 is $site_id, 'R00001';
130 my %site_ids = map { $_ => 1 } $db->get_site_ids(-factor => 'T00428');
131 ok $site_ids{R00001};
132 # get_site_ids(-reference => ...) already tested
134 # get_gene_ids(-site => ...) already tested
135 my @matrix_ids = $db->get_matrix_ids(-site => 'R00001');
136 is "@matrix_ids", 'M00972';
137 my @factor_ids = $db->get_factor_ids(-site => 'R00001');
138 is "@factor_ids", 'T00428';
139 # get_reference_ids(-site => ...) already tested
144 ok my ($matrix_id) = $db->get_matrix_ids(-id => 'V$E47_01');
145 is $matrix_id, 'M00002';
146 ok my $matrix = $db->get_matrix($matrix_id);
147 isa_ok $matrix, 'Bio::Matrix::PSM::SiteMatrix';
151 # Lets try to compress and uncompress the frequencies, see if
152 # there is no considerable loss of data.
153 my $fA = $matrix->get_compressed_freq('A');
154 my @check = Bio::Matrix::PSM::SiteMatrix::_uncompress_string($fA,1,1);
155 my @A = $matrix->get_array('A');
156 my ($var, $max) = (0, 0);
157 for (my $i = 0; $i < @check; $i++) {
158 my $diff = abs(abs($check[$i]) - abs($A[$i]));
160 $max = $diff if ($diff > $max);
162 my $avg = $var / @check;
163 cmp_ok $avg, '<', 0.01; # Loss of data under 1 percent
165 # SiteMatrixI methods
166 is $matrix->id, 'V$E47_01';
167 is $matrix->accession_number, $matrix_id;
168 is $matrix->consensus, 'ATGCATGCATGC';
169 is $matrix->IUPAC, 'NNNNNNNNNNNN';
170 is $matrix->regexp, '\S\S\S\S\S\S\S\S\S\S\S\S';
171 is $matrix->width, 12;
172 is $matrix->sites, 5;
177 ok my $aln = $db->get_aln($matrix_id);
178 isa_ok $aln, 'Bio::SimpleAlign';
180 is $aln->num_residues, 132;
182 is $aln->num_sequences, 11;
183 my @ids = qw(R05108 R05109 R05110 R05111 R05112 R05113 R05114 R05115 R05116 R05117 R05118);
184 foreach my $seq ($aln->each_alphabetically) {
185 is $seq->id, shift(@ids);
188 ok ! $db->get_aln('M00001'); # no seqs in db
189 ok $aln = $db->get_aln('M00001', 1); # force to find seqs, store in db
190 ok $aln = $db->get_aln('M00001'); # seqs now in db
191 is $aln->num_sequences, 5;
193 ($matrix_id) = $db->get_matrix_ids(-name => 'MyoD');
194 is $matrix_id, 'M00001';
195 # get_matrix_ids(-site => ...) already tested
196 my %matrix_ids = map { $_ => 1 } $db->get_matrix_ids(-factor => 'T00526');
197 ok $matrix_ids{M00001};
198 # get_matrix_ids(-reference => ...) already tested
200 # get_site_ids(-matrix => ...) already tested
201 my @factor_ids = $db->get_factor_ids(-matrix => 'M00001');
202 is join(' ', sort @factor_ids), 'T00526 T09177';
203 # get_reference_ids(-matrix => ...) already tested
208 ok my ($fragment_id) = $db->get_fragment_ids(-id => 'FR0002267');
209 is $fragment_id, 'FR0002267'; # id and accession are the same for fragments
210 ok my $seq = $db->get_fragment($fragment_id);
211 isa_ok $seq, 'Bio::SeqI';
212 is $seq->id, 'FR0002267';
213 is $seq->seq, 'GTCTACAACACTCTTGCGGACGGAGAGCCGAAGAGCAAAGCGTCGCCGGGTAAGACGAACGCTCAAGGGGGTACGAGCAGCGTAACGACGGAAACGGTGACGCCCCGGGATTTGGGGCTCAGCTAGGGTCGCCGAGTAGGGGGCCGCGGGGACAACGGGGGCGACACGCCGCTTTCCCTGCGTCTGTGGAGCCTATGGTACGGCGTAACCGGTTGTGTGATGAACTGTCCAGACCGCACGTAGTCCCAGCGCAAGGTCTATGCCGCCTAGAGGCAAGACGGGCCGTCTCCTACTTAGTAGCCAGCTACGGGGCGTTGGTCCCCTCGGTAGTGCAACTATCCAGCCACGGCGTCCGCCGGGCTGAGCCTCAGCAGAGCTGGGGGGGTATCATTCCGACGCTGTTTAATTCGTCAGCAGGACCCACTACACGCTCTGTCATTCGCCTGAGCAGTTGTAAATTAGCGCGGCGATCTTGCAAGAGACAAGGAGGCGAACCTGGGGTCGGGACGTAAGGACGAACGGCAGTACAGACGCTGGGGGACGCCACGTGCCAGAACCTCTCACGACCGGAGGTTCAACGCTGATTGGGGCGCAACAGAGGGCGGAGCAGCGAGGTGGCGCTGGTGGGATGGGGCGAGACAAACCCAAGCTGACGCCGAAGGGCCCGCGTGGCCGGGCTGGGGCCCGTAGAACGAGGGAATTGTATGCGGCGCCTGAATGGGCGCACCACA';
214 is $seq->species, 9606;
216 # -id -species -gene -factor -reference
217 my @fragment_ids = $db->get_fragment_ids(-species => '9606');
219 is [sort @fragment_ids]->[0], 'FR0000001';
220 my %fragment_ids = map { $_ => 1 } $db->get_fragment_ids(-factor => 'T03828');
221 ok $fragment_ids{'FR0002267'};
222 # get_fragment_ids(-gene => ...) already tested
223 # get_fragment_ids(-reference => ...) already tested
225 my ($factor_id) = $db->get_factor_ids(-fragment => 'FR0002267');
226 is $factor_id, 'T03828';
227 # get_gene_ids(-fragment => ...) already tested
228 # get_reference_ids(-fragment => ...) already tested
233 ok my ($factor_id) = $db->get_factor_ids(-id => 'T00001');
234 is $factor_id, 'T00001'; # id and accession are the same for factors
235 ok my $factor = $db->get_factor($factor_id);
236 isa_ok $factor, 'Bio::Map::TranscriptionFactor';
237 is $factor->id, 'T00001';
238 is $factor->universal_name, 'AAF';
239 is $factor->known_maps, 1;
240 my @positions = $factor->get_positions;
243 ($factor_id) = $db->get_factor_ids(-name => 'AAF');
244 is $factor_id, 'T00001';
245 my @factor_ids = $db->get_factor_ids(-species => '9606');
247 is [sort @factor_ids]->[0], 'T00001';
248 @factor_ids = $db->get_factor_ids(-interactors => 'T03200');
249 is [sort @factor_ids]->[0], 'T00002';
250 # get_factor_ids(-gene => ...) already tested
251 # get_factor_ids(-site => ...) already tested
252 # get_factor_ids(-matrix => ...) already tested
253 # get_factor_ids(-fragment => ...) already tested
254 # get_factor_ids(-reference => ...) already tested
256 # get_*_ids(-factor => ...) already tested
260 # how to get something like ok $psmIO->release, '10.2--2006-06-30'; ?
261 # or all factors, all sites, all matrices, all genes etc.?