1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 119);
11 use_ok('Bio::LocatableSeq');
12 use_ok('Bio::AlignIO');
15 my ($str, $aln, $seq, $loc);
19 ok $seq = Bio::LocatableSeq->new(
20 -seq => '--atg---gta--',
24 is $seq->alphabet, 'dna';
29 is $seq->column_from_residue_number(4), 9;
30 is $seq->column_from_residue_number(3), 5;
32 ok $loc = $seq->location_from_column(4);
33 isa_ok $loc,'Bio::Location::Simple';
34 is $loc->to_FTstring, 2;
36 ok $loc = $seq->location_from_column(6);
37 isa_ok $loc,'Bio::Location::Simple';
39 is $loc->location_type, 'IN-BETWEEN';
40 is $loc->to_FTstring, '3^4';
42 is $loc = $seq->location_from_column(2), undef;
44 local $TODO = "Need to fix columns before start of seq w/ start > 1";
46 is $loc = $seq->location_from_column(2), undef;
49 $str = Bio::AlignIO->new(-file=> test_input_file('testaln.pfam'));
51 isa_ok $str,'Bio::AlignIO';
52 $aln = $str->next_aln();
53 ok $seq = $aln->get_seq_by_pos(1);
54 is ref($seq), 'Bio::LocatableSeq';
56 is $seq->get_nse, '1433_LYCES/9-246';
57 is $seq->id, '1433_LYCES';
59 # test invalid sequence
61 throws_ok{ $seq = Bio::LocatableSeq->new( -seq => '//!\\' ) } qr/.+/;
63 # test revcom and trunc
65 $seq = Bio::LocatableSeq->new(
66 -seq => '--atg---gta--',
71 my $seq2 = $seq->trunc(1,9);
72 is $seq2->seq, '--atg---g';
75 is $seq2->strand, $seq->strand;
77 $seq2 = $seq->trunc(3,8);
78 is $seq2->seq, 'atg---';
82 is $seq->strand(-1), -1;
85 $seq2 = $seq->trunc(3,8);
86 is $seq2->seq, 'atg---';
89 $seq2 = $seq->revcom();
90 is $seq2->seq, '--tac---cat--';
91 is $seq2->start, $seq->start;
92 is $seq2->end, $seq->end;
93 is $seq2->strand, $seq->strand * -1;
94 is $seq2->column_from_residue_number(4), 9;
95 is $seq2->column_from_residue_number(3), 5;
97 # test column-mapping for -1 strand sequence
98 $seq = Bio::LocatableSeq->new(
99 -seq => '--atg---gtaa-',
103 is $seq->column_from_residue_number(5),5;
104 is $seq->column_from_residue_number(4),9;
105 ok $loc = $seq->location_from_column(4);
106 isa_ok $loc,'Bio::Location::Simple';
107 is $loc->to_FTstring, 6;
108 ok $loc = $seq->location_from_column(6);
109 isa_ok $loc,'Bio::Location::Simple';
111 is $loc->location_type, 'IN-BETWEEN';
112 is $loc->to_FTstring, '4^5';
115 # more tests for trunc() with strand -1
118 ok $seq = Bio::LocatableSeq->new(
119 -seq => '--atg---gta--',
123 is $seq->alphabet, 'dna';
127 is $seq->num_gaps, 1;
128 is $seq->column_from_residue_number(4), 5;
131 ok $seq2 = $seq->trunc(1,9);
132 is $seq2->seq, '--atg---g';
135 is $seq2->strand, $seq->strand;
137 is $seq->location_from_column(3)->start, 6;
138 is $seq->location_from_column(11)->start, 1;
139 is $seq->location_from_column(9)->start, 3;
143 ok $seq2 = $seq->trunc(7,12);
144 is $seq2->seq, '--gta-';
149 ok $seq2 = $seq->trunc(2,6);
150 is $seq2->seq, '-atg-';
154 ok $seq2 = $seq->trunc(4,7);
155 is $seq2->seq, 'tg--';
159 ok $seq = Bio::LocatableSeq->new();
161 is $seq->start, undef;
164 eval{$nse = $seq->get_nse};
168 eval{$nse = $seq->get_nse};
174 # mapping only supported for 1 => 1, 3 => 1, or 1 => 3 mapping relationships
176 eval{$seq = Bio::LocatableSeq->new(
177 -mapping => [40 => 2],
181 like($@, qr/Mapping values other than 1 or 3 are not currently supported/);
183 eval{$seq = Bio::LocatableSeq->new(
184 -mapping => [3 => 3],
189 # sequence is translated to protein, retains original DNA coordinates
190 # mapping is 1 residue for every 3 coordinate positions
191 $seq = Bio::LocatableSeq->new(
192 -seq => 'KKKAIDLVGVDKARENRQAIYLGASAIAEF',
194 -mapping => [1 => 3],
200 is $seq->seq, 'KKKAIDLVGVDKARENRQAIYLGASAIAEF';
204 # sequence is reverse-translated to DNA, retains original protein coordinates
205 # mapping is 3 residues for every 1 coordinate positions
206 $seq = Bio::LocatableSeq->new(
207 -seq => 'aaraaraargcnathgayytngtnggngtngayaargcnmgngaraaymgncargcnathtayytnggngcnwsngcnathgcngartty',
209 -mapping => [3 => 1],
212 -alphabet => 'protein'
215 is $seq->seq, 'aaraaraargcnathgayytngtnggngtngayaargcnmgngaraaymgncargcnathtayytnggngcnwsngcnathgcngartty';
219 # frameshifts (FASTA-like)
220 # support for this is preliminary
221 # this is a real example from a TFASTY report
223 $seq = Bio::LocatableSeq->new(
224 -seq => 'MGSSSTDRELLSAADVGRTVSRIAHQIIEKTALDDPAERTRVVLLGIPTRGVILATRLAAKIKEFAGEDVPHGALDITLYRDDLNFKPPRPLEATSIPAF\GGVDDAIVILVDDVLYSGRSVRSALDALRDIGRPRIVQLAVLVDRGHRELPI--/DYVGKNVPTSRSESVHVLLSEHDDRDGVVISK',
226 -mapping => [1 => 3],
229 -frameshifts => { # position, frameshift
236 is $seq->seq, 'MGSSSTDRELLSAADVGRTVSRIAHQIIEKTALDDPAERTRVVLLGIPTRGVILATRLAAKIKEFAGEDVPHGALDITLYRDDLNFKPPRPLEATSIPAF\GGVDDAIVILVDDVLYSGRSVRSALDALRDIGRPRIVQLAVLVDRGHRELPI--/DYVGKNVPTSRSESVHVLLSEHDDRDGVVISK';
240 eval { $seq->end(554);};
242 like $@, qr/Overriding value \[554\] with value 552/;
244 lives_ok { $seq = Bio::LocatableSeq->new(
250 );} '* is counted in length';
252 throws_ok { $seq = Bio::LocatableSeq->new(
258 );} qr/Overriding value \[6\] with value 5/, '* is counted in length, but end is wrong';
260 # setting symbols (class variables) - demonstrate scoping issues when using
261 # globals with and w/o localization. To be fixed in a future BioPerl version
267 $temp = $Bio::LocatableSeq::GAP_SYMBOLS;
268 $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
269 $seq = Bio::LocatableSeq->new(
270 -seq => '??atg-?-gta-?',
276 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
281 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
282 is $seq->end(15), 15;
283 $Bio::LocatableSeq::GAP_SYMBOLS = $temp;
284 is $Bio::LocatableSeq::GAP_SYMBOLS, '\-\.=~';
287 local $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
288 $seq = Bio::LocatableSeq->new(
289 -seq => '??atg-?-gta-?',
295 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
302 # note, recalling the end() method uses old $GAP_SYMBOLS, which
303 # no longer are set (this argues for locally set symbols)
305 local $TODO = 'Bio::LocatableSeq global variables have scoping issues';
306 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
308 isnt $seq->end(19), 19;