protected List<String> splitValue(String valuesStr, QueryOperation queryOperation) { return VariantQueryUtils.splitValue(valuesStr, queryOperation); }
/** * Splits the string with the specified operation. * * @param value Value to split * @return List of values, without the delimiter */ public static Pair<QueryOperation, List<String>> splitValue(String value) { QueryOperation operation = checkOperator(value); return Pair.of(operation, splitValue(value, operation)); }
private <T> QueryBuilder addQueryFilter(String key, String value, final QueryBuilder builder, QueryOperation op, Function<String, T> map) { VariantQueryUtils.QueryOperation intraOp = checkOperator(value); return addQueryFilter(key, splitValue(value, intraOp), builder, op, intraOp, map); }
/** * Parse the genotype filter. * * @param sampleGenotypes Genotypes filter value * @param map Initialized map to be filled with the sample to list of genotypes * @return QueryOperation between samples */ public static QueryOperation parseGenotypeFilter(String sampleGenotypes, Map<Object, List<String>> map) { Pair<QueryOperation, Map<String, String>> pair = parseMultiKeyValueFilter(GENOTYPE, sampleGenotypes); for (Map.Entry<String, String> entry : pair.getValue().entrySet()) { List<String> gts = splitValue(entry.getValue(), QueryOperation.OR); boolean anyNegated = false; boolean allNegated = true; for (String gt : gts) { if (isNegated(gt)) { anyNegated = true; } else { allNegated = false; } } if (!allNegated && anyNegated) { throw VariantQueryException.malformedParam(GENOTYPE, sampleGenotypes); } map.put(entry.getKey(), gts); } return pair.getKey(); }
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 } }
/** * Accept filters separated with "," or ";" with the expression: * [{STUDY}:]{COHORT}{OPERATION}{VALUE}. * Where STUDY is optional if defaultStudyConfiguration is provided * * @param key Stats field to filter * @param values Values to parse * @param builder QueryBuilder * @param defaultStudyConfiguration */ private void addStatsFilterList(String key, String values, QueryBuilder builder, StudyConfiguration defaultStudyConfiguration) { QueryOperation op = checkOperator(values); List<String> valuesList = splitValue(values, op); List<DBObject> statsQueries = new LinkedList<>(); for (String value : valuesList) { statsQueries.add(addStatsFilter(key, value, new QueryBuilder(), defaultStudyConfiguration).get()); } if (!statsQueries.isEmpty()) { if (op == QueryOperation.OR) { builder.or(statsQueries.toArray(new DBObject[statsQueries.size()])); } else { builder.and(statsQueries.toArray(new DBObject[statsQueries.size()])); } } }
Pair<Integer, Integer> fileIdPair = studyConfigurationManager .getFileIdPair(entry.getKey(), false, defaultStudyConfiguration); Pair<QueryOperation, List<String>> infoPair = splitValue(infoValues); for (String infoValue : infoPair.getValue()) {
Pair<QueryOperation, List<String>> formatPair = splitValue(formatValues); for (String formatValue : formatPair.getValue()) {
final List<String> list; QueryOperation operation = checkOperator(value); list = splitValue(value, operation);
Pair<QueryOperation, List<String>> pair = splitValue(sampleFilter); samples = new LinkedList<>(pair.getValue()); samplesOperator = pair.getKey();
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; } }
public static List<String> getIncludeStudiesList(Query query, Set<VariantField> fields) { List<String> studies; if (!fields.contains(VariantField.STUDIES)) { studies = Collections.emptyList(); } else if (isValidParam(query, INCLUDE_STUDY)) { String includeStudy = query.getString(VariantQueryParam.INCLUDE_STUDY.key()); if (NONE.equals(includeStudy)) { studies = Collections.emptyList(); } else if (ALL.equals(includeStudy)) { studies = null; } else { studies = query.getAsStringList(VariantQueryParam.INCLUDE_STUDY.key()); } } else if (isValidParam(query, STUDY)) { String value = query.getString(VariantQueryParam.STUDY.key()); studies = new ArrayList<>(splitValue(value, checkOperator(value))); studies.removeIf(VariantQueryUtils::isNegated); // if empty, all the studies if (studies.isEmpty()) { studies = null; } } else { studies = null; } return studies; }
if (isValidParam(query, SAMPLE)) { String value = query.getString(SAMPLE.key()); samples = splitValue(value, checkOperator(value)) .stream()
includeFiles = splitValue(files, checkOperator(files)) .stream() .filter(value -> !isNegated(value))
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); } }
public static StudyConfiguration getDefaultStudyConfiguration(Query query, QueryOptions options, StudyConfigurationManager studyConfigurationManager) { final StudyConfiguration defaultStudyConfiguration; if (isValidParam(query, VariantQueryParam.STUDY)) { String value = query.getString(VariantQueryParam.STUDY.key()); // Check that the study exists VariantQueryUtils.QueryOperation studiesOperation = checkOperator(value); List<String> studiesNames = splitValue(value, studiesOperation); List<Integer> studyIds = studyConfigurationManager.getStudyIds(studiesNames, options); // Non negated studyIds if (studyIds.size() == 1) { defaultStudyConfiguration = studyConfigurationManager.getStudyConfiguration(studyIds.get(0), null).first(); } else { defaultStudyConfiguration = null; } } else { List<String> studyNames = studyConfigurationManager.getStudyNames(null); if (studyNames != null && studyNames.size() == 1) { defaultStudyConfiguration = studyConfigurationManager.getStudyConfiguration(studyNames.get(0), new QueryOptions()).first(); } else { defaultStudyConfiguration = null; } } return defaultStudyConfiguration; }
/** * Accept a list of comparative filters separated with "," or ";" with the expression: * {OPERATION}{VALUE}, where the accepted operations are: <, <=, >, >=, =, ==, !=, ~=. * * @param key * @param value * @param builder * @param extendKey * @return */ private QueryBuilder addCompListQueryFilter(String key, String value, QueryBuilder builder, boolean extendKey) { VariantQueryUtils.QueryOperation op = checkOperator(value); List<String> values = splitValue(value, op); QueryBuilder compBuilder; if (op == QueryOperation.OR) { compBuilder = QueryBuilder.start(); } else { compBuilder = builder; } for (String elem : values) { addCompQueryFilter(key, elem, compBuilder, extendKey); } if (op == QueryOperation.OR) { builder.or(compBuilder.get()); } return builder; }
List<String> samples = VariantQueryUtils.splitValue(samplesStr, queryOperation); samples.stream().filter(s -> !isNegated(s)).forEach(sample -> samplesMap.put(sample, Collections.emptyList()));
scanQuery.putIfNotNull(SAMPLE.key(), splitValue(value).getValue().get(0)); } else if (isValidParam(query, GENOTYPE)) { } else if (isValidParam(query, FILE)) { String value = query.getString(FILE.key()); Pair<QueryOperation, List<String>> pair = splitValue(value); if (pair.getKey() == QueryOperation.OR) {