From 5b1cd3ad87ab2764d2929e4e888e2d2d7dc38ce2 Mon Sep 17 00:00:00 2001 From: tcarver <tjc> Date: Thu, 26 Jul 2012 16:28:02 +0100 Subject: [PATCH] add isPartial() --- uk/ac/sanger/artemis/io/Location.java | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/uk/ac/sanger/artemis/io/Location.java b/uk/ac/sanger/artemis/io/Location.java index e3ac9925d..b479348b8 100644 --- a/uk/ac/sanger/artemis/io/Location.java +++ b/uk/ac/sanger/artemis/io/Location.java @@ -204,6 +204,52 @@ public class Location return true; } + /** + * If lookAt5prime is set to true then only return true if the 5' end is + * partial otherwise only return true if the 3' end is partial. + * @param lookAt5prime + * @return + */ + public boolean isPartial(final boolean lookAt5prime) + { + try + { + LocationParseNode top = getParsedLocation(); + if (top.getType() == LocationParseNode.COMPLEMENT) + top = top.getComplementChild(); + + if (top.getType() == LocationParseNode.JOIN || + top.getType() == LocationParseNode.ORDER) + { + LocationParseNodeVector nodes = top.getChildren(); + LocationParseNode node = nodes.elementAt( + (lookAt5prime ? 0 : nodes.size()-1)); + if (node.getType() == LocationParseNode.COMPLEMENT) + { + node = node.getComplementChild(); + if (node.getType() == LocationParseNode.RANGE + && node.getRange() instanceof FuzzyRange) + top = node; + } + else + top = nodes.elementAt(0); + } + + if (top.getType() == LocationParseNode.RANGE && + top.getRange() instanceof FuzzyRange) + { + final FuzzyRange fuzz = (FuzzyRange) top.getRange(); + if (fuzz.getStartObject() instanceof LowerInteger && (isComplement() ^ lookAt5prime)) + return true; + if (fuzz.getEndObject() instanceof UpperInteger && !(isComplement() ^ lookAt5prime)) + return true; + } + } + catch (Exception e){} + return false; + } + + /** * Returns the value of this Location as a string with the complement (if * any) as the top node and the join or order (if any) below it. -- GitLab