/** * Return the proper instance of the interactor if the database is recognized (the interactor will be returned on the first database which is recognized). It returns null otherwise. * @param xrefs : identifiers * @param name : name * @return the proper instance of the interactor if the database is recognized (the interactor will be returned on the first database which is recognized). It returns null otherwise. */ public Interactor createInteractorFromIdentityXrefs(Collection<? extends Xref> xrefs, String name){ Interactor interactor = null; Iterator<? extends Xref> xrefsIterator = xrefs.iterator(); while (interactor == null && xrefsIterator.hasNext()){ interactor = createInteractorFromDatabase(xrefsIterator.next().getDatabase(), name); } return interactor; }
private String buildDbList( Collection<Xref> identities ) { StringBuilder sb = new StringBuilder( 128 ); for ( Iterator<Xref> dbReferenceIterator = identities.iterator(); dbReferenceIterator.hasNext(); ) { Xref ref = dbReferenceIterator.next(); final String db = ref.getDatabase().getShortName(); final String dbAc = ref.getDatabase().getMIIdentifier(); if( db != null && db.length() > 0 ) { sb.append( db ).append(" ,"); } else if( dbAc != null && dbAc.length() > 0 ) { sb.append( dbAc ).append(" ,"); } } int length = sb.length(); if( length > 0 ) { length = length - 2; // gets rid of the last comma } return sb.substring( 0, length ); }
/** * Collect all Xrefs having specific databases * @param xrefs * @param dbMiRefs * @param dbRefs * @return */ public static Collection<Xref> searchAllXrefsHavingDatabases(Collection<Xref> xrefs, Collection<String> dbMiRefs, Collection<String> dbRefs) { if (xrefs == null || xrefs.isEmpty() || (dbMiRefs.isEmpty() && dbRefs.isEmpty())){ return Collections.EMPTY_LIST; } Collection<Xref> refs = new ArrayList<Xref>(xrefs.size()); for ( Xref ref : xrefs ) { if (ref.getDatabase().getMIIdentifier() != null && !dbMiRefs.isEmpty()) { if (!dbMiRefs.contains( ref.getDatabase().getMIIdentifier() )){ continue; } } else if (!dbRefs.contains( ref.getDatabase().getShortName() )){ continue; } refs.add( ref ); } return refs; }
/** * Method to know if a Xref is from the same database (dbId is the MI identifier and dbName is the database shortname) * @param ref : the Xref * @param dbId : the database MI identifier * @param dbName : the database shortname * @return true if the Xref has a database MI which is dbId or database shortname which is dbName */ public static boolean isXrefFromDatabase(Xref ref, String dbId, String dbName){ if (ref == null || (dbName == null && dbId == null)){ return false; } CvTerm database = ref.getDatabase(); // we can compare identifiers if (dbId != null && database.getMIIdentifier() != null){ // we have the same database id return database.getMIIdentifier().equals(dbId); } // we need to compare dbNames else if (dbName != null) { return dbName.equalsIgnoreCase(database.getShortName()); } return false; }
if (xRef.getDatabase() != null){ String dbAc = xRef.getDatabase().getMIIdentifier();
public void writeIdentifier(Xref identifier) throws IOException { if (identifier != null){ // write db first escapeAndWriteString(identifier.getDatabase().getShortName()); // write xref separator writer.write(MitabUtils.XREF_SEPARATOR); // write id escapeAndWriteString(identifier.getId()); // write version if (identifier.getVersion() != null){ writer.write(identifier.getVersion()); } } }
CvTerm database = ref.getDatabase();
protected IdentificationResults identifyProtein( Xref xrefToMap, IdentificationContext context) throws BridgeFailedException { String value = xrefToMap.getId(); String database = null; String databaseName = null; //Find a way to identify the database if(xrefToMap.getDatabase() != null){ database = xrefToMap.getDatabase().getMIIdentifier(); databaseName = xrefToMap.getDatabase().getShortName(); } //If there's an identity do a search - else return an empty result. if((database != null || databaseName != null) && value != null){ context.setSequence(null); context.setDatabaseForIdentifier(database); context.setDatabaseName(databaseName); context.setIdentifier(value); try{ return strategyWithIdentifier.identifyProtein(context); }catch(StrategyException e){ throw new BridgeFailedException("Failure while attempting to Map protein identifier.",e); } } return null; }
/** * For each cross reference of this XrefContainer, collects all respective cross reference type(s) and * check if the dependencies are correct. * * @param container to check on. * @return a collection of validator messages. * if we fail to retreive the MI Ontology. */ public Collection<ValidatorMessage> check( Experiment container) throws ValidatorException { Collection<ValidatorMessage> messages = Collections.EMPTY_LIST; // Collect the db references Collection<Xref> databaseReferences = container.getXrefs(); if (!databaseReferences.isEmpty()){ messages = new ArrayList<ValidatorMessage>(); for ( Xref reference : databaseReferences) { MiContext context = RuleUtils.buildContext(reference, "database cross reference"); context.addAssociatedContext(RuleUtils.buildContext(container, "experiment")); // build a context in case of error messages.addAll( mapping.check( reference.getDatabase(), reference.getQualifier(), context, this ) ); } } return messages; }
@Override protected IdentificationResults identifyProtein( Xref xrefToMap, IdentificationContext context) throws BridgeFailedException { String value = xrefToMap.getId(); String database = null; String databaseName = null; //Find a way to identify the database if(xrefToMap.getDatabase() != null){ database = xrefToMap.getDatabase().getMIIdentifier(); databaseName = xrefToMap.getDatabase().getShortName(); } //If there's an identity do a search - else return an empty result. if((database != null || databaseName != null) && value != null){ String key = "IDENTIFY_XREF_DB_"+(database != null ? database : databaseName)+"_"+value+(context.getOrganism() != null ? context.getOrganism().getTaxId() : ""); Object o = getFromCache(key); if (o != null){ return (IdentificationResults)o; } IdentificationResults res = super.identifyProtein(xrefToMap, context); storeInCache(key, res); return res; } return null; }
/** * * @param ref * @param interactor * @return an array of String : first the database, then the interactorId */ public static String[] extractInteractorId(Xref ref, Interactor interactor){ String interactorId = null; String db = null; if (ref != null){ interactorId = JSONValue.escape(ref.getId()); db = JSONValue.escape(ref.getDatabase().getShortName()); } else{ interactorId = Integer.toString(UnambiguousExactInteractorBaseComparator.hashCode(interactor)); db = "generated"; } return new String[]{db, interactorId}; }
/** * * @param ref * @param interaction * @return an array of String : first the database, then the interactionId */ public static String[] extractInteractionId(Xref ref, Interaction interaction){ String interactorId = null; String db = null; if (ref != null){ interactorId = JSONValue.escape(ref.getId()); db = JSONValue.escape(ref.getDatabase().getShortName()); } else if (interaction instanceof InteractionEvidence && ((InteractionEvidence)interaction).getImexId() != null){ interactorId = ((InteractionEvidence)interaction).getImexId(); db = "imex"; } else{ interactorId = Integer.toString(interaction.hashCode()); db = "generated"; } return new String[]{db, interactorId}; }
/** * * @param ref * @param interaction * @param number a suffix * @return an array of String : first the database, then the interactionId, then a number to append */ public static String[] extractBinaryInteractionId(Xref ref, BinaryInteraction interaction, Integer number){ String interactorId = null; String db = null; if (ref != null){ interactorId = JSONValue.escape(ref.getId())+(number != null ? "_"+number:""); db = JSONValue.escape(ref.getDatabase().getShortName()); } else if (interaction instanceof InteractionEvidence && ((InteractionEvidence)interaction).getImexId() != null){ interactorId = ((InteractionEvidence)interaction).getImexId()+(number != null ? "_"+number:""); db = "imex"; } else{ interactorId = Integer.toString(interaction.hashCode())+(number != null ? "_"+number:""); db = "generated"; } return new String[]{db, interactorId}; } }
/** * For each cross reference of this XrefContainer, collects all respective cross reference type(s) and * check if the dependencies are correct. * * @param container to check on. * @return a collection of validator messages. * if we fail to retreive the MI Ontology. */ public Collection<ValidatorMessage> check( Interaction container) throws ValidatorException { Collection<ValidatorMessage> messages = new ArrayList<ValidatorMessage>(); // Collect the db references Collection<Xref> databaseReferences = container.getXrefs(); for ( Xref reference : databaseReferences) { MiContext context = RuleUtils.buildContext(reference, "database xref"); context.addAssociatedContext(RuleUtils.buildContext(container, "interaction")); // build a context in case of error messages.addAll( mapping.check( reference.getDatabase(), reference.getQualifier(), context, this ) ); } // Collect the identifiers Collection<Xref> identifiers = container.getIdentifiers(); for ( Xref reference : identifiers) { MiContext context = RuleUtils.buildContext(reference, "database xref"); context.addAssociatedContext(RuleUtils.buildContext(container, "interaction")); // build a context in case of error messages.addAll( mapping.check( reference.getDatabase(), reference.getQualifier(), context, this ) ); } return messages; }
/** * For each cross reference of this XrefContainer, collects all respective cross reference type(s) and * check if the dependencies are correct. * * @param container to check on. * @return a collection of validator messages. * if we fail to retreive the MI Ontology. */ public Collection<ValidatorMessage> check( Feature container) throws ValidatorException { Collection<ValidatorMessage> messages = new ArrayList<ValidatorMessage>(); // Collect the identifiers Collection<Xref> identifiers = container.getIdentifiers(); for ( Xref reference : identifiers) { MiContext context = RuleUtils.buildContext(reference, "database xref"); context.addAssociatedContext(RuleUtils.buildContext(container, "feature")); // build a context in case of error messages.addAll( mapping.check( reference.getDatabase(), reference.getQualifier(), context, this ) ); } // Collect the db references Collection<Xref> databaseReferences = container.getXrefs(); for ( Xref reference : databaseReferences) { MiContext context = RuleUtils.buildContext(reference, "database xref"); context.addAssociatedContext(RuleUtils.buildContext(container, "feature")); // build a context in case of error messages.addAll( mapping.check( reference.getDatabase(), reference.getQualifier(), context, this ) ); } return messages; }
messages.addAll( mapping.check( reference.getDatabase(), reference.getQualifier(), context, this ) ); messages.addAll( mapping.check( reference.getDatabase(), reference.getQualifier(), context, this ) );
protected void processInteractorPool(Collection<MitabXref> xref, InteractorPool interactor) { InteractorPool pool = (InteractorPool)interactor; for (Xref ref : xref){ // we have a component of the interactor pool if (XrefUtils.doesXrefHaveQualifier(ref, Xref.INTERACTOR_SET_QUALIFIER_MI, Xref.INTERACTOR_SET_QUALIFIER)){ Interactor subInteractor = interactorFactory.createInteractorFromDatabase(ref.getDatabase(), ref.getId().toLowerCase()); if (subInteractor != null){ subInteractor.getIdentifiers().add(new MitabXref(ref.getDatabase(), ref.getId(), ref.getVersion(), CvTermUtils.createIdentityQualifier())); ((MitabInteractor)subInteractor).setSourceLocator(((MitabXref)ref).getSourceLocator()); } // create a default interactor else{ subInteractor = interactorFactory.createInteractor(ref.getId().toLowerCase(), CvTermUtils.createUnknownInteractorType()); subInteractor.getIdentifiers().add(new MitabXref(ref.getDatabase(), ref.getId(), ref.getVersion(), CvTermUtils.createIdentityQualifier())); ((MitabInteractor)subInteractor).setSourceLocator(((MitabXref)ref).getSourceLocator()); } // add the component to the interactor pool pool.add(subInteractor); } // we have a simple xref else{ pool.getXrefs().add(ref); } } }
for (Xref id : p.getIdentifiers()){ if (DefaultCvTermComparator.areEquals(id.getDatabase(), newId.getDatabase())){ refIterator.remove();
public void write(Xref object) throws IOException { MIJsonUtils.writeStartObject(writer); MIJsonUtils.writeProperty("db", JSONValue.escape(object.getDatabase().getShortName()), writer); MIJsonUtils.writeSeparator(writer); MIJsonUtils.writeProperty("id", JSONValue.escape(object.getId()), writer); MIJsonUtils.writeEndObject(writer); } }
if (pubId == null && !intactPublication.getIdentifiers().isEmpty()){ Xref id = intactPublication.getXrefs().iterator().next(); source = id.getDatabase().getShortName(); pubId = id.getId();