public VariantQueryResult<Variant> get(Query query, QueryOptions options) { try { return (VariantQueryResult<Variant>) getOrIterator(query, options, false); } catch (StorageEngineException e) { throw VariantQueryException.internalException(e); } }
@Override public VariantDBIterator iterator(Query query, QueryOptions options) { try { return (VariantDBIterator) getOrIterator(query, options, true); } catch (StorageEngineException e) { throw VariantQueryException.internalException(e); } }
@Override public void forEachRemaining(Consumer<? super Variant> action) { Objects.requireNonNull(action); while (hasNext()) { action.accept(next()); } try { close(); } catch (Exception e) { throw VariantQueryException.internalException(e); } }
@Override public QueryResult<Long> count(Query query) { if (query == null) { query = new Query(); } long startTime = System.currentTimeMillis(); String sql = queryParser.parse(query, new QueryOptions(QueryOptions.COUNT, true)).getSql(); logger.info(sql); try (Statement statement = getJdbcConnection().createStatement(); ResultSet resultSet = statement.executeQuery(sql)) { // Cleans up Statement and RS resultSet.next(); long count = resultSet.getLong(1); return new QueryResult<>("count", ((int) (System.currentTimeMillis() - startTime)), 1, 1, "", "", Collections.singletonList(count)); } catch (SQLException e) { throw VariantQueryException.internalException(e); } }
protected Query preProcessQuery(Query query, QueryOptions options) { try { query = variantStorageEngine.preProcessQuery(query, options); } catch (StorageEngineException e) { throw VariantQueryException.internalException(e); } return query; }
protected Query preProcessQuery(Query query, QueryOptions options) { try { query = variantStorageEngine.preProcessQuery(query, options); } catch (StorageEngineException e) { throw VariantQueryException.internalException(e); } return query; }
} else { throw VariantQueryException.internalException(new IllegalStateException("Unsupported negated files with operator OR"));
public SingleSampleIndexVariantDBIterator(Table table, List<Region> regions, Integer studyId, String sample, List<String> gts, SampleIndexDBAdaptor dbAdaptor) { if (CollectionUtils.isEmpty(regions)) { // If no regions are defined, get a list of one null element to initialize the stream. regions = Collections.singletonList(null); } else { regions = VariantQueryUtils.mergeRegions(regions); } Iterator<Iterator<Variant>> iterators = regions.stream() .map(region -> { // One scan per region Scan scan = dbAdaptor.parse(region, studyId, sample, gts, false); SampleIndexConverter converter = new SampleIndexConverter(region); try { ResultScanner scanner = table.getScanner(scan); addCloseable(scanner); Iterator<Result> resultIterator = scanner.iterator(); Iterator<Iterator<Variant>> transform = Iterators.transform(resultIterator, result -> converter.convert(result).iterator()); return Iterators.concat(transform); } catch (IOException e) { throw VariantQueryException.internalException(e); } }).iterator(); iterator = Iterators.concat(iterators); }
/** * Partially processed iterator. Internal usage only. * @param regions List of regions * @param studyId Study ID * @param sample Sample * @param gts Processed list of GTs. Real GTs only. * @return SingleSampleIndexVariantDBIterator */ private SingleSampleIndexVariantDBIterator internalIterator(List<Region> regions, int studyId, String sample, List<String> gts) { String tableName = tableNameGenerator.getSampleIndexTableName(studyId); try { return hBaseManager.act(tableName, table -> { return new SingleSampleIndexVariantDBIterator(table, regions, studyId, sample, gts, this); }); } catch (IOException e) { throw VariantQueryException.internalException(e); } }
public Set<String> getGenesByGo(List<String> goValues) { Set<String> genes = new HashSet<>(); QueryOptions params = new QueryOptions(QueryOptions.INCLUDE, "name,chromosome,start,end"); try { List<QueryResult<Gene>> responses = cellBaseClient.getGeneClient().get(goValues, params) .getResponse(); for (QueryResult<Gene> response : responses) { for (Gene gene : response.getResult()) { genes.add(gene.getName()); } } } catch (IOException e) { throw VariantQueryException.internalException(e); } return genes; }
throw VariantQueryException.internalException(e);
public Iterator<Map<String, List<Variant>>> rawIterator(int study, int sample) throws IOException { String tableName = tableNameGenerator.getSampleIndexTableName(study); return hBaseManager.act(tableName, table -> { Scan scan = new Scan(); scan.setRowPrefixFilter(SampleIndexConverter.toRowKey(sample)); SampleIndexConverter converter = new SampleIndexConverter(); try { ResultScanner scanner = table.getScanner(scan); Iterator<Result> resultIterator = scanner.iterator(); Iterator<Map<String, List<Variant>>> iterator = Iterators.transform(resultIterator, converter::convertToMap); return iterator; } catch (IOException e) { throw VariantQueryException.internalException(e); } }); }
throw VariantQueryException.internalException(e);
throw VariantQueryException.internalException(e);
scans.add(scan); } catch (IOException e) { throw VariantQueryException.internalException(e); scans.add(scan); } catch (IOException e) { throw VariantQueryException.internalException(e);
public Set<String> getGenesByExpression(List<String> expressionValues) { Set<String> genes = new HashSet<>(); QueryOptions params = new QueryOptions(QueryOptions.INCLUDE, "name,chromosome,start,end"); // The number of results for each expression value may be huge. Query one by one for (String expressionValue : expressionValues) { try { String[] split = expressionValue.split(":"); expressionValue = split[0]; Query cellbaseQuery = new Query(2) .append(GeneDBAdaptor.QueryParams.ANNOTATION_EXPRESSION_TISSUE.key(), expressionValue) .append(GeneDBAdaptor.QueryParams.ANNOTATION_EXPRESSION_VALUE.key(), "UP"); List<QueryResult<Gene>> responses = cellBaseClient.getGeneClient().search(cellbaseQuery, params) .getResponse(); for (QueryResult<Gene> response : responses) { for (Gene gene : response.getResult()) { genes.add(gene.getName()); } } } catch (IOException e) { throw VariantQueryException.internalException(e); } } return genes; }
archiveHelper = getArchiveHelper(studyId, fileId); } catch (IOException | StorageEngineException e) { throw VariantQueryException.internalException(e); return new VariantHadoopArchiveDBIterator(resScan, archiveHelper, options).setRegion(region); } catch (IOException e) { throw VariantQueryException.internalException(e); return table.getScanner(scan); } catch (IOException e) { throw VariantQueryException.internalException(e); throw VariantQueryException.internalException(e); throw VariantQueryException.internalException(e);
throw VariantQueryException.internalException(e); throw VariantQueryException.internalException(e); }); } catch (IOException e) { throw VariantQueryException.internalException(e);
variants.close(); } catch (Exception e) { throw VariantQueryException.internalException(e);
return table.getScanner(scan).iterator(); } catch (IOException e) { throw VariantQueryException.internalException(e); throw VariantQueryException.internalException(e);