use of org.rsc.chemspider.api.FilteringApi in project mzmine2 by mzmine.
the class ChemSpiderGateway method findCompounds.
@Override
public String[] findCompounds(final double mass, final MZTolerance mzTolerance, final int numOfResults, ParameterSet parameters) throws IOException {
logger.finest("Searching by mass...");
// Get search range
final Range<Double> mzRange = mzTolerance.getToleranceRange(mass);
final double queryMz = RangeUtils.rangeCenter(mzRange);
final double queryRange = RangeUtils.rangeLength(mzRange) / 2.0;
// Get security token.
final String apiKey = parameters.getParameter(ChemSpiderParameters.SECURITY_TOKEN).getValue();
try {
FilterByMassRequest filterRequest = new FilterByMassRequest();
filterRequest.setMass(queryMz);
filterRequest.setRange(queryRange);
filterRequest.setOrderBy(OrderByEnum.RECORDID);
FilteringApi apiInstance = new FilteringApi();
apiInstance.getApiClient().setUserAgent("MZmine " + MZmineCore.getMZmineVersion());
FilterQueryResponse queryId = apiInstance.filterMassPost(filterRequest, apiKey);
QueryResultResponse result = apiInstance.filterQueryIdResultsGet(queryId.getQueryId(), apiKey, 0, numOfResults);
List<Integer> integerIDs = result.getResults();
List<String> stringIDs = Lists.transform(integerIDs, Functions.toStringFunction());
return stringIDs.toArray(new String[0]);
} catch (ApiException e) {
throw new IOException(e);
}
}
Aggregations