From 13b63a5062917e46fb8b86ff41ceb79b9b494de1 Mon Sep 17 00:00:00 2001 From: "Francisco J. Ossandon" Date: Thu, 7 Aug 2014 15:49:23 -0400 Subject: [PATCH] FTLocationFactory.pm: Fixed a long-standing issue at "from_string()" and now "join(A..B,join(C..D,join(E..F,G..H)),I..J)" is equivalent to "join(A..B,C..D,E..F,G..H,J..I)". Updated test. --- Bio/Factory/FTLocationFactory.pm | 19 ++++++++++++++++++- t/SeqFeature/LocationFactory.t | 3 +-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Bio/Factory/FTLocationFactory.pm b/Bio/Factory/FTLocationFactory.pm index 579332149..c909bf8e2 100644 --- a/Bio/Factory/FTLocationFactory.pm +++ b/Bio/Factory/FTLocationFactory.pm @@ -245,7 +245,24 @@ sub from_string { $loc_obj->strand(-1); } - push @loc_objs, $loc_obj; + # For Split-type $loc_obj, if guide strand is set (meaning consistent strand for + # all sublocs) and guide strand is the same than the last location from @loc_objs, + # then recover the sublocations and add them to @loc_objs. This way, + # "join(10..20,join(30..40,50..60))" becomes "join(10..20,30..40,50..60)" + my $guide_strand = ($loc_obj->isa('Bio::Location::SplitLocationI')) ? ($loc_obj->guide_strand || 0) : 0; + my $last_strand = (scalar @loc_objs > 0) ? $loc_objs[-1]->strand : 0; + if ( $guide_strand != 0 + and $guide_strand == $last_strand + and $oparg eq $op # join(,join()) OK, order(join()) NOT OK + ) { + my @subloc_objs = $loc_obj->sub_Location(0); + foreach my $subloc_obj (@subloc_objs) { + push @loc_objs, $subloc_obj; + } + } + else { + push @loc_objs, $loc_obj; + } } my $ct = @loc_objs; if ($op && !($op eq 'join' || $op eq 'order' || $op eq 'bond') diff --git a/t/SeqFeature/LocationFactory.t b/t/SeqFeature/LocationFactory.t index f94a999b2..94c417ac5 100644 --- a/t/SeqFeature/LocationFactory.t +++ b/t/SeqFeature/LocationFactory.t @@ -195,7 +195,6 @@ SKIP: { # join(1000..2000,join(3000..4000,join(5000..6000,7000..8000)),9000..10000) # is the same as # join(1000..2000,3000..4000,5000..6000,7000..8000,9000..10000) - # But I don't want to bother with it at this point my @expected = (# intentionally testing same expected string twice # as I am providing two different encodings @@ -206,7 +205,7 @@ SKIP: { 'join(20464..20694,21548..22763,complement(join(231520..231669,232596..232990,314652..314672)))', 'join(20464..20694,21548..22763,complement(join(231520..231669,232596..232990,314652..314672)))', # this is just seen once - 'join(1000..2000,join(3000..4000,join(5000..6000,7000..8000)),9000..10000)', + 'join(1000..2000,3000..4000,5000..6000,7000..8000,9000..10000)', 'order(S67862.1:72..75,join(S67863.1:1..788,1..19))' ); -- 2.11.4.GIT