1 # -*-Perl-*- Test Harness script for Bioperl
9 test_begin(-tests => 325);
11 use_ok('Bio::Factory::FTLocationFactory');
14 my $simple_impl = "Bio::Location::Simple";
15 my $fuzzy_impl = "Bio::Location::Fuzzy";
16 my $split_impl = "Bio::Location::Split";
18 # Holds strings and results. The latter is an array of expected class name,
19 # min/max start position and position type, min/max end position and position
20 # type, location type, the number of locations, and the strand.
23 # note: the following are directly taken from
24 # http://www.insdc.org/documents/feature_table.html#3.4.3
26 => [$simple_impl, 467, 467, "EXACT",
30 => [$simple_impl, 340, 340, "EXACT",
34 => [$fuzzy_impl, undef, 345, "BEFORE",
38 => [$fuzzy_impl, undef, 1, "BEFORE",
42 => [$fuzzy_impl, 1, 1, "EXACT",
46 => [$fuzzy_impl, 102, 102, "EXACT",
50 => [$fuzzy_impl, 23, 45, "WITHIN",
53 "(122.133)..(204.221)"
54 => [$fuzzy_impl, 122, 133, "WITHIN",
58 => [$simple_impl, 123, 123, "EXACT",
62 => [$fuzzy_impl, 145, 145, "EXACT",
65 "join(12..78,134..202)"
66 => [$split_impl, 12, 12, "EXACT",
69 "complement(join(2691..4571,4918..5163))"
70 => [$split_impl, 2691, 2691, "EXACT",
73 # Partial frameshifted gene at the end of a contig
74 "complement(join(94468..94578,94578..>94889))"
75 => [$split_impl, 94468, 94468, "EXACT",
76 94889, undef, "AFTER",
78 "complement(34..(122.126))"
79 => [$fuzzy_impl, 34, 34, "EXACT",
83 => [$simple_impl, 100, 100, "EXACT",
86 "join(1..100,J00194.1:100..202)"
87 => [$split_impl, 1, 1, "EXACT",
91 # this variant is not really allowed by the FT definition
92 # document but we want to be able to cope with it
94 => [$simple_impl, 100, 100, "EXACT",
97 "((122.133)..(204.221))"
98 => [$fuzzy_impl, 122, 133, "WITHIN",
101 "join(AY016290.1:108..185,AY016291.1:1546..1599)"
102 => [$split_impl, 108, 108, "EXACT",
106 # UNCERTAIN locations and positions (Swissprot)
108 => [$fuzzy_impl, 2465, 2465, "UNCERTAIN",
112 => [$fuzzy_impl, 22, 22, "EXACT",
116 => [$fuzzy_impl, 22, 22, "UNCERTAIN",
120 => [$fuzzy_impl, undef, undef, "UNCERTAIN",
124 => [$fuzzy_impl, undef, 1, "BEFORE",
125 undef, undef, "UNCERTAIN",
128 => [$fuzzy_impl, undef, undef, "UNCERTAIN",
132 => [$fuzzy_impl, 1, 1, "EXACT",
133 undef, undef, "UNCERTAIN",
136 => [$fuzzy_impl, undef, undef, "UNCERTAIN",
137 undef, undef, "UNCERTAIN",
140 => [$fuzzy_impl, 1, 1, "UNCERTAIN",
145 my $locfac = Bio::Factory::FTLocationFactory->new();
146 isa_ok($locfac,'Bio::Factory::LocationFactoryI');
148 # sorting is to keep the order constant from one run to the next
149 foreach my $locstr (keys %testcases) {
150 my $loc = $locfac->from_string($locstr);
151 if($locstr eq "join(AY016290.1:108..185,AY016291.1:1546..1599)") {
152 $loc->seq_id("AY016295.1");
154 if($locstr eq "join(1..100,J00194.1:100..202)") {
155 $loc->seq_id("unknown");
157 my @res = @{$testcases{$locstr}};
158 is(ref($loc), $res[0], $res[0]);
159 is($loc->min_start(), $res[1]);
160 is($loc->max_start(), $res[2]);
161 is($loc->start_pos_type(), $res[3]);
162 is($loc->min_end(), $res[4]);
163 is($loc->max_end(), $res[5]);
164 is($loc->end_pos_type(), $res[6]);
165 is($loc->location_type(), $res[7]);
166 my @locs = $loc->each_Location();
168 my $ftstr = $loc->to_FTstring();
169 # this is a somewhat ugly hack, but we want clean output from to_FTstring()
170 # Umm, then these should really fail, correct?
171 # Should we be engineering workarounds for tests?
172 $locstr = "J00194:100..202" if $locstr eq "J00194:(100..202)";
173 $locstr = "(122.133)..(204.221)" if $locstr eq "((122.133)..(204.221))";
175 is($ftstr, $locstr, "Location String: $locstr");
176 # test strand production
177 is($loc->strand(), $res[9]);
181 skip('nested matches in regex only supported in v5.6.1 and higher', 8) unless $^V gt v5.6.0;
183 # Tests based on location definition (http://www.insdc.org/documents/feature_table.html#3.4)
184 my $string1 = 'complement(join(2691..4571,4918..5163))';
185 my $string2 = 'join(complement(4918..5163),complement(2691..4571))';
186 my $loc1 = $locfac->from_string($string1);
187 my $loc2 = $locfac->from_string($string2);
188 my $loc1_str = $loc1->to_FTstring;
189 my $loc2_str = $loc2->to_FTstring;
190 is($loc1_str, $string1, $string1);
191 is($loc2_str, $string1, $string2);
192 is($loc1_str, $loc2_str, 'equivalent remote location strings');
194 # Test for equivalent reverse strand locations adding one remote component
195 $string1 = 'complement(join(TEST0001.1:2691..4571,4918..5163))';
196 $string2 = 'join(complement(4918..5163),complement(TEST0001.1:2691..4571))';
197 $loc1 = $locfac->from_string($string1);
198 $loc2 = $locfac->from_string($string2);
199 $loc1_str = $loc1->to_FTstring;
200 $loc2_str = $loc2->to_FTstring;
201 is($loc1_str, $string1, $string1);
202 is($loc2_str, $string1, $string2);
203 is($loc1_str, $loc2_str, 'equivalent remote location strings');
205 # Test for equivalent reverse strand locations adding two remote components
206 $string1 = 'complement(join(TEST0001.1:2691..4571,TEST0008.1:4918..5163))';
207 $string2 = 'join(complement(TEST0008.1:4918..5163),complement(TEST0001.1:2691..4571))';
208 $loc1 = $locfac->from_string($string1);
209 $loc2 = $locfac->from_string($string2);
210 $loc1_str = $loc1->to_FTstring;
211 $loc2_str = $loc2->to_FTstring;
212 is($loc1_str, $string1, $string1);
213 is($loc2_str, $string1, $string2);
214 is($loc1_str, $loc2_str, 'equivalent remote location strings');
216 # bug #1674, #1765, 2101
217 # EMBL-like (BAC19856.3 protein)
218 # join(20464..20694,21548..22763,join(complement(314652..314672),complement(232596..232990),complement(231520..231669)))
220 # join(20464..20694,21548..22763,complement(join(231520..231669,232596..232990,314652..314672)))
222 # join(1000..2000,join(3000..4000,join(5000..6000,7000..8000)),9000..10000)
224 # join(1000..2000,3000..4000,5000..6000,7000..8000,9000..10000)
226 my @expected = (# intentionally testing same expected string twice
227 # as I am providing two different encodings
228 # that should mean the same thing
229 'join(11025..11049,complement(join(315036..315294,251354..251412,241499..241580,239890..240081)))',
230 'join(11025..11049,complement(join(315036..315294,251354..251412,241499..241580,239890..240081)))',
232 'join(20464..20694,21548..22763,complement(join(231520..231669,232596..232990,314652..314672)))',
233 'join(20464..20694,21548..22763,complement(join(231520..231669,232596..232990,314652..314672)))',
234 # this is just seen once
235 'join(1000..2000,3000..4000,5000..6000,7000..8000,9000..10000)',
236 'order(S67862.1:72..75,join(S67863.1:1..788,1..19))'
240 'join(11025..11049,join(complement(239890..240081),complement(241499..241580),complement(251354..251412),complement(315036..315294)))',
241 'join(11025..11049,complement(join(315036..315294,251354..251412,241499..241580,239890..240081)))',
242 'join(20464..20694,21548..22763,complement(join(231520..231669,232596..232990,314652..314672)))',
243 'join(20464..20694,21548..22763,join(complement(314652..314672),complement(232596..232990),complement(231520..231669)))',
244 'join(1000..2000,join(3000..4000,join(5000..6000,7000..8000)),9000..10000)',
245 'order(S67862.1:72..75,join(S67863.1:1..788,1..19))'
247 my $loc = $locfac->from_string($locstr);
248 my $ftstr = $loc->to_FTstring();
249 is($ftstr, shift @expected, $locstr);