1 # -*-Perl-*- Test Harness script for Bioperl
10 test_begin(-tests => 119);
12 use_ok('Bio::LocatableSeq');
13 use_ok('Bio::AlignIO');
16 my ($str, $aln, $seq, $loc);
20 ok $seq = Bio::LocatableSeq->new(
21 -seq => '--atg---gta--',
25 is $seq->alphabet, 'dna';
30 is $seq->column_from_residue_number(4), 9;
31 is $seq->column_from_residue_number(3), 5;
33 ok $loc = $seq->location_from_column(4);
34 isa_ok $loc,'Bio::Location::Simple';
35 is $loc->to_FTstring, 2;
37 ok $loc = $seq->location_from_column(6);
38 isa_ok $loc,'Bio::Location::Simple';
40 is $loc->location_type, 'IN-BETWEEN';
41 is $loc->to_FTstring, '3^4';
43 is $loc = $seq->location_from_column(2), undef;
45 local $TODO = "Need to fix columns before start of seq w/ start > 1";
47 is $loc = $seq->location_from_column(2), undef;
50 $str = Bio::AlignIO->new(-file=> test_input_file('testaln.pfam'));
52 isa_ok $str,'Bio::AlignIO';
53 $aln = $str->next_aln();
54 ok $seq = $aln->get_seq_by_pos(1);
55 is ref($seq), 'Bio::LocatableSeq';
57 is $seq->get_nse, '1433_LYCES/9-246';
58 is $seq->id, '1433_LYCES';
60 # test invalid sequence
62 throws_ok{ $seq = Bio::LocatableSeq->new( -seq => '//!\\' ) } qr/.+/;
64 # test revcom and trunc
66 $seq = Bio::LocatableSeq->new(
67 -seq => '--atg---gta--',
72 my $seq2 = $seq->trunc(1,9);
73 is $seq2->seq, '--atg---g';
76 is $seq2->strand, $seq->strand;
78 $seq2 = $seq->trunc(3,8);
79 is $seq2->seq, 'atg---';
83 is $seq->strand(-1), -1;
86 $seq2 = $seq->trunc(3,8);
87 is $seq2->seq, 'atg---';
90 $seq2 = $seq->revcom();
91 is $seq2->seq, '--tac---cat--';
92 is $seq2->start, $seq->start;
93 is $seq2->end, $seq->end;
94 is $seq2->strand, $seq->strand * -1;
95 is $seq2->column_from_residue_number(4), 9;
96 is $seq2->column_from_residue_number(3), 5;
98 # test column-mapping for -1 strand sequence
99 $seq = Bio::LocatableSeq->new(
100 -seq => '--atg---gtaa-',
104 is $seq->column_from_residue_number(5),5;
105 is $seq->column_from_residue_number(4),9;
106 ok $loc = $seq->location_from_column(4);
107 isa_ok $loc,'Bio::Location::Simple';
108 is $loc->to_FTstring, 6;
109 ok $loc = $seq->location_from_column(6);
110 isa_ok $loc,'Bio::Location::Simple';
112 is $loc->location_type, 'IN-BETWEEN';
113 is $loc->to_FTstring, '4^5';
116 # more tests for trunc() with strand -1
119 ok $seq = Bio::LocatableSeq->new(
120 -seq => '--atg---gta--',
124 is $seq->alphabet, 'dna';
128 is $seq->num_gaps, 1;
129 is $seq->column_from_residue_number(4), 5;
132 ok $seq2 = $seq->trunc(1,9);
133 is $seq2->seq, '--atg---g';
136 is $seq2->strand, $seq->strand;
138 is $seq->location_from_column(3)->start, 6;
139 is $seq->location_from_column(11)->start, 1;
140 is $seq->location_from_column(9)->start, 3;
144 ok $seq2 = $seq->trunc(7,12);
145 is $seq2->seq, '--gta-';
150 ok $seq2 = $seq->trunc(2,6);
151 is $seq2->seq, '-atg-';
155 ok $seq2 = $seq->trunc(4,7);
156 is $seq2->seq, 'tg--';
160 ok $seq = Bio::LocatableSeq->new();
162 is $seq->start, undef;
165 eval{$nse = $seq->get_nse};
169 eval{$nse = $seq->get_nse};
175 # mapping only supported for 1 => 1, 3 => 1, or 1 => 3 mapping relationships
177 eval{$seq = Bio::LocatableSeq->new(
178 -mapping => [40 => 2],
182 like($@, qr/Mapping values other than 1 or 3 are not currently supported/);
184 eval{$seq = Bio::LocatableSeq->new(
185 -mapping => [3 => 3],
190 # sequence is translated to protein, retains original DNA coordinates
191 # mapping is 1 residue for every 3 coordinate positions
192 $seq = Bio::LocatableSeq->new(
193 -seq => 'KKKAIDLVGVDKARENRQAIYLGASAIAEF',
195 -mapping => [1 => 3],
201 is $seq->seq, 'KKKAIDLVGVDKARENRQAIYLGASAIAEF';
205 # sequence is reverse-translated to DNA, retains original protein coordinates
206 # mapping is 3 residues for every 1 coordinate positions
207 $seq = Bio::LocatableSeq->new(
208 -seq => 'aaraaraargcnathgayytngtnggngtngayaargcnmgngaraaymgncargcnathtayytnggngcnwsngcnathgcngartty',
210 -mapping => [3 => 1],
213 -alphabet => 'protein'
216 is $seq->seq, 'aaraaraargcnathgayytngtnggngtngayaargcnmgngaraaymgncargcnathtayytnggngcnwsngcnathgcngartty';
220 # frameshifts (FASTA-like)
221 # support for this is preliminary
222 # this is a real example from a TFASTY report
224 $seq = Bio::LocatableSeq->new(
225 -seq => 'MGSSSTDRELLSAADVGRTVSRIAHQIIEKTALDDPAERTRVVLLGIPTRGVILATRLAAKIKEFAGEDVPHGALDITLYRDDLNFKPPRPLEATSIPAF\GGVDDAIVILVDDVLYSGRSVRSALDALRDIGRPRIVQLAVLVDRGHRELPI--/DYVGKNVPTSRSESVHVLLSEHDDRDGVVISK',
227 -mapping => [1 => 3],
230 -frameshifts => { # position, frameshift
237 is $seq->seq, 'MGSSSTDRELLSAADVGRTVSRIAHQIIEKTALDDPAERTRVVLLGIPTRGVILATRLAAKIKEFAGEDVPHGALDITLYRDDLNFKPPRPLEATSIPAF\GGVDDAIVILVDDVLYSGRSVRSALDALRDIGRPRIVQLAVLVDRGHRELPI--/DYVGKNVPTSRSESVHVLLSEHDDRDGVVISK';
241 eval { $seq->end(554);};
243 like $@, qr/Overriding value \[554\] with value 552/;
245 lives_ok { $seq = Bio::LocatableSeq->new(
251 );} '* is counted in length';
253 throws_ok { $seq = Bio::LocatableSeq->new(
259 );} qr/Overriding value \[6\] with value 5/, '* is counted in length, but end is wrong';
261 # setting symbols (class variables) - demonstrate scoping issues when using
262 # globals with and w/o localization. To be fixed in a future BioPerl version
268 $temp = $Bio::LocatableSeq::GAP_SYMBOLS;
269 $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
270 $seq = Bio::LocatableSeq->new(
271 -seq => '??atg-?-gta-?',
277 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
282 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
283 is $seq->end(15), 15;
284 $Bio::LocatableSeq::GAP_SYMBOLS = $temp;
285 is $Bio::LocatableSeq::GAP_SYMBOLS, '\-\.=~';
288 local $Bio::LocatableSeq::GAP_SYMBOLS = '-\?';
289 $seq = Bio::LocatableSeq->new(
290 -seq => '??atg-?-gta-?',
296 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
303 # note, recalling the end() method uses old $GAP_SYMBOLS, which
304 # no longer are set (this argues for locally set symbols)
306 local $TODO = 'Bio::LocatableSeq global variables have scoping issues';
307 is $Bio::LocatableSeq::GAP_SYMBOLS, '-\?';
309 isnt $seq->end(19), 19;