public static VariantQueryException cohortNotFound(int cohortId, int studyId, Collection<String> availableCohorts) { return cohortNotFound(cohortId, null, studyId, availableCohorts); }
public static VariantQueryException cohortNotFound(String cohortName, int studyId, Collection<String> availableCohorts) { return cohortNotFound(null, String.valueOf(cohortName), studyId, availableCohorts); }
/** * Get list of fileIds from a study. * * @param cohorts List of cohorts * @param studyConfiguration Study configuration. * @return List of file ids within this study * @throws VariantQueryException if the list of cohorts contains cohorts from other studies */ public static List<Integer> getCohortIdsFromStudy(List<?> cohorts, StudyConfiguration studyConfiguration) throws VariantQueryException { Objects.requireNonNull(studyConfiguration); List<Integer> fileIds = new ArrayList<>(cohorts.size()); for (Object cohortObj : cohorts) { Integer cohortId = getCohortIdFromStudy(cohortObj, studyConfiguration); if (cohortId == null) { throw VariantQueryException.cohortNotFound(cohortObj.toString(), studyConfiguration.getStudyId(), studyConfiguration.getCohortIds().keySet()); } fileIds.add(cohortId); } return fileIds; }
/** * Finds the cohortId from a cohort reference. * * @param cohort Cohort reference (name or id) * @param studyConfiguration Default study configuration * @return Cohort id * @throws VariantQueryException if the cohort does not exist */ public int getCohortId(String cohort, StudyConfiguration studyConfiguration) throws VariantQueryException { int cohortId; if (StringUtils.isNumeric(cohort)) { cohortId = Integer.parseInt(cohort); if (!studyConfiguration.getCohortIds().containsValue(cohortId)) { throw VariantQueryException.cohortNotFound(cohortId, studyConfiguration.getStudyId(), studyConfiguration.getCohortIds().keySet()); } } else { Integer cohortIdNullable = studyConfiguration.getCohortIds().get(cohort); if (cohortIdNullable == null) { throw VariantQueryException.cohortNotFound(cohort, studyConfiguration.getStudyId(), studyConfiguration.getCohortIds().keySet()); } cohortId = cohortIdNullable; } return cohortId; }
@Test public void testGetAllVariants_maf_cohortNotFound() throws Exception { VariantQueryException exception = VariantQueryException.cohortNotFound("cohort3", studyConfiguration.getStudyId(), studyConfiguration.getCohortIds().keySet()); thrown.expect(instanceOf(exception.getClass())); thrown.expectCause(is(exception.getCause())); query(new Query(STATS_MAF.key(), STUDY_NAME + ":cohort3>0.2"), null); }
@Test public void testGetAllVariants_cohorts_fail1() throws Exception { VariantQueryException expected = VariantQueryException.cohortNotFound("cohort5_dont_exists", 1, studyConfiguration.getCohortIds().keySet()); thrown.expect(expected.getClass()); thrown.expectMessage(expected.getMessage()); queryResult = query(new Query(STUDY.key(), 1) .append(COHORT.key(), "!cohort5_dont_exists"), null); }
cohortId = StudyConfigurationManager.getCohortIdFromStudy(cohort, defaultStudyConfiguration); if (cohortId == null) { throw VariantQueryException.cohortNotFound(cohort, defaultStudyConfiguration.getStudyId(), defaultStudyConfiguration.getCohortIds().keySet());