private void truncateLabelsIfNecessary() { while ( calculateLabelLength() > AnnotatedObject.MAX_SHORT_LABEL_LEN ) { int baitLength = baitLabel.length(); int preyLength = ( preyLabel == null ) ? 0 : preyLabel.length(); if ( baitLength > preyLength ) { baitLabel = baitLabel.substring( 0, baitLabel.length() - 1 ); // truncate, remove last charachter (from bait) } else { if ( preyLabel != null ) { preyLabel = preyLabel.substring( 0, preyLabel.length() - 1 ); // truncate, remove last charachter (from prey) } } } // while }
boolean isSelfInteraction = isSelfInteraction( completeLabel );
public InteractionShortLabel(String baitLabel, String preyLabel, Integer suffix) { this.baitLabel = prepareLabel(baitLabel); this.preyLabel = prepareLabel(preyLabel); this.suffix = suffix; if (this.baitLabel.contains(INTERACTION_SEPARATOR)) { throw new IllegalArgumentException("Bait label cannot contain '" + INTERACTION_SEPARATOR + "': " + baitLabel); } if (this.preyLabel != null && preyLabel.contains(INTERACTION_SEPARATOR)) { throw new IllegalArgumentException("Prey label cannot contain '" + INTERACTION_SEPARATOR + "': " + preyLabel); } }
boolean isSelfInteraction = isSelfInteraction( completeLabel );
/** * Calculates the next available suffix using a short label - which is * the highest suffix + 1 * * @param shortLabel the label to use * * @return the next available suffix. */ protected static Integer calculateNextSuffix(String shortLabel) { String labelWithoutSuffix = removeSuffix(shortLabel); // we get all the labels with the same bait-prey combination List<String> shortLabelsWithSuffix = IntactContext.getCurrentInstance().getDataContext().getDaoFactory() .getInteractionDao().getShortLabelsLike(labelWithoutSuffix + "%"); int maxSuffix = -1; for (String labelWithSuffix : shortLabelsWithSuffix) { InteractionShortLabel label = new InteractionShortLabel(labelWithSuffix); Integer suffix = label.getSuffix(); if (suffix != null) { maxSuffix = Math.max(maxSuffix, suffix); } else { maxSuffix = 0; } } if (maxSuffix == -1) { return null; } return maxSuffix + 1; }
/** * Interactions follow the nomenclature baitLabel-preyLabel-suffix (where suffix is optional integer). * Self-interactions follow label-suffix (where suffix is optional integer). * @param completeLabel */ private void parse(String completeLabel) { if (!completeLabel.contains(INTERACTION_SEPARATOR)) { throw new IllegalArgumentException("This label is not an interaction label (does not contain '" + INTERACTION_SEPARATOR + "'): " + completeLabel); } String[] baitPrayLabels = completeLabel.split(INTERACTION_SEPARATOR); if (baitPrayLabels.length > 3) { throw new IllegalArgumentException("This label is not an interaction label (contain more than one '" + INTERACTION_SEPARATOR + "'): " + completeLabel); } // self interactions boolean isSelfInteraction = isSelfInteraction(completeLabel); this.baitLabel = baitPrayLabels[0]; if (!isSelfInteraction) { this.preyLabel = baitPrayLabels[1]; } else { this.suffix = Integer.valueOf(baitPrayLabels[1]); } if (baitPrayLabels.length == 3) { if (isSelfInteraction) { suffix = Integer.valueOf(baitPrayLabels[1]); } else { suffix = Integer.valueOf(baitPrayLabels[2]); } } }
/** * Calculates the next available suffix using a short label - which is * the highest suffix + 1 * * @param shortLabel the label to use * @return the next available suffix. */ protected static Integer calculateNextSuffix( String shortLabel ) { String labelWithoutSuffix = removeSuffix( shortLabel ); // we get all the labels with the same bait-prey combination List<String> shortLabelsWithSuffix = IntactContext.getCurrentInstance().getDataContext().getDaoFactory() .getInteractionDao().getShortLabelsLike( labelWithoutSuffix + "%" ); int maxSuffix = -1; for ( String labelWithSuffix : shortLabelsWithSuffix ) { InteractionShortLabel label = new InteractionShortLabel( labelWithSuffix ); Integer suffix = label.getSuffix(); if ( suffix != null ) { maxSuffix = Math.max( maxSuffix, suffix ); } else { maxSuffix = 0; } } if ( maxSuffix == -1 ) { return null; } return maxSuffix + 1; }
/** * Calculates the next available suffix using a short label - which is * the highest suffix + 1 * * @param shortLabel the label to use * @return the next available suffix. */ protected static Integer calculateNextSuffix( String shortLabel ) { String labelWithoutSuffix = removeSuffix( shortLabel ); // we get all the labels with the same bait-prey combination List<String> shortLabelsWithSuffix = IntactContext.getCurrentInstance().getDataContext().getDaoFactory() .getInteractionDao().getShortLabelsLike( labelWithoutSuffix + "%" ); int maxSuffix = -1; for ( String labelWithSuffix : shortLabelsWithSuffix ) { InteractionShortLabel label = new InteractionShortLabel( labelWithSuffix ); Integer suffix = label.getSuffix(); if ( suffix != null ) { maxSuffix = Math.max( maxSuffix, suffix ); } else { maxSuffix = 0; } } if ( maxSuffix == -1 ) { return null; } return maxSuffix + 1; }
public String getCompleteLabel( boolean includeSuffix ) { if (!isValid){ return this.originalLabel; } truncateLabelsIfNecessary(); String strPrey = ""; if ( preyLabel != null ) { //not a self-interaction strPrey = INTERACTION_SEPARATOR + preyLabel; } String strSuffix = ""; if ( includeSuffix && suffix != null ) { strSuffix = INTERACTION_SEPARATOR + suffix; } String complete = baitLabel + strPrey + strSuffix; return complete; }
/** * Gets the next available suffix for a provided shortLabel * * @param shortLabel Can already have a suffix or not. * @return The next available shortLabel */ public static String nextAvailableShortlabel( String shortLabel ) { Integer nextSuffix = calculateNextSuffix( shortLabel ); InteractionShortLabel label = new InteractionShortLabel( shortLabel ); if ( nextSuffix != null ) { label.setSuffix( nextSuffix ); } return label.getCompleteLabel(); }
public String getCompleteLabel() { return getCompleteLabel( true ); }
public InteractionShortLabel(String completeLabel) { parse(completeLabel); }
/** * Gets the next available suffix for a provided shortLabel * * @param shortLabel Can already have a suffix or not. * * @return The next available shortLabel */ public static String nextAvailableShortlabel(String shortLabel) { Integer nextSuffix = calculateNextSuffix(shortLabel); InteractionShortLabel label = new InteractionShortLabel(shortLabel); if (nextSuffix != null) { label.setSuffix(nextSuffix); } return label.getCompleteLabel(); }
public String getCompleteLabel(boolean includeSuffix) { truncateLabelsIfNecessary(); String strPrey = ""; if (preyLabel != null) { //not a self-interaction strPrey = INTERACTION_SEPARATOR + preyLabel; } String strSuffix = ""; if (includeSuffix && suffix != null) { strSuffix = INTERACTION_SEPARATOR + suffix; } String complete = baitLabel + strPrey + strSuffix; return complete; }
/** * Gets the next available suffix for a provided shortLabel * * @param shortLabel Can already have a suffix or not. * @return The next available shortLabel */ public static String nextAvailableShortlabel( String shortLabel ) { Integer nextSuffix = calculateNextSuffix( shortLabel ); InteractionShortLabel label = new InteractionShortLabel( shortLabel ); if ( nextSuffix != null ) { label.setSuffix( nextSuffix ); } return label.getCompleteLabel(); }
public String getCompleteLabel() { return getCompleteLabel(true); }
public String getCompleteLabel( boolean includeSuffix ) { if (!isValid){ return this.originalLabel; } truncateLabelsIfNecessary(); String strPrey = ""; if ( preyLabel != null ) { //not a self-interaction strPrey = INTERACTION_SEPARATOR + preyLabel; } String strSuffix = ""; if ( includeSuffix && suffix != null ) { strSuffix = INTERACTION_SEPARATOR + suffix; } String complete = baitLabel + strPrey + strSuffix; return complete; }
public String getCompleteLabel() { return getCompleteLabel( true ); }
private void truncateLabelsIfNecessary() { while (calculateLabelLength() > AnnotatedObject.MAX_SHORT_LABEL_LEN) { int baitLength = baitLabel.length(); int preyLength = (preyLabel == null)? 0 : preyLabel.length(); if (baitLength > preyLength) { baitLabel = baitLabel.substring(0, baitLabel.length() - 1); // truncate, remove last charachter (from bait) } else { if (preyLabel != null) { preyLabel = preyLabel.substring(0, preyLabel.length() - 1); // truncate, remove last charachter (from prey) } } } // while }
public InteractionShortLabel( String completeLabel ) { this.isValid = parse( completeLabel ); this.originalLabel = completeLabel; }