/** * Creates a candiate short label - not taking into account if an interaction with the same name exists in the database * * @param baitShortLabel bait gene name * @param preyShortLabel prey gene name * @return the short label */ protected static String createCandidateShortLabel( String baitShortLabel, String preyShortLabel ) { return createCandidateShortLabel( baitShortLabel, preyShortLabel, null ); }
return getLabel(components.get(0)); } else if (components.size() > 1) { String shortLabel1 = getLabel(components.get(0)); String shortLabel2 = getLabel(components.get(1)); return createCandidateShortLabel( shortLabel1, shortLabel2 );
baitShortlabel = getLabelFromCollection(baits, true); // fail on error preyShortlabel = getLabelFromCollection(preys, false); // don't fail on error if (preyShortlabel == null) { preyShortlabel = getLabelFromCollection(neutrals, true); // fail on error String candidateShortLabel = createCandidateShortLabel(baitShortlabel, preyShortlabel);
/** * 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(); }
/** * Syncs a short label with the database, checking that there are no duplicates and that the correct suffix is added. * <p/> * Concurrency note: just after getting the new short label, it is recommended to persist/update the interaction immediately * in the database - so this method should ONLY be used before saving the interaction to the database. In some * race conditions, two interactions could be created with the same id; currently there is no way to * reserve a short label * * @param shortLabel the short label to sync * @return the synced short label * @see uk.ac.ebi.intact.model.util.InteractionShortLabelGenerator * @since 1.6 */ public static String syncShortLabelWithDb( String shortLabel ) { if (isTemporaryLabel(shortLabel)) { if (log.isWarnEnabled()) log.warn("Label for interaction was temporary ("+shortLabel+"), hence not synced with the database"); return shortLabel; } return InteractionShortLabelGenerator.nextAvailableShortlabel( shortLabel ); }
/** * 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; }
return getLabel(components.get(0)); } else if (components.size() > 1) { String shortLabel1 = getLabel(components.get(0)); String shortLabel2 = getLabel(components.get(1)); return createCandidateShortLabel( shortLabel1, shortLabel2 );
/** * 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(); }
/** * Syncs a short label with the database, checking that there are no duplicates and that the correct suffix is added. * <p/> * Concurrency note: just after getting the new short label, it is recommended to persist/update the interaction immediately * in the database - so this method should ONLY be used before saving the interaction to the database. In some * race conditions, two interactions could be created with the same id; currently there is no way to * reserve a short label * * @param shortLabel the short label to sync * @return the synced short label * @see uk.ac.ebi.intact.model.util.InteractionShortLabelGenerator * @since 1.6 */ public static String syncShortLabelWithDb(String shortLabel) { if (isTemporaryLabel(shortLabel)) { if (log.isDebugEnabled()) log.debug("Label for interaction was temporary (" + shortLabel + "), hence not synced with the database"); return shortLabel; } return InteractionShortLabelGenerator.nextAvailableShortlabel(shortLabel); }
/** * 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; }
/** * Creates a candiate short label - not taking into account if an interaction with the same name exists in the database * * @param baitShortLabel bait gene name * @param preyShortLabel prey gene name * * @return the short label */ protected static String createCandidateShortLabel(String baitShortLabel, String preyShortLabel) { return createCandidateShortLabel(baitShortLabel, preyShortLabel, null); }
/** * 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(); }
/** * Syncs a short label with the database, checking that there are no duplicates and that the correct suffix is added. * <p/> * Concurrency note: just after getting the new short label, it is recommended to persist/update the interaction immediately * in the database - so this method should ONLY be used before saving the interaction to the database. In some * race conditions, two interactions could be created with the same id; currently there is no way to * reserve a short label * * @param shortLabel the short label to sync * @return the synced short label * @see uk.ac.ebi.intact.model.util.InteractionShortLabelGenerator * @since 1.6 */ public static String syncShortLabelWithDb(String shortLabel) { if (isTemporaryLabel(shortLabel)) { if (log.isDebugEnabled()) log.debug("Label for interaction was temporary (" + shortLabel + "), hence not synced with the database"); return shortLabel; } return InteractionShortLabelGenerator.nextAvailableShortlabel(shortLabel); }
/** * 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; }
/** * Creates a candiate short label - not taking into account if an interaction with the same name exists in the database * * @param baitShortLabel bait gene name * @param preyShortLabel prey gene name * @return the short label */ protected static String createCandidateShortLabel( String baitShortLabel, String preyShortLabel ) { return createCandidateShortLabel( baitShortLabel, preyShortLabel, null ); }
/** * Creates a shortLabel based on the participants of an interaction - NOT in sync with the database * (when interactions are persisted the short label needs to be in sync with the database. If there are * existing interactions with the same participants, the short label would be the same, so a prefix * with a number should be added) * * @param interaction the interaction used to calculate the shortlabel * @return the short label * @see uk.ac.ebi.intact.model.util.InteractionShortLabelGenerator * @since 1.6 */ public static String calculateShortLabel( final Interaction interaction ) { return InteractionShortLabelGenerator.createCandidateShortLabel( interaction ); }
/** * Creates a shortLabel based on the participants of an interaction - NOT in sync with the database * (when interactions are persisted the short label needs to be in sync with the database. If there are * existing interactions with the same participants, the short label would be the same, so a prefix * with a number should be added) * * @param interaction the interaction used to calculate the shortlabel * @return the short label * @see uk.ac.ebi.intact.model.util.InteractionShortLabelGenerator * @since 1.6 */ public static String calculateShortLabel(final Interaction interaction) { return InteractionShortLabelGenerator.createCandidateShortLabel(interaction); }
/** * Creates a shortLabel based on the participants of an interaction - NOT in sync with the database * (when interactions are persisted the short label needs to be in sync with the database. If there are * existing interactions with the same participants, the short label would be the same, so a prefix * with a number should be added) * * @param interaction the interaction used to calculate the shortlabel * @return the short label * @see uk.ac.ebi.intact.model.util.InteractionShortLabelGenerator * @since 1.6 */ public static String calculateShortLabel(final Interaction interaction) { return InteractionShortLabelGenerator.createCandidateShortLabel(interaction); }