private Query createGetByInteractorTypeQuery(String cvIdentifer, boolean includeChildren, boolean isCount) { List<String> cvIdentifiers = new ArrayList<String>(); cvIdentifiers.add(cvIdentifer); if (includeChildren) { CvObjectDao<CvInteractorType> cvObjectDao = IntactContext.getCurrentInstance().getDaoFactory() .getCvObjectDao(CvInteractorType.class); CvDagObject cvInteractorType = cvObjectDao.getByPsiMiRef(cvIdentifer); if (cvInteractorType != null) { final Set<String> childrenMIs = CvObjectUtils.getChildrenMIs(cvInteractorType); cvIdentifiers.addAll(childrenMIs); } else { if (log.isDebugEnabled()) log.debug("CvInteractorType with this identifier was not found in the database: "+cvIdentifer); } } String sqlQuery = (isCount? "select count(*) " : "") + "from " + getEntityClass().getName() + " i where " + "i.cvInteractorType.identifier in (:interactorTypeIdentifiers)"; Query query = getEntityManager().createQuery(sqlQuery); query.setParameter("interactorTypeIdentifiers", cvIdentifiers); return query; }
cv = dao.getByPsiMiRef( mi ); if (cv == null) { out.println("ERROR: The MI reference you gave doesn't exists. Using the shortlabel instead."); cv = dao.getByShortLabel( shortlabel );
/** * Fetches the corresponding CvDatabase for a specific institution. * * @param context The IntactContext to run the queries to the database * @param institution The institution to find a CvDatabase for * @param defaultDatabaseIdentifier If the passed institution does not have a PSI-MI identifier, the default identifier to use. * @return */ public static CvDatabase retrieveCvDatabase(IntactContext context, Institution institution, String defaultDatabaseIdentifier) { InstitutionXref identityXref = XrefUtils.getPsiMiIdentityXref(institution); if (identityXref == null) return null; CvDatabase cvDatabase = context.getDaoFactory().getCvObjectDao(CvDatabase.class).getByIdentifier(identityXref.getPrimaryId()); if (cvDatabase == null && defaultDatabaseIdentifier != null) { cvDatabase = context.getDaoFactory().getCvObjectDao(CvDatabase.class).getByIdentifier(defaultDatabaseIdentifier); } return cvDatabase; }
public static String createSyncLabelIfNecessary(String shortLabel, Class<? extends CvDagObject> termClass){ CvObjectDao cvDao = IntactContext.getCurrentInstance().getDaoFactory().getCvObjectDao(termClass); AnnotatedObject existingOriginalShortLabel = cvDao.getByShortLabel(shortLabel); List<String> existingLabels = cvDao.getShortLabelsLike(shortLabel + "-%");
private CvFuzzyType findCvFuzzyTypeInDatabase(CvFuzzyType type){ if(type == null){ return null; } CvFuzzyType status = null; if (type.getIdentifier() != null){ status = intactContext.getDaoFactory().getCvObjectDao(CvFuzzyType.class).getByIdentifier(type.getIdentifier()); } else if (type.getShortLabel() != null){ status = intactContext.getDaoFactory().getCvObjectDao(CvFuzzyType.class).getByShortLabel(type.getShortLabel()); } return status; }
cv = dao.getByPsiMiRef(mi); cv = dao.getByShortLabel(clazz, shortlabel); } else { psi = IntactContext.getCurrentInstance().getDataContext().getDaoFactory() .getCvObjectDao(CvDatabase.class).getByPsiMiRef(CvDatabase.PSI_MI_MI_REF); getDaoFactory().getCvObjectDao( clazz ).persist(cv); if ( log.isDebugEnabled() ) log.debug("Created missing CV Term: " + clazz.getSimpleName() + "( " + cv.getShortLabel() + " - " +
protected <T extends CvObject> T getCvObjectByLabel( Class<T> cvObjectClass, String label ) { if ( label == null ) { throw new NullPointerException( "label is null" ); } if ( log.isTraceEnabled() ) log.trace( "Processed values size: " + processed.size() ); for ( CvObject cvObject : processed.values() ) { if ( cvObjectClass.isAssignableFrom( cvObject.getClass() ) && label.equals( cvObject.getShortLabel() ) ) { return ( T ) cvObject; } } return IntactContext.getCurrentInstance().getDataContext().getDaoFactory() .getCvObjectDao( cvObjectClass ).getByShortLabel( cvObjectClass, label ); }
.getCvObjectDao(CvXrefQualifier.class).getByPsiMiRef(CvXrefQualifier.IDENTITY_MI_REF); identity = cvBuilder.createIdentityCvXrefQualifier( owner ); identity.setFullName("identical object"); intactContext.getDataContext().getDaoFactory().getCvObjectDao(CvXrefQualifier.class).persist(identity); .getCvObjectDao(CvDatabase.class).getByPsiMiRef(CvDatabase.PSI_MI_MI_REF); intactContext.getDataContext().getDaoFactory().getCvObjectDao(CvDatabase.class).persist(psi);
private CvTopic createCvTopicObsolete() { final DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); if ( obsoleteTopic != null ) { if (daoFactory.getBaseDao().isTransient(obsoleteTopic) && obsoleteTopic.getAc() != null) { obsoleteTopic = daoFactory.getCvObjectDao( CvTopic.class ).getByAc( obsoleteTopic.getAc() ); } } else { obsoleteTopic = daoFactory.getCvObjectDao( CvTopic.class ).getByPsiMiRef( CvTopic.OBSOLETE_MI_REF ); } if ( obsoleteTopic == null ) { // create the obsolete term (which is obsolete too!) obsoleteTopic = CvObjectUtils.createCvObject( IntactContext.getCurrentInstance().getInstitution(), CvTopic.class, CvTopic.OBSOLETE_MI_REF, CvTopic.OBSOLETE ); obsoleteTopic.setFullName( "obsolete term" ); addObsoleteAnnotation( obsoleteTopic, "Deprecated CV term that should not be used to annotate entries" ); } return obsoleteTopic; }
CvXrefQualifier secondary = factory.getCvObjectDao(CvXrefQualifier.class).getByPsiMiRef(CvXrefQualifier.SECONDARY_AC_MI_REF); factory.getCvObjectDao(CvDagObject.class).delete(term);
@Transactional(propagation = Propagation.REQUIRED) public void updateChildrenHavingMissingParent(String child, String parent) { CvObjectDao<CvDagObject> cvDao = IntactContext.getCurrentInstance().getDaoFactory().getCvObjectDao(CvDagObject.class); CvDagObject reloadedChild = cvDao.getByAc(child); CvDagObject reloadedParent = cvDao.getByAc(parent); if (reloadedChild != null){ reloadedChild.addParent(reloadedParent); IntactContext.getCurrentInstance().getCorePersister().saveOrUpdate(reloadedChild); } else { log.warn("Cv object " + child + " cannot be updated because does not exist anymore"); } }
/** * Prints the most counts in the database. * @param ps The printStream to use * * @since 1.9.0 */ public static void printDatabaseCounts(PrintStream ps) { final DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); ps.println("Publications: "+ daoFactory.getPublicationDao().countAll()); ps.println("\tXrefs: "+ daoFactory.getXrefDao(PublicationXref.class).countAll()); ps.println("\tAliases: "+ daoFactory.getAliasDao(PublicationAlias.class).countAll()); ps.println("Experiments: "+ daoFactory.getExperimentDao().countAll()); ps.println("\tXrefs: "+ daoFactory.getXrefDao(ExperimentXref.class).countAll()); ps.println("\tAliases: "+ daoFactory.getAliasDao(ExperimentAlias.class).countAll()); ps.println("Interactors: "+ daoFactory.getInteractorDao().countAll()); ps.println("\tInteractions: "+ daoFactory.getInteractionDao().countAll()); ps.println("\tPolymers: " + daoFactory.getPolymerDao().countAll()); ps.println("\t\tProteins: "+ daoFactory.getProteinDao().countAll()); ps.println("\t\tNucleic Acids: "+ daoFactory.getInteractorDao(NucleicAcidImpl.class).countAll()); ps.println("\tSmall molecules: " + daoFactory.getInteractorDao(SmallMoleculeImpl.class).countAll()); ps.println("\tInteractor Xrefs: "+ daoFactory.getXrefDao(InteractorXref.class).countAll()); ps.println("\tInteractor Aliases: "+ daoFactory.getAliasDao(InteractorAlias.class).countAll()); ps.println("Components: "+ daoFactory.getComponentDao().countAll()); ps.println("Features: "+ daoFactory.getFeatureDao().countAll()); ps.println("\tRanges: "+ daoFactory.getRangeDao().countAll()); ps.println("CvObjects: "+ daoFactory.getCvObjectDao().countAll()); ps.println("BioSources: "+ daoFactory.getBioSourceDao().countAll()); ps.println("Annotations: "+ daoFactory.getAnnotationDao().countAll()); ps.println("Institutions: "+ daoFactory.getInstitutionDao().countAll()); }
/** * The local identity is created using a sequence. If the sequence does not exist, a new one is created * with initial value calculated using the maximum integer for the existing local CV identifiers. * @return The next value available * @throws SequenceCreationException thrown if the sequence cannot be created. */ protected String nextLocalIdentifier() throws SequenceCreationException { final IntactContext context = IntactContext.getCurrentInstance(); String prefix = context.getConfig().getLocalCvPrefix(); Integer max = context.getDataContext().getDaoFactory() .getCvObjectDao().getLastCvIdentifierWithPrefix(prefix); if (max == null) max = 0; SequenceManager seqManager = (SequenceManager) context.getSpringContext().getBean("sequenceManager"); seqManager.createSequenceIfNotExists(IntactAuxiliaryConfigurator.CV_LOCAL_SEQ, max+1); String nextIntegerAsString = String.valueOf(seqManager.getNextValueForSequence(IntactAuxiliaryConfigurator.CV_LOCAL_SEQ)); return prefix+":" + StringUtils.leftPad(nextIntegerAsString, 4, "0"); }
cv = dao.getByPsiMiRef(mi); cv = dao.getByShortLabel(clazz, shortlabel); } else { psi = IntactContext.getCurrentInstance().getDataContext().getDaoFactory() .getCvObjectDao(CvDatabase.class).getByPsiMiRef(CvDatabase.PSI_MI_MI_REF); getDaoFactory().getCvObjectDao( clazz ).persist(cv); if ( log.isDebugEnabled() ) log.debug("Created missing CV Term: " + clazz.getSimpleName() + "( " + cv.getShortLabel() + " - " +
/** * Adds the 'on-hold' to a publication. * * @param intactContext The IntactContext as accessing data is necessary * @param publication the publication to hold * @param reason the reason for the 'on-hold' status * @since 2.5.0 */ public static void markAsOnHold(IntactContext intactContext, Publication publication, String reason) { CvTopic onholdTopic = intactContext.getDaoFactory().getCvObjectDao(CvTopic.class).getByShortLabel(CvTopic.ON_HOLD); if (onholdTopic == null) throw new IllegalStateException("CvTopic on-hold was not found in the database"); Annotation annotation = new Annotation(onholdTopic, reason); publication.addAnnotation(annotation); }
CvTopic cvTop = factory.getCvObjectDao(CvTopic.class).getByIdentifier(currentOntologyRef.getTopicId()); CvTopic cvTop = factory.getCvObjectDao(CvTopic.class).getByIdentifier(currentOntologyRef.getTopicId()); CvTopic topicFromDb = factory.getCvObjectDao(CvTopic.class).getByShortLabel(CvTopic.DEFINITION); CvTopic topicFromDb = factory.getCvObjectDao(CvTopic.class).getByIdentifier(CvTopic.URL_MI_REF); CvTopic topicFromDb = factory.getCvObjectDao(CvTopic.class).getByIdentifier(CvTopic.OBSOLETE_MI_REF); comment = factory.getCvObjectDao(CvTopic.class).getByIdentifier(CvTopic.COMMENT_MI_REF);
.getCvObjectDao(CvXrefQualifier.class).getByPsiMiRef(CvXrefQualifier.IDENTITY_MI_REF); identity = cvBuilder.createIdentityCvXrefQualifier( owner ); identity.setFullName("identical object"); intactContext.getDataContext().getDaoFactory().getCvObjectDao(CvXrefQualifier.class).persist(identity); .getCvObjectDao(CvDatabase.class).getByPsiMiRef(CvDatabase.PSI_MI_MI_REF); intactContext.getDataContext().getDaoFactory().getCvObjectDao(CvDatabase.class).persist(psi);
@Transactional(propagation = Propagation.REQUIRES_NEW) /** * Updated a cv object given its intact accession. This method will not create any missing parents */ public void updateCv(String cvObjectAc, String ontologyId) throws CvUpdateException { DaoFactory factory = IntactContext.getCurrentInstance().getDaoFactory(); CvDagObject cvObject = factory.getCvObjectDao(CvDagObject.class).getByAc(cvObjectAc); if (cvObject != null){ updateCv(cvObject, ontologyId); } // fire an error because term ac cannot be found in the database else { CvUpdateError error = errorFactory.createCvUpdateError(UpdateError.not_found_intact_ac, "Intact Ac does not match any Cv term in the database", null, cvObject.getAc(), null); UpdateErrorEvent evt = new UpdateErrorEvent(this, error); fireOnUpdateError(evt); } }
/** * Prints the most counts in the database. * @param ps The printStream to use * * @since 1.9.0 */ public static void printDatabaseCounts(PrintStream ps) { final DaoFactory daoFactory = IntactContext.getCurrentInstance().getDataContext().getDaoFactory(); ps.println("Publications: "+ daoFactory.getPublicationDao().countAll()); ps.println("\tXrefs: "+ daoFactory.getXrefDao(PublicationXref.class).countAll()); ps.println("\tAliases: "+ daoFactory.getAliasDao(PublicationAlias.class).countAll()); ps.println("Experiments: "+ daoFactory.getExperimentDao().countAll()); ps.println("\tXrefs: "+ daoFactory.getXrefDao(ExperimentXref.class).countAll()); ps.println("\tAliases: "+ daoFactory.getAliasDao(ExperimentAlias.class).countAll()); ps.println("Interactors: "+ daoFactory.getInteractorDao().countAll()); ps.println("\tInteractions: "+ daoFactory.getInteractionDao().countAll()); ps.println("\tPolymers: " + daoFactory.getPolymerDao().countAll()); ps.println("\t\tProteins: "+ daoFactory.getProteinDao().countAll()); ps.println("\t\tNucleic Acids: "+ daoFactory.getInteractorDao(NucleicAcidImpl.class).countAll()); ps.println("\tSmall molecules: " + daoFactory.getInteractorDao(SmallMoleculeImpl.class).countAll()); ps.println("\tInteractor Xrefs: "+ daoFactory.getXrefDao(InteractorXref.class).countAll()); ps.println("\tInteractor Aliases: "+ daoFactory.getAliasDao(InteractorAlias.class).countAll()); ps.println("Components: "+ daoFactory.getComponentDao().countAll()); ps.println("Features: "+ daoFactory.getFeatureDao().countAll()); ps.println("\tRanges: "+ daoFactory.getRangeDao().countAll()); ps.println("CvObjects: "+ daoFactory.getCvObjectDao().countAll()); ps.println("BioSources: "+ daoFactory.getBioSourceDao().countAll()); ps.println("Annotations: "+ daoFactory.getAnnotationDao().countAll()); ps.println("Institutions: "+ daoFactory.getInstitutionDao().countAll()); }