1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 118);
12 use_ok('Bio::LocatableSeq');
13 use_ok('Bio::AlignIO');
16 my ($str, $aln, $seq, $loc);
18 ok $seq = Bio::LocatableSeq->new(
19 -seq => '--atg---gta--',
23 is $seq->alphabet, 'dna';
28 is $seq->column_from_residue_number(4), 9;
29 is $seq->column_from_residue_number(3), 5;
31 ok $loc = $seq->location_from_column(4);
32 isa_ok $loc,'Bio::Location::Simple';
33 is $loc->to_FTstring, 2;
35 ok $loc = $seq->location_from_column(6);
36 isa_ok $loc,'Bio::Location::Simple';
38 is $loc->location_type, 'IN-BETWEEN';
39 is $loc->to_FTstring, '3^4';
41 is $loc = $seq->location_from_column(2), undef;
43 local $TODO = "Need to fix columns before start of seq w/ start > 1";
45 is $loc = $seq->location_from_column(2), undef;
48 $str = Bio::AlignIO->new(-file=> test_input_file('testaln.pfam'));
50 isa_ok $str,'Bio::AlignIO';
51 $aln = $str->next_aln();
52 ok $seq = $aln->get_seq_by_pos(1);
53 is ref($seq), 'Bio::LocatableSeq';
55 is $seq->get_nse, '1433_LYCES/9-246';
56 is $seq->id, '1433_LYCES';
58 # test revcom and trunc
60 $seq = Bio::LocatableSeq->new(
61 -seq => '--atg---gta--',
66 my $seq2 = $seq->trunc(1,9);
67 is $seq2->seq, '--atg---g';
70 is $seq2->strand, $seq->strand;
72 $seq2 = $seq->trunc(3,8);
73 is $seq2->seq, 'atg---';
77 is $seq->strand(-1), -1;
80 $seq2 = $seq->trunc(3,8);
81 is $seq2->seq, 'atg---';
84 $seq2 = $seq->revcom();
85 is $seq2->seq, '--tac---cat--';
86 is $seq2->start, $seq->start;
87 is $seq2->end, $seq->end;
88 is $seq2->strand, $seq->strand * -1;
89 is $seq2->column_from_residue_number(4), 9;
90 is $seq2->column_from_residue_number(3), 5;
92 # test column-mapping for -1 strand sequence
93 $seq = Bio::LocatableSeq->new(
94 -seq => '--atg---gtaa-',
98 is $seq->column_from_residue_number(5),5;
99 is $seq->column_from_residue_number(4),9;
100 ok $loc = $seq->location_from_column(4);
101 isa_ok $loc,'Bio::Location::Simple';
102 is $loc->to_FTstring, 6;
103 ok $loc = $seq->location_from_column(6);
104 isa_ok $loc,'Bio::Location::Simple';
106 is $loc->location_type, 'IN-BETWEEN';
107 is $loc->to_FTstring, '4^5';
110 # more tests for trunc() with strand -1
113 ok $seq = Bio::LocatableSeq->new(
114 -seq => '--atg---gta--',
118 is $seq->alphabet, 'dna';
122 is $seq->num_gaps, 1;
123 is $seq->column_from_residue_number(4), 5;
126 ok $seq2 = $seq->trunc(1,9);
127 is $seq2->seq, '--atg---g';
130 is $seq2->strand, $seq->strand;
132 is $seq->location_from_column(3)->start, 6;
133 is $seq->location_from_column(11)->start, 1;
134 is $seq->location_from_column(9)->start, 3;
138 ok $seq2 = $seq->trunc(7,12);
139 is $seq2->seq, '--gta-';
144 ok $seq2 = $seq->trunc(2,6);
145 is $seq2->seq, '-atg-';
149 ok $seq2 = $seq->trunc(4,7);
150 is $seq2->seq, 'tg--';
154 ok $seq = Bio::LocatableSeq->new();
156 is $seq->start, undef;
159 eval{$nse = $seq->get_nse};
163 eval{$nse = $seq->get_nse};
169 # mapping only supported for 1 => 1, 3 => 1, or 1 => 3 mapping relationships
171 eval{$seq = Bio::LocatableSeq->new(
172 -mapping => [40 => 2],
176 like($@, qr/Mapping values other than 1 or 3 are not currently supported/);
178 eval{$seq = Bio::LocatableSeq->new(
179 -mapping => [3 => 3],
184 # sequence is translated to protein, retains original DNA coordinates
185 # mapping is 1 residue for every 3 coordinate positions
186 $seq = Bio::LocatableSeq->new(
187 -seq => 'KKKAIDLVGVDKARENRQAIYLGASAIAEF',
189 -mapping => [1 => 3],
195 is $seq->seq, 'KKKAIDLVGVDKARENRQAIYLGASAIAEF';
199 # sequence is reverse-translated to DNA, retains original protein coordinates
200 # mapping is 3 residues for every 1 coordinate positions
201 $seq = Bio::LocatableSeq->new(
202 -seq => 'aaraaraargcnathgayytngtnggngtngayaargcnmgngaraaymgncargcnathtayytnggngcnwsngcnathgcngartty',
204 -mapping => [3 => 1],
207 -alphabet => 'protein'
210 is $seq->seq, 'aaraaraargcnathgayytngtnggngtngayaargcnmgngaraaymgncargcnathtayytnggngcnwsngcnathgcngartty';
214 # frameshifts (FASTA-like)
215 # support for this is preliminary
216 # this is a real example from a TFASTY report
218 $seq = Bio::LocatableSeq->new(
219 -seq => 'MGSSSTDRELLSAADVGRTVSRIAHQIIEKTALDDPAERTRVVLLGIPTRGVILATRLAAKIKEFAGEDVPHGALDITLYRDDLNFKPPRPLEATSIPAF\GGVDDAIVILVDDVLYSGRSVRSALDALRDIGRPRIVQLAVLVDRGHRELPI--/DYVGKNVPTSRSESVHVLLSEHDDRDGVVISK',
221 -mapping => [1 => 3],
224 -frameshifts => { # position, frameshift
231 is $seq->seq, 'MGSSSTDRELLSAADVGRTVSRIAHQIIEKTALDDPAERTRVVLLGIPTRGVILATRLAAKIKEFAGEDVPHGALDITLYRDDLNFKPPRPLEATSIPAF\GGVDDAIVILVDDVLYSGRSVRSALDALRDIGRPRIVQLAVLVDRGHRELPI--/DYVGKNVPTSRSESVHVLLSEHDDRDGVVISK';
235 eval { $seq->end(554);};
237 like $@, qr/Overriding value \[554\] with value 552/;
239 lives_ok { $seq = Bio::LocatableSeq->new(
245 );} '* is counted in length';
247 throws_ok { $seq = Bio::LocatableSeq->new(
253 );} qr/Overriding value \[6\] with value 5/, '* is counted in length, but end is wrong';
255 # setting symbols (class variables) - demonstrate scoping issues when using
256 # globals with and w/o localization. To be fixed in a future BioPerl version
262 $temp = $Bio::LocatableSeq::GAP_SYMBOLS;
263 $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
264 $seq = Bio::LocatableSeq->new(
265 -seq => '??atg-?-gta-?',
271 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
276 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
277 is $seq->end(15), 15;
278 $Bio::LocatableSeq::GAP_SYMBOLS = $temp;
279 is $Bio::LocatableSeq::GAP_SYMBOLS, '\-\.=~';
282 local $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
283 $seq = Bio::LocatableSeq->new(
284 -seq => '??atg-?-gta-?',
290 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
297 # note, recalling the end() method uses old $GAP_SYMBOLS, which
298 # no longer are set (this argues for locally set symbols)
300 local $TODO = 'Bio::LocatableSeq global variables have scoping issues';
301 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
303 isnt $seq->end(19), 19;