private long getMinRangeLength(psidev.psi.mi.jami.model.Range range, boolean isStartDefined, boolean isEndDefined){ long startPos = 0; long endPos = 0; if (isStartDefined){ startPos = range.getStart().getEnd(); } if (isEndDefined) { endPos = range.getEnd().getStart(); } if (PositionUtils.isLessThan(range.getStart())){ startPos = Math.max(1, startPos - 1); } else if (PositionUtils.isGreaterThan(range.getStart())){ startPos = Math.min(startPos + 1, endPos); } if (PositionUtils.isLessThan(range.getEnd())){ endPos = Math.max(endPos - 1, startPos); } else if (PositionUtils.isGreaterThan(range.getEnd())){ endPos = endPos + 1; } return endPos - startPos + 1; }
private long getMaxRangeLength(psidev.psi.mi.jami.model.Range range, boolean isStartDefined, boolean isEndDefined){ long startPos = 0; long endPos = 0; if (isStartDefined){ startPos = range.getStart().getStart(); } if (isEndDefined) { endPos = range.getEnd().getEnd(); } if (PositionUtils.isLessThan(range.getStart())){ startPos = Math.max(startPos - 1, 1); } else if (PositionUtils.isGreaterThan(range.getStart())){ startPos = Math.min(startPos + 1, endPos); } if (PositionUtils.isLessThan(range.getEnd())){ endPos = Math.max(endPos - 1, startPos); } else if (PositionUtils.isGreaterThan(range.getEnd())){ endPos = endPos + 1; } return endPos - startPos + 1; }
/** * Converts a range in a String. * Undetermined position is represented with ? * N-terminal range is represented with n * C-terminal range is represented with c * fuzzy ranges are represented with x1..x2 * @param range * @return */ public static String convertRangeToString(Range range){ if (range == null){ return null; } String pos1 = PositionUtils.convertPositionToString(range.getStart()); String pos2 = PositionUtils.convertPositionToString(range.getEnd()); return pos1+Range.POSITION_SEPARATOR+pos2; }
/** * All properties are copied from source to target excepted the participant * @param source * @param target */ public static void copyAndOverrideRangeProperties(Range source, Range target){ if (source != null && target != null){ target.setPositions(source.getStart(), source.getEnd()); target.setLink(source.isLink()); target.setResultingSequence(source.getResultingSequence()); } }
/** * * @param range * @return the hashcode consistent with the equals method for this comparator */ public static int hashCode(Range range){ if (unambiguousRangeComparator == null){ unambiguousRangeComparator = new UnambiguousRangeComparator(); } if (range == null){ return 0; } int hashcode = 31; Position start = range.getStart(); hashcode = 31*hashcode + UnambiguousPositionComparator.hashCode(start); Position end = range.getEnd(); hashcode = 31*hashcode + UnambiguousPositionComparator.hashCode(end); hashcode = 31 * hashcode + (range.isLink() ? 0 : 1); return hashcode; } }
/** * Method to check if the range is valid or not. If the range is valid, the method returns null otherwise it returns a message. * @param range : the range to check * @param sequence : the sequence of the polymer * @return empty list if the range is within the sequence, coherent with its fuzzy type and not overlapping. If the range is not valid, it will return a list of error messages describing why the range is invalid */ public static List<String> validateRange(Range range, String sequence){ if (range != null) { Position start = range.getStart(); Position end = range.getEnd(); List<String> messages = PositionUtils.validateRangePosition(start, sequence); messages.addAll(PositionUtils.validateRangePosition(end, sequence)); if (areRangeStatusInconsistent(range)){ messages.add("The start status "+start.getStatus().getShortName() +" and end status "+end.getStatus().getShortName()+" are inconsistent"); } if (areRangePositionsOverlapping(range)){ messages.add("The range positions overlap : ("+start.getStart()+"-"+start.getEnd()+") - ("+end.getStart()+"-"+end.getEnd()+")"); } return messages; } return Collections.EMPTY_LIST; }
Position pos1 = range.getStart(); Position pos2 = range.getEnd();
/** * For each participants of the interaction, collect all respective feature types and feature range status and * check if the dependencies are correct. * * @param feature to check on. * @return a collection of validator messages. * if we fail to retreive the MI Ontology. */ public Collection<ValidatorMessage> check( Feature feature) throws ValidatorException { Collection<ValidatorMessage> messages = Collections.EMPTY_LIST; if (feature.getType() != null){ Collection<Range> featureRange = feature.getRanges(); CvTerm featureType = feature.getType(); messages = new ArrayList<ValidatorMessage>(); if (!feature.getRanges().isEmpty()){ for (Range r : featureRange){ // build a context in case of error MiContext context = RuleUtils.buildContext(feature, "feature"); context.addAssociatedContext(RuleUtils.buildContext(featureType, "feature type")); context.addAssociatedContext(RuleUtils.buildContext(r, "feature range")); CvTerm startStatus = r.getStart().getStatus(); CvTerm endStatus = r.getEnd().getStatus(); messages.addAll( mapping.check( featureType, startStatus, context, this ) ); messages.addAll( mapping.check( featureType, endStatus, context, this ) ); } } } return messages; }
/** * * @param range * @return the hashcode consistent with the equals method for this comparator */ public static int hashCode(Range range){ if (unambiguousRangeAndResultingSequenceComparator == null){ unambiguousRangeAndResultingSequenceComparator = new UnambiguousRangeAndResultingSequenceComparator(); } if (range == null){ return 0; } int hashcode = 31; Position start = range.getStart(); hashcode = 31*hashcode + UnambiguousPositionComparator.hashCode(start); Position end = range.getEnd(); hashcode = 31*hashcode + UnambiguousPositionComparator.hashCode(end); hashcode = 31 * hashcode + (range.isLink() ? 0 : 1); ResultingSequence resultingSequence = range.getResultingSequence(); hashcode = 31 * hashcode + ResultingSequenceComparator.hashCode(resultingSequence); return hashcode; } }
boolean isEndDefined = true; if (range.getStart().isPositionUndetermined()){ isStartDefined = false;
/** * * @param range : the range to check * @return true if the range status are inconsistent (n-terminal is the end, c-terminal is the beginning) */ public static boolean areRangeStatusInconsistent(Range range){ Position start = range.getStart(); Position end = range.getEnd(); // the start position is C-terminal but the end position is different from C-terminal if (PositionUtils.isCTerminal(start) && !PositionUtils.isCTerminal(end)){ return true; } // the end position is N-terminal but the start position is different from N-terminal else if (PositionUtils.isNTerminal(end) && !PositionUtils.isNTerminal(start)){ return true; } else if (PositionUtils.isCTerminalRange(start) && !(PositionUtils.isCTerminal(end) || PositionUtils.isCTerminalRange(end))){ return true; } else if (PositionUtils.isNTerminalRange(end) && !(PositionUtils.isNTerminal(start) || PositionUtils.isNTerminalRange(start))){ return true; } return false; }
checkCv(messages, range.getStart().getStatus(), f, "feature"); checkCv(messages, range.getEnd().getStatus(), f, "feature");
Position start = range.getStart(); Position end = range.getEnd(); long fromStart = start.getStart();