private static Collection<InteractorXref> extractCrossReferencesFrom(Protein protein, String databaseMiRef, String qualifierMiRef) { Collection<InteractorXref> parents = new ArrayList<InteractorXref>(); for (InteractorXref ref : protein.getXrefs()) { if (ref.getCvDatabase().getIdentifier().equals(databaseMiRef)) { if (ref.getCvXrefQualifier().getIdentifier().equals(qualifierMiRef)) { parents.add(ref); } } } return parents; }
/** * Add all the cross references with qualifier 'identity' to the list of identifiers of the protein (intact cross references are ignored) * @param refs : the refs of the protein * @param context : the context of the protein */ private void addIdentityCrossreferencesToContext(Collection<InteractorXref> refs, UpdateContext context){ for (InteractorXref ref : refs){ if (ref.getPrimaryId() != null){ if (ref.getCvXrefQualifier() != null){ CvXrefQualifier qualifier = ref.getCvXrefQualifier(); if (isIdentityCrossReference(qualifier)){ CvDatabase database = ref.getCvDatabase(); if (database != null){ if (database.getIdentifier() != null && !CvDatabase.INTACT_MI_REF.equals(database.getIdentifier())){ context.addIdentifier(database.getIdentifier(), ref.getPrimaryId()); } else if (database.getShortLabel() != null && !CvDatabase.INTACT.equals(database.getShortLabel())) { context.addIdentifier(database.getShortLabel(), ref.getPrimaryId()); } } } } } } }
/** * Check if two interactors contain the same identity xrefs, excluding the IMEx partner identities * * @param interactor1 * @param interactor2 * @return */ public static boolean containTheSameIdentities(Interactor interactor1, Interactor interactor2) { List<InteractorXref> identities1 = getIdentityXrefs(interactor1, true); List<InteractorXref> identities2 = getIdentityXrefs(interactor2, true); if (identities1.size() != identities2.size()) { return false; } Comparator<InteractorXref> identityXrefComparator = new Comparator<InteractorXref>() { public int compare(InteractorXref o1, InteractorXref o2) { return o1.getPrimaryId().compareTo(o2.getPrimaryId()); } }; Collections.sort(identities1, identityXrefComparator); Collections.sort(identities2, identityXrefComparator); for (int i = 0; i < identities1.size(); i++) { if (!(identities1.get(i).equals(identities2.get(i)))) { return false; } } return true; }
/** * Retreives Imex identifier stored in the Xrefs. * * @param interaction the interaction to search on. * @return an imex id or null if not found. */ public static String getImexIdentifier(Interaction interaction) { if (interaction == null) { throw new IllegalArgumentException("You must give a non null interaction"); } for (InteractorXref xref : interaction.getXrefs()) { if (CvDatabase.IMEX_MI_REF.equals(xref.getCvDatabase().getIdentifier())) { return xref.getPrimaryId(); } } // Could not find an IMEx id return null; }
private Collection<ProteinImpl> getProteinByXref(String primaryId, CvDatabase database, CvXrefQualifier qualifier) { XrefDao<InteractorXref> xrefDao = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getXrefDao(InteractorXref.class); Collection<InteractorXref> xrefs = xrefDao.getByPrimaryId(primaryId, false); Collection<ProteinImpl> proteins = new ArrayList<ProteinImpl>(); for (InteractorXref xref : xrefs) { if ((null != database && database.equals(xref.getCvDatabase())) || (null == database && null == xref.getCvDatabase())) { if ((null != qualifier && qualifier.equals(xref.getCvXrefQualifier())) || (null == qualifier && null == xref.getCvXrefQualifier())) { proteins.add((ProteinImpl) xref.getParent()); } } } return proteins; }
public int compare(InteractorXref o1, InteractorXref o2) { return o1.getPrimaryId().compareTo(o2.getPrimaryId()); } };
protected void fixSourceReferenceXrefsIfNecessary(Interaction interaction) { InteractorXref xrefToFix = null; if( ConverterContext.getInstance().isAutoFixInteractionSourceReference() ) { // Look up source reference xref and only try to fix identity if there is no source ref present. // if the qualifier is identity, we will check if the owner identity MI is the same as the database MI for (InteractorXref xref : interaction.getXrefs()) { if (xref.getCvXrefQualifier() != null && getInstitutionPrimaryId() != null && getInstitutionPrimaryId().equals( xref.getPrimaryId() ) && !CvXrefQualifier.SOURCE_REFERENCE_MI_REF.equals(xref.getCvXrefQualifier().getIdentifier())) { xrefToFix = xref; break; } } if ( xrefToFix != null ) { log.warn("Interaction identity xref found pointing to the source database. It should be of type 'source-reference'. Will be fixed automatically: "+xrefToFix); CvXrefQualifier sourceReference = CvObjectUtils.createCvObject(interaction.getOwner(), CvXrefQualifier.class, CvXrefQualifier.SOURCE_REFERENCE_MI_REF, CvXrefQualifier.SOURCE_REFERENCE); xrefToFix.setCvXrefQualifier(sourceReference); addMessageToContext(MessageLevel.WARN, "Interaction identity xref found pointing to the source database. It should be of type 'source-reference'. Fixed.", true); } } }
protected ProteinImpl getProteinTranscriptsMasterProtein( Protein proteinTranscript, String cvXRefQualifier) { if ( proteinTranscript == null ) { throw new NullPointerException( "proteinTranscript must not be null." ); } if ( cvXRefQualifier == null ) { throw new NullPointerException( "The Cv Xref qualifier must not be null." ); } String masterProtAc = null; for (InteractorXref xref : proteinTranscript.getXrefs()) { if (xref.getCvXrefQualifier() != null && cvXRefQualifier.equals(xref.getCvXrefQualifier().getIdentifier())) { if (masterProtAc == null) { masterProtAc = xref.getPrimaryId(); } else { throw new IntactException("This protein transcript contains more than one "+cvXRefQualifier+" xrefs: "+proteinTranscript.getShortLabel() ); } } } // search protein by AC return getByAc(masterProtAc); }
public Interaction createInteractionRandomBinary(String imexId) { CvInteractionType cvInteractionType = createCvObject(CvInteractionType.class, CvInteractionType.DIRECT_INTERACTION_MI_REF, CvInteractionType.DIRECT_INTERACTION); CvInteractorType intType = createCvObject(CvInteractorType.class, CvInteractorType.INTERACTION_MI_REF, CvInteractorType.INTERACTION ); Experiment experimentEmpty = createExperimentEmpty(); Interaction interaction = new InteractionImpl(new ArrayList<Experiment>(Arrays.asList(experimentEmpty)), cvInteractionType, intType, nextString("label"), getInstitution()); experimentEmpty.getInteractions().add(interaction); createComponentBait(interaction, createProteinRandom()); createComponentPrey(interaction, createProteinRandom()); String shortLabel = InteractionUtils.calculateShortLabel(interaction); interaction.setShortLabel(shortLabel); if (imexId != null) { CvObjectBuilder cvBuilder = new CvObjectBuilder(); CvXrefQualifier idQual = cvBuilder.createIdentityCvXrefQualifier(getInstitution()); CvDatabase imexDb = createCvObject(CvDatabase.class, CvDatabase.IMEX_MI_REF, CvDatabase.IMEX); interaction.addXref(new InteractorXref(getInstitution(), imexDb, imexId, idQual)); } return interaction; }
/** * Checks if the current protein is a chain * * @param protein the protein to check * @return true if the protein is a chain */ public static boolean isFeatureChain(Protein protein) { Collection<InteractorXref> xrefs = protein.getXrefs(); for (InteractorXref xref : xrefs) { if (xref.getCvXrefQualifier() != null) { String qualifierIdentity = xref.getCvXrefQualifier().getIdentifier(); if (CvXrefQualifier.CHAIN_PARENT_MI_REF.equals(qualifierIdentity)) { return true; } } } return false; }
public Collection<GeneralMessage> check( SmallMolecule smallMolecule ) throws SanityRuleException { Collection<GeneralMessage> messages = new ArrayList<GeneralMessage>(); final Collection<InteractorXref> identities = XrefUtils.getIdentityXrefs( smallMolecule ); switch( identities.size() ) { case 0: messages.add( new GeneralMessage( MessageDefinition.SMALL_MOLECULE_IDENTITY_MISSING, smallMolecule ) ); break; case 1: final InteractorXref xref = identities.iterator().next(); if ( ! CvObjectUtils.hasIdentity( xref.getCvDatabase(), CvDatabase.CHEBI_MI_REF ) ) { messages.add( new GeneralMessage(MessageDefinition.SMALL_MOLECULE_IDENTITY_INVALID_DB, smallMolecule ) ); } break; default: // more than 1 messages.add( new GeneralMessage( MessageDefinition.SMALL_MOLECULE_IDENTITY_MULTIPLE, smallMolecule ) ); } return messages; } }
public int compare(InteractorXref o1, InteractorXref o2) { return o1.getPrimaryId().compareTo(o2.getPrimaryId()); } };
/** * Retreives Imex identifier stored in the Xrefs. * * @param interaction the interaction to search on. * @return an imex id or null if not found. */ public static String getImexIdentifier(Interaction interaction) { if (interaction == null) { throw new IllegalArgumentException("You must give a non null interaction"); } for (InteractorXref xref : interaction.getXrefs()) { if (CvDatabase.IMEX_MI_REF.equals(xref.getCvDatabase().getIdentifier())) { return xref.getPrimaryId(); } } // Could not find an IMEx id return null; }
private Collection<ProteinImpl> getProteinByXref(String primaryId, CvDatabase database, CvXrefQualifier qualifier) { XrefDao<InteractorXref> xrefDao = IntactContext.getCurrentInstance().getDataContext().getDaoFactory().getXrefDao(InteractorXref.class); Collection<InteractorXref> xrefs = xrefDao.getByPrimaryId(primaryId, false); Collection<ProteinImpl> proteins = new ArrayList<ProteinImpl>(); for (InteractorXref xref : xrefs) { if ((null != database && database.equals(xref.getCvDatabase())) || (null == database && null == xref.getCvDatabase())) { if ((null != qualifier && qualifier.equals(xref.getCvXrefQualifier())) || (null == qualifier && null == xref.getCvXrefQualifier())) { proteins.add((ProteinImpl) xref.getParent()); } } } return proteins; }
protected ProteinImpl getProteinTranscriptsMasterProtein( Protein proteinTranscript, String cvXRefQualifier) { if ( proteinTranscript == null ) { throw new NullPointerException( "proteinTranscript must not be null." ); } if ( cvXRefQualifier == null ) { throw new NullPointerException( "The Cv Xref qualifier must not be null." ); } String masterProtAc = null; for (InteractorXref xref : proteinTranscript.getXrefs()) { if (xref.getCvXrefQualifier() != null && cvXRefQualifier.equals(xref.getCvXrefQualifier().getIdentifier())) { if (masterProtAc == null) { masterProtAc = xref.getPrimaryId(); } else { throw new IntactException("This protein transcript contains more than one "+cvXRefQualifier+" xrefs: "+proteinTranscript.getShortLabel() ); } } } // search protein by AC return getByAc(masterProtAc); }
public Interaction createInteractionRandomBinary(String imexId) { CvInteractionType cvInteractionType = createCvObject(CvInteractionType.class, CvInteractionType.DIRECT_INTERACTION_MI_REF, CvInteractionType.DIRECT_INTERACTION); CvInteractorType intType = createCvObject(CvInteractorType.class, CvInteractorType.INTERACTION_MI_REF, CvInteractorType.INTERACTION ); Experiment experimentEmpty = createExperimentEmpty(); Interaction interaction = new InteractionImpl(new ArrayList<Experiment>(Arrays.asList(experimentEmpty)), cvInteractionType, intType, nextString("label"), getInstitution()); experimentEmpty.getInteractions().add(interaction); createComponentBait(interaction, createProteinRandom()); createComponentPrey(interaction, createProteinRandom()); String shortLabel = InteractionUtils.calculateShortLabel(interaction); interaction.setShortLabel(shortLabel); if (imexId != null) { CvObjectBuilder cvBuilder = new CvObjectBuilder(); CvXrefQualifier idQual = cvBuilder.createIdentityCvXrefQualifier(getInstitution()); CvDatabase imexDb = createCvObject(CvDatabase.class, CvDatabase.IMEX_MI_REF, CvDatabase.IMEX); interaction.addXref(new InteractorXref(getInstitution(), imexDb, imexId, idQual)); } return interaction; }
/** * Checks if the current protein is a splice variant * * @param protein the protein to check * @return true if the protein is a splice variant */ public static boolean isSpliceVariant(Protein protein) { Collection<InteractorXref> xrefs = protein.getXrefs(); for (InteractorXref xref : xrefs) { if (xref.getCvXrefQualifier() != null) { String qualifierIdentity = xref.getCvXrefQualifier().getIdentifier(); if (CvXrefQualifier.ISOFORM_PARENT_MI_REF.equals(qualifierIdentity)) { return true; } } } return false; }
private static Collection<InteractorXref> extractCrossReferencesFrom(Protein protein, String databaseMiRef, String qualifierMiRef) { Collection<InteractorXref> parents = new ArrayList<InteractorXref>(); for (InteractorXref ref : protein.getXrefs()) { if (ref.getCvDatabase().getIdentifier().equals(databaseMiRef)) { if (ref.getCvXrefQualifier().getIdentifier().equals(qualifierMiRef)) { parents.add(ref); } } } return parents; }
/** * Get the uniprot primary ID from Protein and Splice variant. * * @param protein the Protein for which we want the uniprot ID. * * @return the uniprot ID as a String or null if none is found (should not occur) */ public String getUniprotPrimaryAc(final Protein protein) { if (protAcToUniprotIdCache.containsKey(protein.getAc())) { return protAcToUniprotIdCache.get(protein.getAc()); } String uniprotId = null; Collection<InteractorXref> xrefs = protein.getXrefs(); for (InteractorXref xref : xrefs) { if (getUniprot().equals(xref.getCvDatabase()) && getIdentity().equals(xref.getCvXrefQualifier())) { uniprotId = xref.getPrimaryId(); break; } } protAcToUniprotIdCache.put(protein.getAc(), uniprotId); return uniprotId; } }
public int compare(InteractorXref o1, InteractorXref o2) { return o1.getPrimaryId().toLowerCase().compareTo(o2.getPrimaryId().toLowerCase()); } });