Query cohortQuery = new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT); QueryOptions cohortOptions = new QueryOptions(INCLUDE, CohortDBAdaptor.QueryParams.SAMPLE_UIDS.key()); new QueryOptions(INCLUDE, CohortDBAdaptor.QueryParams.SAMPLE_UIDS.key()), sessionId) .first() .getSamples()
fixComplexQueryParam(QueryParams.ATTRIBUTES.key(), query); fixComplexQueryParam(QueryParams.BATTRIBUTES.key(), query); fixComplexQueryParam(QueryParams.NATTRIBUTES.key(), query); QueryParams queryParam = QueryParams.getParam(entry.getKey()) != null ? QueryParams.getParam(entry.getKey()) : QueryParams.getParam(key); if (queryParam == null) { if (Constants.PRIVATE_ANNOTATION_PARAM_TYPES.equals(entry.getKey())) { switch (queryParam) { case UID: addAutoOrQuery(PRIVATE_UID, queryParam.key(), query, queryParam.type(), andBsonList); break; case STUDY_UID: addAutoOrQuery(PRIVATE_STUDY_ID, queryParam.key(), query, queryParam.type(), andBsonList); break; case ATTRIBUTES: addAutoOrQuery(entry.getKey(), entry.getKey(), query, queryParam.type(), andBsonList); break; case BATTRIBUTES: String mongoKey = entry.getKey().replace(QueryParams.BATTRIBUTES.key(), QueryParams.ATTRIBUTES.key()); addAutoOrQuery(mongoKey, entry.getKey(), query, queryParam.type(), andBsonList); break; case NATTRIBUTES: mongoKey = entry.getKey().replace(QueryParams.NATTRIBUTES.key(), QueryParams.ATTRIBUTES.key()); addAutoOrQuery(mongoKey, entry.getKey(), query, queryParam.type(), andBsonList); break; case ANNOTATION: if (annotationDocument == null) {
new ObjectMap(CohortDBAdaptor.QueryParams.SAMPLES.key(), cohortFromStorage), true, null, sessionId); Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), studyConfiguration.getCalculatedStats().stream() .map(studyConfiguration.getCohortIds().inverse()::get) .collect(Collectors.toList())); Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), studyConfiguration.getInvalidStats().stream() .map(studyConfiguration.getCohortIds().inverse()::get) .collect(Collectors.toList()));
.append(CohortDBAdaptor.QueryParams.SAMPLE_UIDS.key(), sample.getUid()) .append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); DBIterator<Cohort> cohortIterator = cohortDBAdaptor.iterator(auxQuery, QueryOptions.empty()); while (cohortIterator.hasNext()) { Query cohortQuery = new Query(CohortDBAdaptor.QueryParams.UID.key(), cohort.getUid()); WriteResult delete = catalogManager.getCohortManager().delete(studyStr, cohortQuery, new ObjectMap(), sessionId); if (delete.getWarning() != null || delete.getError() != null) {
Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), sampleAclParams.getCohort()); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()); QueryResult<Cohort> cohortQueryResult = catalogManager.getCohortManager().get(studyStr, query, options, sessionId);
Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT); QueryResult<Cohort> queryResult = catalogManager.getCohortManager().get(study.getFqn(), query, new QueryOptions(), sessionId);
finalQuery.append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); .append(CohortDBAdaptor.QueryParams.UID.key(), cohort.getUid()) .append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()); ObjectMap updateParams = new ObjectMap() .append(CohortDBAdaptor.QueryParams.STATUS_NAME.key(), Status.DELETED) .append(CohortDBAdaptor.QueryParams.ID.key(), cohort.getId() + suffixName); QueryResult<Long> update = cohortDBAdaptor.update(updateQuery, updateParams, QueryOptions.empty()); if (update.first() > 0) {
String[] acceptedParams = {QueryParams.NAME.key(), QueryParams.DESCRIPTION.key(), QueryParams.CREATION_DATE.key()}; filterStringParams(parameters, cohortParams, acceptedParams); Map<String, Class<? extends Enum>> acceptedEnums = Collections.singletonMap(QueryParams.TYPE.key(), Study.Type.class); filterEnumParams(parameters, cohortParams, acceptedEnums); if (parameters.containsKey(CohortDBAdaptor.QueryParams.ID.key())) { throw new CatalogDBException("Update cohort: Cannot update " + QueryParams.ID.key() + " parameter. More than one cohort " + "found to be updated."); .append(QueryParams.ID.key(), parameters.get(QueryParams.ID.key())) .append(QueryParams.STUDY_UID.key(), studyId); QueryResult<Long> count = count(tmpQuery); if (count.getResult().get(0) > 0) { throw new CatalogDBException("Cannot update the " + QueryParams.ID.key() + ". Cohort " + parameters.get(QueryParams.ID.key()) + " already exists."); cohortParams.put(QueryParams.ID.key(), parameters.get(QueryParams.ID.key())); if (parameters.containsKey(QueryParams.SAMPLES.key())) { List<Long> objectSampleList = parameters.getAsLongList(QueryParams.SAMPLES.key()); List<Sample> sampleList = new ArrayList<>(); for (Long sampleId : objectSampleList) { cohortParams.put(QueryParams.SAMPLES.key(), cohortConverter.convertSamplesToDocument(sampleList)); String[] acceptedMapParams = {QueryParams.ATTRIBUTES.key(), QueryParams.STATS.key()}; filterMapParams(parameters, cohortParams, acceptedMapParams);
for (String cohort : cohorts) { String cohortId = catalogManager.getCohortManager().get(study.getFqn(), cohort, new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.ID.key()), sessionId).first().getId(); cohortIds.add(cohortId);
if (parameters.containsKey(CohortDBAdaptor.QueryParams.SAMPLES.key()) || parameters.containsKey(CohortDBAdaptor.QueryParams.ID.key())) { switch (cohort.getStatus().getName()) { case Cohort.CohortStatus.CALCULATING: List<String> sampleStringList = parameters.getAsStringList(CohortDBAdaptor.QueryParams.SAMPLES.key()); Query query = new Query() .append(SampleDBAdaptor.QueryParams.STUDY_UID.key(), study.getUid()) parameters.put(CohortDBAdaptor.QueryParams.SAMPLES.key(), sampleQueryResult.getResult().stream() .map(Sample::getUid) .collect(Collectors.toList()));
List<String> includeList = new ArrayList<>(); for (String include : currentIncludeList) { if (include.startsWith(CohortDBAdaptor.QueryParams.SAMPLES.key() + ".")) { includeList.add(include.replace(CohortDBAdaptor.QueryParams.SAMPLES.key() + ".", "")); List<String> excludeList = new ArrayList<>(); for (String exclude : currentExcludeList) { if (exclude.startsWith(CohortDBAdaptor.QueryParams.SAMPLES.key() + ".")) { String replace = exclude.replace(CohortDBAdaptor.QueryParams.SAMPLES.key() + ".", ""); if (!SampleDBAdaptor.QueryParams.UID.key().equals(replace) && !SampleDBAdaptor.QueryParams.VERSION.key().equals(replace)) {
Object samples = cohortDocument.get(CohortDBAdaptor.QueryParams.SAMPLES.key()); if (samples != null && !options.getBoolean(NATIVE_QUERY)) { List<Document> sampleList = (List<Document>) samples; List<Document> samples = (List<Document>) cohortDocument.get(CohortDBAdaptor.QueryParams.SAMPLES.key()); cohortDocument.put(CohortDBAdaptor.QueryParams.SAMPLES.key(), tmpSampleList); });
.append(CohortDBAdaptor.QueryParams.STUDY_UID.key(), resource.getStudy().getUid()) .append(CohortDBAdaptor.QueryParams.UID.key(), resource.getResource().getUid()); QueryResult<Cohort> cohortQueryResult = cohortDBAdaptor.get(query, new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.SAMPLES.key()));
numResults = catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.SAMPLES.key(), sampleId1.getId()), new QueryOptions(), sessionIdUser).getNumResults(); assertEquals(2, numResults); numResults = catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.SAMPLES.key(), sampleId1.getId() + "," + sampleId5.getId()), new QueryOptions(), sessionIdUser).getNumResults(); assertEquals(3, numResults); numResults = catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "MyCohort2"), new QueryOptions(), sessionIdUser).getNumResults(); assertEquals(1, numResults); numResults = catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), "~MyCohort."), new QueryOptions(), sessionIdUser).getNumResults(); assertEquals(4, numResults); numResults = catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.TYPE.key(), Study.Type.FAMILY), new QueryOptions(), sessionIdUser).getNumResults(); assertEquals(2, numResults); numResults = catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.TYPE.key(), "CASE_CONTROL"), new QueryOptions(), sessionIdUser).getNumResults(); assertEquals(1, numResults); numResults = catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.UID.key(), myCohort1.getUid() + "," + myCohort2.getUid() + "," + myCohort3.getUid()), new QueryOptions(), sessionIdUser).getNumResults(); assertEquals(3, numResults);
new Query(CohortDBAdaptor.QueryParams.ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSetId), new QueryOptions()); if (cohorts.getNumResults() != 0) { String msg = "Can't delete VariableSetId, still in use as \"variableSetId\" of cohorts : [";
new Query(CohortDBAdaptor.QueryParams.STUDY_UID.key(), studyId), null).getResult(); assertEquals(numCohorts, cohorts.size()); Set<String> names = cohorts.stream().map(Cohort::getId).collect(Collectors.toSet());
assertEquals(Cohort.CohortStatus.READY, getDefaultCohort(studyId).getStatus().getName()); checkCalculatedStats(studyId, Collections.singletonMap(DEFAULT_COHORT, catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first()), catalogManager, dbName, sessionId); assertNotNull(catalogManager.getFileManager().get(studyId, getFile(2).getId(), null, sessionId).first().getStats().get(FileMetadataReader.VARIANT_FILE_STATS)); assertNotNull(catalogManager.getFileManager().get(studyId, getFile(4).getId(), null, sessionId).first().getStats().get(FileMetadataReader.VARIANT_FILE_STATS)); checkCalculatedStats(studyId, Collections.singletonMap(DEFAULT_COHORT, catalogManager.getCohortManager().get(studyId, new Query(CohortDBAdaptor.QueryParams.ID.key(), DEFAULT_COHORT), new QueryOptions(), sessionId).first()), catalogManager, dbName, sessionId);