public static boolean isQueryCovered(Query query) { for (VariantQueryParam nonCoveredParam : UNSUPPORTED_QUERY_PARAMS) { if (isValidParam(query, nonCoveredParam)) { return false; } } return true; }
private void unsupportedFilter(Query query, VariantQueryParam param) { if (isValidParam(query, param)) { String warn = "Unsupported filter \"" + param + "\""; // warnings.add(warn); logger.warn(warn); } }
public static boolean isIncludeFilesDefined(Query query, Set<VariantField> fields) { if (getIncludeFilesList(query, fields) != null) { return true; } return isValidParam(query, SAMPLE, true) || isValidParam(query, INCLUDE_SAMPLE, false) || isValidParam(query, GENOTYPE, false); }
public static boolean isIncludeSamplesDefined(Query query, Set<VariantField> fields) { if (getIncludeSamplesList(query, fields) != null) { return true; } return isValidParam(query, FILE, true) || isValidParam(query, INCLUDE_FILE, true); }
@Override protected QueryOptions getIteratorQueryOptions(Query query, ObjectMap params) { QueryOptions iteratorQueryOptions = super.getIteratorQueryOptions(query, params); if (!VariantQueryUtils.isValidParam(query, VariantQueryParam.FILE) || !VariantQueryUtils.isValidParam(query, VariantQueryParam.ANNOTATION_EXISTS)) { iteratorQueryOptions.putIfAbsent(VariantHadoopDBAdaptor.NATIVE, true); } return iteratorQueryOptions; }
public static Set<VariantQueryParam> validParams(Query query) { Set<VariantQueryParam> params = new HashSet<>(query == null ? 0 : query.size()); for (VariantQueryParam queryParam : values()) { if (isValidParam(query, queryParam)) { params.add(queryParam); } } return params; }
private boolean doHBaseColumnIntersect(Query query, QueryOptions options) { return options.getBoolean("hbase_column_intersect", true) // && !options.getBoolean(VariantHadoopDBAdaptor.NATIVE) && (isValidParam(query, SAMPLE) && isSupportedQueryParam(query, SAMPLE) || isValidParam(query, FILE) && isSupportedQueryParam(query, FILE) || isValidParam(query, GENOTYPE) && isSupportedQueryParam(query, GENOTYPE) && parseGenotypeFilter(query.getString(GENOTYPE.key()), new HashMap<>()) != QueryOperation.OR); }
private List<Region> getRegions(Query query) { List<Region> regions = new ArrayList<>(); if (isValidParam(query, REGION)) { regions.addAll(Region.parseRegions(query.getString(REGION.key()))); } if (isValidParam(query, ANNOT_GENE_REGIONS)) { regions.addAll(Region.parseRegions(query.getString(ANNOT_GENE_REGIONS.key()))); } regions = mergeRegions(regions); return regions; }
private String buildOutputFileName(String alias, Query query) { List<Region> regions = new ArrayList<>(); if (VariantQueryUtils.isValidParam(query, VariantQueryParam.REGION)) { List<Region> c = Region.parseRegions(query.getString(VariantQueryParam.REGION.key())); if (c != null) { regions.addAll(c); } } if (regions.isEmpty() || regions.size() > 1) { return alias + '.' + TimeUtils.getTime(); } else { return alias + ".region_" + regions.get(0).toString() + '.' + TimeUtils.getTime(); } } }
public static boolean isValidParam(Query query, QueryParam param, boolean discardNegated) { boolean validParam = isValidParam(query, param); if (!discardNegated || !validParam) { return validParam; } else { String strValue = query.getString(param.key()); return splitValue(strValue, checkOperator(strValue)) .stream() .anyMatch((v) -> !isNegated(v)); // Discard negated } }
public static boolean isOutputMultiStudy(Query query, QueryOptions options, Collection<?> studies) { Set<VariantField> fields = VariantField.getIncludeFields(options); if (!fields.contains(VariantField.STUDIES)) { return false; } else if (isValidParam(query, INCLUDE_STUDY)) { String includeStudy = query.getString(VariantQueryParam.INCLUDE_STUDY.key()); if (NONE.equals(includeStudy)) { return false; } else if (ALL.equals(includeStudy)) { return studies.size() > 1; } else { return query.getAsList(VariantQueryParam.INCLUDE_STUDY.key()).size() > 1; } } else if (isValidParam(query, STUDY)) { String value = query.getString(VariantQueryParam.STUDY.key()); long numStudies = splitValue(value, checkOperator(value)).stream().filter(s -> !isNegated(s)).count(); return numStudies > 1; } else { return studies.size() > 1; } }
@Override protected boolean doIntersectWithSearch(Query query, QueryOptions options) throws StorageEngineException { boolean doIntersectWithSearch = super.doIntersectWithSearch(query, options); if (doIntersectWithSearch) { if (!isValidParam(query, VariantQueryParam.ANNOT_TRAIT) && VariantStorageEngine.UseSearchIndex.from(options).equals(VariantStorageEngine.UseSearchIndex.AUTO) && doHBaseSampleIndexIntersect(query, options)) { return false; } } return doIntersectWithSearch; }
public static void convertExpressionToGeneQuery(Query query, CellBaseUtils cellBaseUtils) { if (isValidParam(query, VariantQueryParam.ANNOT_EXPRESSION)) { String value = query.getString(VariantQueryParam.ANNOT_EXPRESSION.key()); // Check if comma separated of semi colon separated (AND or OR) VariantQueryUtils.QueryOperation queryOperation = checkOperator(value); // Split by comma or semi colon List<String> expressionValues = splitValue(value, queryOperation); if (queryOperation == VariantQueryUtils.QueryOperation.AND) { throw VariantQueryException.malformedParam(VariantQueryParam.ANNOT_EXPRESSION, value, "Unimplemented AND operator"); } // query.remove(VariantQueryParam.ANNOT_EXPRESSION.key()); Set<String> genesByExpression = cellBaseUtils.getGenesByExpression(expressionValues); if (genesByExpression.isEmpty()) { genesByExpression = Collections.singleton(NONE); } query.put(ANNOT_EXPRESSION_GENES.key(), genesByExpression); } }
public static void convertGoToGeneQuery(Query query, CellBaseUtils cellBaseUtils) { if (isValidParam(query, VariantQueryParam.ANNOT_GO)) { String value = query.getString(VariantQueryParam.ANNOT_GO.key()); // Check if comma separated of semi colon separated (AND or OR) VariantQueryUtils.QueryOperation queryOperation = checkOperator(value); // Split by comma or semi colon List<String> goValues = splitValue(value, queryOperation); if (queryOperation == VariantQueryUtils.QueryOperation.AND) { throw VariantQueryException.malformedParam(VariantQueryParam.ANNOT_GO, value, "Unimplemented AND operator"); } // query.remove(VariantQueryParam.ANNOT_GO.key()); Set<String> genesByGo = cellBaseUtils.getGenesByGo(goValues); if (genesByGo.isEmpty()) { genesByGo = Collections.singleton(NONE); } query.put(ANNOT_GO_GENES.key(), genesByGo); } }
@Test public void testIsValid() { assertFalse(isValidParam(new Query(), ANNOTATION_EXISTS)); assertFalse(isValidParam(new Query(ANNOTATION_EXISTS.key(), null), ANNOTATION_EXISTS)); assertFalse(isValidParam(new Query(ANNOTATION_EXISTS.key(), ""), ANNOTATION_EXISTS)); assertFalse(isValidParam(new Query(ANNOTATION_EXISTS.key(), Collections.emptyList()), ANNOTATION_EXISTS)); assertFalse(isValidParam(new Query(ANNOTATION_EXISTS.key(), Arrays.asList()), ANNOTATION_EXISTS)); assertTrue(isValidParam(new Query(ANNOTATION_EXISTS.key(), Arrays.asList(1,2,3)), ANNOTATION_EXISTS)); assertTrue(isValidParam(new Query(ANNOTATION_EXISTS.key(), 5), ANNOTATION_EXISTS)); assertTrue(isValidParam(new Query(ANNOTATION_EXISTS.key(), "sdfas"), ANNOTATION_EXISTS)); }
public static Query getEngineQuery(Query query, QueryOptions options, StudyConfigurationManager scm) throws StorageEngineException { Collection<VariantQueryParam> uncoveredParams = uncoveredParams(query); Query engineQuery = new Query(); for (VariantQueryParam uncoveredParam : uncoveredParams) { engineQuery.put(uncoveredParam.key(), query.get(uncoveredParam.key())); } // Despite STUDIES is a covered filter, it has to be in the underlying // query to be used as defaultStudy if (isValidParam(query, STUDY)) { if (!uncoveredParams.isEmpty()) { // This will set the default study, if needed engineQuery.put(STUDY.key(), query.get(STUDY.key())); } else if (!isValidParam(query, INCLUDE_STUDY)) { // If returned studies is not defined, we need to define it with the values from STUDIES List<Integer> studies = VariantQueryUtils.getIncludeStudies(query, options, scm); engineQuery.put(INCLUDE_STUDY.key(), studies); } } return engineQuery; }
@Override public Query preProcessQuery(Query originalQuery, QueryOptions options) throws StorageEngineException { Query query = super.preProcessQuery(originalQuery, options); StudyConfigurationManager studyConfigurationManager = getStudyConfigurationManager(); List<String> studyNames = studyConfigurationManager.getStudyNames(QueryOptions.empty()); CellBaseUtils cellBaseUtils = getCellBaseUtils(); if (isValidParam(query, STUDY) && studyNames.size() == 1) { query.remove(STUDY.key()); } convertGoToGeneQuery(query, cellBaseUtils); convertExpressionToGeneQuery(query, cellBaseUtils); convertGenesToRegionsQuery(query, cellBaseUtils); return query; }
public Project getProjectFromQuery(Query query, String sessionId, QueryOptions options) throws CatalogException { if (isValidParam(query, VariantCatalogQueryUtils.PROJECT)) { String project = query.getString(VariantCatalogQueryUtils.PROJECT.key()); return catalogManager.getProjectManager().get(project, options, sessionId).first(); } else { String studyFqn = getAnyStudy(query, sessionId); String project = catalogManager.getStudyManager().getProjectFqn(studyFqn); return catalogManager.getProjectManager().get(new Query(ProjectDBAdaptor.QueryParams.FQN.key(), project), options, sessionId) .first(); } }
public Integer getReleaseFilter(Query query, String sessionId) throws CatalogException { Integer release; if (isValidParam(query, VariantQueryParam.RELEASE)) { release = query.getInt(VariantQueryParam.RELEASE.key(), -1); if (release <= 0) { throw VariantQueryException.malformedParam(VariantQueryParam.RELEASE, query.getString(VariantQueryParam.RELEASE.key())); } Project project = getProjectFromQuery(query, sessionId, new QueryOptions(INCLUDE, ProjectDBAdaptor.QueryParams.CURRENT_RELEASE.key())); int currentRelease = project.getCurrentRelease(); if (release > currentRelease) { throw VariantQueryException.malformedParam(VariantQueryParam.RELEASE, query.getString(VariantQueryParam.RELEASE.key())); } else if (release == currentRelease) { // Using latest release. We don't need to filter by release! release = null; } // else, filter by release } else { release = null; } return release; }
@Test public void queryByFamily() throws Exception { Query query = queryUtils.parseQuery(new Query(STUDY.key(), "s1").append(FAMILY.key(), "f1"), sessionId); assertEquals(Arrays.asList("sample1", "sample2", "sample3", "sample4"), query.getAsStringList(SAMPLE.key())); assertFalse(VariantQueryUtils.isValidParam(query, GENOTYPE)); query = queryUtils.parseQuery(new Query(STUDY.key(), "s1").append(FAMILY.key(), "f1").append(MODE_OF_INHERITANCE.key(), "MONOALLELIC"), sessionId); assertEquals("sample3:0/1,1/1;sample4:0/0;sample1:0/0;sample2:0/0", query.getString(GENOTYPE.key())); assertFalse(VariantQueryUtils.isValidParam(query, SAMPLE)); }