Skip to content

Commit

Permalink
Converted more p5 code in LocationFactory. Uncommented a few more tes…
Browse files Browse the repository at this point in the history
…ts that now pass and Strand for Split now returns Any instead of Mu when no strand can be found.
  • Loading branch information
Takadonet committed Mar 27, 2011
1 parent b4acd69 commit 52f2d17
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
22 changes: 13 additions & 9 deletions lib/Bio/Factory/FTLocationFactory.pm
Expand Up @@ -26,6 +26,10 @@ method from_string($locstr is copy ,$op?) {
# convert ABC123:(X..Y) to ABC123:[X..Y]
# we should never see the above
# $locstr =~ s{:\((\d+\.{2}\d+)\)}{:\[$1\]}g;
while ($locstr ~~ / \: \( (\d+ \. ** 2 \d+) \)/ ) {
$locstr ~~ s/ \: \( (\d+ \. ** 2 \d+) \) /\:\[$0\]/;
}

}

# if ($locstr =~ m{(.*?)\(($LOCREG)\)(.*)}o) { # any matching parentheses?
Expand All @@ -52,7 +56,6 @@ method from_string($locstr is copy ,$op?) {

# && $sub !~~ m{(?:join|order|bond)}) {
my @splitlocs = split(',' , $sub);


$loc_obj = Bio::Role::Location::Split.new(#verbose => 1,
splittype => $oparg);
Expand Down Expand Up @@ -109,15 +112,15 @@ method from_string($locstr is copy ,$op?) {



method !parse_location($locstr) {
method !parse_location($locstr is copy) {
my ($loc, $seqid);
#self.debug( "Location parse, processing $locstr\n");
# 'remote' location?
# if($locstr =~ m{^(\S+):(.*)$}o) {
# # yes; memorize remote ID and strip from location string
# $seqid = $1;
# $locstr = $2;
# }
if ($locstr ~~ /^(\S+)\:(.*)$/) {
# yes; memorize remote ID and strip from location string
$seqid = $0;
$locstr = $1;
}

# split into start and end
my ($start, $end) = split(/\.\./, $locstr);
Expand All @@ -126,7 +129,10 @@ method !parse_location($locstr) {
# possibly surrounding the entire location the parentheses around start
# and/or may be asymmetrical
# Note: these are from X.Y fuzzy locations, which are deprecated!

# $start =~ s/(?:^\[+|\]+$)//g if $start;
$start ~~ s/^\[+|\]+// if $start;
$end ~~ s/^\[+|\]+// if $end;
# $end =~ s/(?:^\[+|\]+$)//g if $end;

# Is this a simple (exact) or a fuzzy location? Simples have exact start
Expand Down Expand Up @@ -167,8 +173,6 @@ method !parse_location($locstr) {
if ( $start_num > $end_num && $loctype ne '?') {
($start,$end,$strand) = ($end,$start,-1);
}


# instantiate location and initialize
$loc = $locclass.new(#verbose => self.verbose,
start => $start,
Expand Down
2 changes: 1 addition & 1 deletion lib/Bio/Role/Location/Split.pm
Expand Up @@ -213,7 +213,7 @@ multi method strand($value?) {
if ((! $lstrand) ||
($strand && ($strand != $lstrand)) ||
$loc.is_remote()) {
$strand = Mu;
$strand = Any;
last;
} elsif (! $strand) {
$strand = $lstrand;
Expand Down
17 changes: 9 additions & 8 deletions t/Factory/FTLocationFactory.t
Expand Up @@ -48,16 +48,16 @@ my %testcases = (
# 2691, 2691, "EXACT", 5163, 5163, "EXACT", "EXACT", 2, -1],
# "complement(34..(122.126))" => [$fuzzy_impl,
# 34, 34, "EXACT", 122, 126, "WITHIN", "EXACT", 1, -1],
# "J00194:100..202" => [$simple_impl,
# 100, 100, "EXACT", 202, 202, "EXACT", "EXACT", 1, 1],
"J00194:100..202" => [$simple_impl,
100, 100, "EXACT", 202, 202, "EXACT", "EXACT", 1, 1],
# # this variant is not really allowed by the FT definition
# # document but we want to be able to cope with it
# "J00194:(100..202)" => [$simple_impl,
# 100, 100, "EXACT", 202, 202, "EXACT", "EXACT", 1, 1],
"J00194:(100..202)" => [$simple_impl,
100, 100, "EXACT", 202, 202, "EXACT", "EXACT", 1, 1],
# "((122.133)..(204.221))" => [$fuzzy_impl,
# 122, 133, "WITHIN", 204, 221, "WITHIN", "EXACT", 1, 1],
# "join(AY016290.1:108..185,AY016291.1:1546..1599)"=> [$split_impl,
# 108, 108, "EXACT", 185, 185, "EXACT", "EXACT", 2, undef],
"join(AY016290.1:108..185,AY016291.1:1546..1599)"=> [$split_impl,
108, 108, "EXACT", 185, 185, "EXACT", "EXACT", 2, Any],

# # UNCERTAIN locations and positions (Swissprot)
# "?2465..2774" => [$fuzzy_impl,
Expand Down Expand Up @@ -85,10 +85,10 @@ my $locfac = Bio::Factory::FTLocationFactory.new();
ok($locfac ~~ Bio::Factory::FTLocationFactory, 'Is Bio::Location::FTLocationFactory Role');

# sorting is to keep the order constant from one run to the next
for keys %testcases -> $locstr {
for keys %testcases -> $locstr is copy {
my $loc = $locfac.from_string($locstr);
if ($locstr eq "join(AY016290.1:108..185,AY016291.1:1546..1599)") {
$loc.seq_id("AY016295.1");
$loc.seq_id ="AY016295.1";
}
my @res = @(%testcases{$locstr});
is($loc.WHAT, @res[0], @res[0]);
Expand All @@ -111,6 +111,7 @@ for keys %testcases -> $locstr {
is($ftstr, $locstr, "Location String: $locstr");
# test strand production
is($loc.strand(), @res[9]);

}

# SKIP: {
Expand Down

0 comments on commit 52f2d17

Please sign in to comment.