List of usage examples for org.apache.solr.client.solrj SolrQuery setQuery
public SolrQuery setQuery(String query)
From source file:edu.vt.vbi.patric.common.DataApiHandler.java
License:Apache License
/** * wrapper function of field facet query * * @param core SolrCore/*from w w w .ja v a 2 s . c o m*/ * @param queryParam query condition * @param filterParam filter condition * @param facetFields comma separated list of fields */ public Map getFieldFacets(SolrCore core, String queryParam, String filterParam, String facetFields) throws IOException { Map<String, Object> res = new HashMap<>(); SolrQuery query = new SolrQuery(); query.setQuery(queryParam); if (filterParam != null) { query.addFilterQuery(filterParam); } query.setRows(0).setFacet(true).setFacetLimit(-1).setFacetMinCount(1) .setFacetSort(FacetParams.FACET_SORT_COUNT).set("json.nl", "map"); query.addFacetField(facetFields.split(",")); List<String> fields = Arrays.asList(facetFields.split(",")); LOGGER.trace("getFieldFacets: [{}] {}", core.getSolrCoreName(), query.toString()); String response = this.solrQuery(core, query); Map resp = jsonParser.readValue(response); Map facet_fields = (Map) ((Map) resp.get("facet_counts")).get("facet_fields"); Map<String, Object> facets = new HashMap<>(); for (String field : fields) { Map values = (Map) facet_fields.get(field); Map<String, Integer> facetValues = new LinkedHashMap<>(); for (Map.Entry<String, Integer> entry : (Iterable<Map.Entry>) values.entrySet()) { facetValues.put(entry.getKey(), entry.getValue()); } facets.put(field, facetValues); } res.put("total", ((Map) resp.get("response")).get("numFound")); res.put("facets", facets); return res; }
From source file:edu.vt.vbi.patric.common.DataApiHandler.java
License:Apache License
/** * wrapper function of pivot facet query * * @param core SolrCore/*ww w . j a v a 2 s . c o m*/ * @param queryParam query condition * @param filterParam filter condition * @param facetFields comma separated list of fields */ public Map getPivotFacets(SolrCore core, String queryParam, String filterParam, String facetFields) throws IOException { Map<String, Object> res = new HashMap<>(); SolrQuery query = new SolrQuery(); query.setQuery(queryParam); if (filterParam != null) { query.addFilterQuery(filterParam); } query.setRows(0).setFacet(true).setFacetLimit(-1).setFacetMinCount(1) .setFacetSort(FacetParams.FACET_SORT_INDEX); query.addFacetPivotField(facetFields); LOGGER.trace("getPivotFacets: [{}] {}", core.getSolrCoreName(), query.toString()); String response = this.solrQuery(core, query); Map<String, Object> resp = jsonParser.readValue(response); Map facet_fields = (Map) ((Map) resp.get("facet_counts")).get("facet_pivot"); List<Map> values = (List) facet_fields.get(facetFields); Map<String, Object> facet = new LinkedHashMap<>(); for (Map value : values) { String localKey = value.get("value").toString(); List<Map> localValues = (List) value.get("pivot"); Map<String, Integer> pivotValues = new LinkedHashMap<>(); for (Map local : localValues) { pivotValues.put(local.get("value").toString(), (Integer) local.get("count")); } facet.put(localKey, pivotValues); } res.put("total", ((Map) resp.get("response")).get("numFound")); res.put(facetFields, facet); return res; }
From source file:edu.vt.vbi.patric.common.DataApiHandler.java
License:Apache License
public SolrQuery buildSolrQuery(Map<String, String> key, String sorts, String facets, int start, int end, boolean highlight) { SolrQuery query = new SolrQuery(); SolrInterface solr = new SolrInterface(); // Processing key map query.setQuery(StringHelper.stripQuoteAndParseSolrKeywordOperator(key.get("keyword"))); if (key.containsKey("filter") && key.get("filter") != null) { query.addFilterQuery(key.get("filter")); }//w ww . j a v a 2 s.c o m if (key.containsKey("filter2") && key.get("filter2") != null) { query.addFilterQuery(key.get("filter2")); } // use SolrJoin if possible if (key.containsKey("join")) { query.addFilterQuery(key.get("join")); } if (key.containsKey("fields") && !key.get("fields").equals("")) { query.addField(key.get("fields")); } // sort conditions if (sorts != null && !sorts.equals("") && !sorts.equals("[]")) { try { JSONArray sorter = (JSONArray) new JSONParser().parse(sorts); for (Object aSort : sorter) { JSONObject jsonSort = (JSONObject) aSort; query.addSort(SolrQuery.SortClause.create(jsonSort.get("property").toString(), jsonSort.get("direction").toString().toLowerCase())); } } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } } // facet conditions if (facets != null && !facets.equals("") && !facets.equals("{}")) { query.setFacet(true).setFacetMinCount(1).setFacetLimit(-1).setFacetSort(FacetParams.FACET_SORT_COUNT) .set("json.nl", "map"); try { JSONObject facetConditions = (JSONObject) new JSONParser().parse(facets); if (facetConditions.containsKey("facet.sort")) { String facetSort = facetConditions.get("facet.sort").toString(); if (facetSort.equals("index")) { query.setFacetSort(FacetParams.FACET_SORT_INDEX); } } if (facetConditions.containsKey("field_facets")) { String[] fieldFacets = facetConditions.get("field_facets").toString().split(","); query.addFacetField(fieldFacets); } if (facetConditions.containsKey("date_range_facets") && !facetConditions.get("date_range_facets").equals("")) { String[] dateRangeFacets = facetConditions.get("date_range_facets").toString().split(","); for (String field : dateRangeFacets) { query.addDateRangeFacet(field, solr.getRangeStartDate(), solr.getRangeEndDate(), solr.getRangeDate()); } } } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } } // start & end query.setStart(start); // setting starting index if (end == -1) { query.setRows(MAX_ROWS); } else { query.setRows(end); } // highlight if (highlight) { query.set("hl", "on").set("hl.fl", "*"); } return query; }
From source file:edu.vt.vbi.patric.common.FacetHelper.java
License:Apache License
private static JSONObject getSingleFacetsData(DataApiHandler dataApi, SolrCore core, String keyword, String single_facet, String[] facets, String fq) throws IOException, ParseException { SolrInterface solr = new SolrInterface(); keyword = StringHelper.stripQuoteAndParseSolrKeywordOperator(keyword); int beginindex = keyword.indexOf(" AND (" + single_facet); int endindex = 0; StringBuffer s = new StringBuffer(keyword); if (beginindex < 0) { beginindex = keyword.indexOf("(" + single_facet); endindex = keyword.indexOf(") AND ", beginindex); if (endindex < 0) { endindex = keyword.indexOf("))", beginindex); // TODO: this cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1 // when Patric Libs keyword - (*) and endindex: 2 LOGGER.debug("string:{}, beginIndex: {}, endIndex:{}", s, beginindex, endindex); if (endindex > 0) { s.delete(beginindex, endindex + 2); }/* w ww . j a va 2 s . c o m*/ } else { s.delete(beginindex, endindex + 6); } } else { endindex = keyword.indexOf("))", beginindex); if (endindex == -1) { endindex = keyword.indexOf("])", beginindex); } s.delete(beginindex, endindex + 2); } if (s.length() == 0) s.append("(*)"); SolrQuery query = new SolrQuery(); query.setQuery(s.toString()); if (fq != null) { query.setFilterQueries(fq); } query.setStart(0).setRows(1).setFacet(true).setFacetMinCount(1).set("json.nl", "map"); for (String facet : facets) { if (!facet.equals("completion_date") && !facet.equals("release_date")) { query.addFacetField(facet); } else { query.addDateRangeFacet(facet, solr.getRangeStartDate(), solr.getRangeEndDate(), solr.getRangeDate()); } } String apiResponse = dataApi.solrQuery(core, query); Map resp = jsonMapReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); JSONObject ret = new JSONObject(); ret.put("response", new JSONObject(respBody)); ret.put("facets", FacetHelper.formatFacetTree((Map) resp.get("facet_counts"))); return ret; }
From source file:edu.vt.vbi.patric.common.SolrInterface.java
License:Apache License
public String getProteomicsTaxonIdFromFeatureId(String id) { SolrQuery query = new SolrQuery(); query.setQuery("na_feature_id:" + id); query.setRows(1000000);/*from w ww .j ava 2s . c o m*/ String experiment_id = ""; // try { // QueryResponse qr = server.query(query); // SolrDocumentList sdl = qr.getResults(); // // for (SolrDocument d : sdl) { // for (Entry<String, Object> el : d) { // if (el.getKey().equals("experiment_id")) { // if (experiment_id.length() == 0) // experiment_id = el.getValue().toString(); // else // experiment_id += "##" + el.getValue().toString(); // } // } // } // } // catch (SolrServerException e) { // e.printStackTrace(); // } return experiment_id; }
From source file:edu.vt.vbi.patric.portlets.CompPathwayTable.java
License:Apache License
@SuppressWarnings("unchecked") private JSONObject processEcNumberTab(DataApiHandler dataApi, String pathwayClass, String pathwayId, String ecNumber, String annotation, String contextType, String contextId) throws PortletException, IOException { JSONObject jsonResult = new JSONObject(); SolrQuery query = new SolrQuery("*:*"); if (pathwayClass != null && !pathwayClass.equals("")) { query.addFilterQuery("pathway_class:" + pathwayClass); }//from w w w. jav a 2 s . c o m if (pathwayId != null && !pathwayId.equals("")) { query.addFilterQuery("pathway_id:" + pathwayId); } if (ecNumber != null && !ecNumber.equals("")) { query.addFilterQuery("ec_number:" + ecNumber); } if (annotation != null && !annotation.equals("")) { query.addFilterQuery("annotation:" + annotation); } if (contextType.equals("genome")) { query.addFilterQuery( SolrCore.GENOME.getSolrCoreJoin("genome_id", "genome_id", "genome_id:" + contextId)); } else if (contextType.equals("taxon")) { query.addFilterQuery( SolrCore.GENOME.getSolrCoreJoin("genome_id", "genome_id", "taxon_lineage_ids:" + contextId)); } JSONArray items = new JSONArray(); int count_total = 0; int count_unique = 0; try { Set<String> listPathwayIds = new HashSet<>(); Set<String> listEcNumbers = new HashSet<>(); // get pathway stat query.setRows(0).setFacet(true); query.add("json.facet", "{stat:{field:{field:pathway_ec,limit:-1,facet:{genome_count:\"unique(genome_id)\",gene_count:\"unique(feature_id)\",ec_count:\"unique(ec_number)\"}}}}"); LOGGER.trace("[{}] {}", SolrCore.PATHWAY.getSolrCoreName(), query); String apiResponse = dataApi.solrQuery(SolrCore.PATHWAY, query); Map resp = jsonReader.readValue(apiResponse); List<Map> buckets = (List<Map>) ((Map) ((Map) resp.get("facets")).get("stat")).get("buckets"); Map<String, Map> mapStat = new HashMap<>(); for (Map value : buckets) { if (!value.get("genome_count").toString().equals("0")) { mapStat.put(value.get("val").toString(), value); String[] pathway_ec = value.get("val").toString().split("_"); listPathwayIds.add(pathway_ec[0]); listEcNumbers.add(pathway_ec[1]); } } // get pathway list SolrQuery pathwayQuery = new SolrQuery("*:*"); if (!listPathwayIds.isEmpty()) { pathwayQuery.setQuery("pathway_id:(" + StringUtils.join(listPathwayIds, " OR ") + ")"); pathwayQuery.setFields("pathway_id,pathway_name,pathway_class,ec_number,ec_description"); pathwayQuery.setRows(Math.max(dataApi.MAX_ROWS, listPathwayIds.size())); LOGGER.trace("[{}] {}", SolrCore.PATHWAY_REF.getSolrCoreName(), pathwayQuery); apiResponse = dataApi.solrQuery(SolrCore.PATHWAY_REF, pathwayQuery); resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); List<Map> sdl = (List<Map>) respBody.get("docs"); for (Map doc : sdl) { String aPathwayId = doc.get("pathway_id").toString(); String aEcNumber = doc.get("ec_number").toString(); Map stat = mapStat.get(aPathwayId + "_" + aEcNumber); if (stat != null && !stat.get("genome_count").toString().equals("0")) { JSONObject item = new JSONObject(); item.put("pathway_id", aPathwayId); item.put("pathway_name", doc.get("pathway_name")); item.put("pathway_class", doc.get("pathway_class")); float genome_count = Float.parseFloat(stat.get("genome_count").toString()); float gene_count = Float.parseFloat(stat.get("gene_count").toString()); item.put("ec_name", doc.get("ec_description")); item.put("ec_number", doc.get("ec_number")); item.put("gene_count", gene_count); item.put("genome_count", genome_count); item.put("algorithm", annotation); items.add(item); } } count_total = items.size(); count_unique = listEcNumbers.size(); } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } // Wrapping jsonResult jsonResult.put("total", count_total); jsonResult.put("results", items); jsonResult.put("unique", count_unique); return jsonResult; }
From source file:edu.vt.vbi.patric.portlets.Downloads.java
License:Apache License
public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { String mode = request.getParameter("mode"); if (mode.equals("getGenomeCount")) { String taxonId = request.getParameter("taxonId"); String dataSource = request.getParameter("data_source"); DataApiHandler dataApi = new DataApiHandler(request); SolrQuery query = new SolrQuery(); if (taxonId != null) { query.setQuery("taxon_lineage_ids:" + taxonId); } else {//from w ww .j a v a 2 s. c o m query.setQuery("*:*"); } if (dataSource != null) { String[] sources = dataSource.split(","); List<String> conditions = new ArrayList<>(); for (String source : sources) { switch (source) { case ".PATRIC": conditions.add("patric_cds:[1 TO *]"); break; case ".RefSeq": conditions.add("refseq_cds:[1 TO *]"); break; } } query.setFilterQueries(StringUtils.join(conditions, " OR ")); } query.setRows(0); LOGGER.debug("[{}] {}", SolrCore.GENOME, query.toString()); String apiResponse = dataApi.solrQuery(SolrCore.GENOME, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); int numFound = (Integer) respBody.get("numFound"); response.getWriter().write("" + numFound); } else if (mode.equals("download")) { String genomeId = request.getParameter("genomeId"); String taxonId = request.getParameter("taxonId"); String fileTypes = request.getParameter("finalfiletype"); String annotations = request.getParameter("finalalgorithm"); Logger LOGGER = LoggerFactory.getLogger(CreateZip.class); List<String> genomeIdList = new LinkedList<>(); DataApiHandler dataApi = new DataApiHandler(request); SolrQuery query = new SolrQuery("*:*"); if (genomeId != null && !genomeId.equals("")) { query.addFilterQuery("genome_id:(" + genomeId.replaceAll(",", " OR ") + ")"); } if (taxonId != null && !taxonId.equals("")) { query.addFilterQuery("taxon_lineage_ids:" + taxonId); } query.setRows(dataApi.MAX_ROWS).addField("genome_id"); LOGGER.debug("[{}] {}", SolrCore.GENOME, query.toString()); String apiResponse = dataApi.solrQuery(SolrCore.GENOME, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); List<Genome> genomeList = dataApi.bindDocuments((List<Map>) respBody.get("docs"), Genome.class); for (Genome genome : genomeList) { genomeIdList.add(genome.getId()); } CreateZip zip = new CreateZip(); byte[] bytes = zip.ZipIt(genomeIdList, Arrays.asList(annotations.split(",")), Arrays.asList(fileTypes.split(","))); if (bytes.length > 0) { response.setContentType("application/octetstream"); response.setProperty("Cache-Control", "cache"); response.setProperty("Content-Disposition", "attachment; filename=\"patric_downloads.zip\""); response.setContentLength(bytes.length); response.getPortletOutputStream().write(bytes); } else { response.getWriter().write("Sorry. The requested file(s) are not available."); } } }
From source file:edu.vt.vbi.patric.portlets.ExperimentListPortlet.java
License:Apache License
@Override protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); SiteHelper.setHtmlMetaElements(request, response, "Experiment List"); response.setTitle("Experiment List"); String cType = request.getParameter("context_type"); String cId = request.getParameter("context_id"); if (cType != null && cId != null) { String kw = (request.getParameter("keyword") != null) ? request.getParameter("keyword") : ""; if (kw != null && (kw.startsWith("/") || kw.startsWith("#"))) { kw = ""; }// ww w . j av a 2 s. c o m String keyword = "(*)"; String filter; String eid; if (cType.equals("taxon") && cId.equals("2")) { filter = "*"; eid = ""; } else { DataApiHandler dataApi = new DataApiHandler(request); List<String> items = new ArrayList<>(); SolrQuery query = new SolrQuery(); if (cType.equals("taxon")) { query.setQuery("*:*"); query.setFilterQueries( SolrCore.GENOME.getSolrCoreJoin("genome_id", "genome_ids", "taxon_lineage_ids:" + cId)); } else if (cType.equals("genome")) { query = new SolrQuery("genome_ids:" + cId); } query.setRows(10000).setFields("eid"); String apiResponse = dataApi.solrQuery(SolrCore.TRANSCRIPTOMICS_EXPERIMENT, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); List<Map> sdl = (List<Map>) respBody.get("docs"); for (Map doc : sdl) { items.add(doc.get("eid").toString()); } if (items.size() > 0) { eid = StringUtils.join(items, "##"); } else { eid = "0"; } filter = eid; } request.setAttribute("keyword", keyword); request.setAttribute("kw", kw); request.setAttribute("eid", eid); request.setAttribute("filter", filter); PortletRequestDispatcher prd = getPortletContext() .getRequestDispatcher("/WEB-INF/jsp/experiment/list.jsp"); prd.include(request, response); } }
From source file:edu.vt.vbi.patric.portlets.GenomeBrowser.java
License:Apache License
private void printRefSeqInfo(ResourceRequest request, ResourceResponse response) throws IOException { String contextType = request.getParameter("cType"); String contextId = request.getParameter("cId"); DataApiHandler dataApi = new DataApiHandler(request); SolrQuery query = new SolrQuery(); if (contextType.equals("genome")) { query.setQuery("genome_id:" + contextId); } else if (contextType.equals("feature")) { query.setQuery(SolrCore.FEATURE.getSolrCoreJoin("genome_id", "genome_id", "feature_id:" + contextId)); }/* w ww . j a va 2 s. c o m*/ query.setRows(dataApi.MAX_ROWS).addSort("accession", SolrQuery.ORDER.asc); JSONArray jsonResult = new JSONArray(); LOGGER.trace("[{}] {}", SolrCore.SEQUENCE.getSolrCoreName(), query.toString()); String apiResponse = dataApi.solrQuery(SolrCore.SEQUENCE, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); List<GenomeSequence> sequences = dataApi.bindDocuments((List<Map>) respBody.get("docs"), GenomeSequence.class); for (GenomeSequence sequence : sequences) { JSONObject seq = new JSONObject(); seq.put("length", sequence.getLength()); seq.put("name", sequence.getAccession()); seq.put("accn", sequence.getAccession()); // seq.put("sid", sequence.getId()); seq.put("sid", sequence.getGenomeId()); seq.put("start", 0); seq.put("end", sequence.getLength()); seq.put("seqDir", ""); seq.put("seqChunkSize", sequence.getLength()); jsonResult.add(seq); } // TODO: remove this when data API limit is removed int i = 1; while (sequences.size() == 25000) { query.setStart(25000 * i); apiResponse = dataApi.solrQuery(SolrCore.SEQUENCE, query); resp = jsonReader.readValue(apiResponse); respBody = (Map) resp.get("response"); sequences = dataApi.bindDocuments((List<Map>) respBody.get("docs"), GenomeSequence.class); for (GenomeSequence sequence : sequences) { JSONObject seq = new JSONObject(); seq.put("length", sequence.getLength()); seq.put("name", sequence.getAccession()); seq.put("accn", sequence.getAccession()); seq.put("sid", sequence.getGenomeId()); seq.put("start", 0); seq.put("end", sequence.getLength()); seq.put("seqDir", ""); seq.put("seqChunkSize", sequence.getLength()); jsonResult.add(seq); } i++; } response.setContentType("application/json"); jsonResult.writeJSONString(response.getWriter()); response.getWriter().close(); }
From source file:edu.vt.vbi.patric.portlets.PathwayFinder.java
License:Apache License
@SuppressWarnings("unchecked") private JSONObject processPathwayTab(DataApiHandler dataApi, String pathwayId, String ecNumber, String annotation, String taxonId, String genomeId, String keyword) throws PortletException, IOException { JSONObject jsonResult = new JSONObject(); SolrQuery query = new SolrQuery("*:*"); if (pathwayId != null && !pathwayId.equals("")) { query.addFilterQuery("pathway_id:" + pathwayId); }//from w w w .j a v a 2 s . co m if (ecNumber != null && !ecNumber.equals("")) { query.addFilterQuery("ec_number:" + ecNumber); } if (annotation != null && !annotation.equals("") && !annotation.equalsIgnoreCase("ALL")) { query.addFilterQuery("annotation:" + annotation); } if (taxonId != null && !taxonId.equals("")) { query.addFilterQuery( SolrCore.GENOME.getSolrCoreJoin("genome_id", "genome_id", "taxon_lineage_ids:" + taxonId)); } if (genomeId != null && !genomeId.equals("")) { query.addFilterQuery(SolrCore.GENOME.getSolrCoreJoin("genome_id", "genome_id", "genome_id:(" + genomeId.replaceAll(",", " OR ") + ")")); } if (keyword != null && !keyword.equals("")) { query.setQuery(keyword); } JSONArray items = new JSONArray(); int count_total = 0; int count_unique = 0; try { Set<String> listPathwayIds = new HashSet<>(); Map<String, JSONObject> uniquePathways = new HashMap<>(); // get pathway stat query.setRows(0).setFacet(true); query.add("json.facet", "{stat:{field:{field:pathway_id,limit:-1,facet:{genome_count:\"unique(genome_id)\",gene_count:\"unique(feature_id)\",ec_count:\"unique(ec_number)\",genome_ec:\"unique(genome_ec)\"}}}}"); LOGGER.trace("processPathwayTab: [{}] {}", SolrCore.PATHWAY.getSolrCoreName(), query); String apiResponse = dataApi.solrQuery(SolrCore.PATHWAY, query); Map resp = jsonReader.readValue(apiResponse); List<Map> buckets = (List<Map>) ((Map) ((Map) resp.get("facets")).get("stat")).get("buckets"); Map<String, Map> mapStat = new HashMap<>(); for (Map value : buckets) { mapStat.put(value.get("val").toString(), value); listPathwayIds.add(value.get("val").toString()); } if (!listPathwayIds.isEmpty()) { // get pathway list SolrQuery pathwayQuery = new SolrQuery( "pathway_id:(" + StringUtils.join(listPathwayIds, " OR ") + ")"); pathwayQuery.setFields("pathway_id,pathway_name,pathway_class"); pathwayQuery.setRows(Math.max(dataApi.MAX_ROWS, listPathwayIds.size())); LOGGER.trace("processPathwayTab: [{}] {}", SolrCore.PATHWAY_REF.getSolrCoreName(), pathwayQuery); apiResponse = dataApi.solrQuery(SolrCore.PATHWAY_REF, pathwayQuery); resp = jsonReader.readValue(apiResponse); Map respBody = (Map) resp.get("response"); List<Map> sdl = (List<Map>) respBody.get("docs"); for (Map doc : sdl) { String aPathwayId = doc.get("pathway_id").toString(); Map stat = mapStat.get(aPathwayId); if (!uniquePathways.containsKey(aPathwayId) && !stat.get("genome_count").toString().equals("0")) { JSONObject item = new JSONObject(); item.put("pathway_id", aPathwayId); item.put("pathway_name", doc.get("pathway_name")); item.put("pathway_class", doc.get("pathway_class")); float genome_ec = Float.parseFloat(stat.get("genome_ec").toString()); float genome_count = Float.parseFloat(stat.get("genome_count").toString()); float ec_count = Float.parseFloat(stat.get("ec_count").toString()); float gene_count = Float.parseFloat(stat.get("gene_count").toString()); float ec_cons = 0; float gene_cons = 0; if (genome_count > 0 && ec_count > 0) { ec_cons = genome_ec / genome_count / ec_count * 100; gene_cons = gene_count / genome_count / ec_count; } item.put("ec_cons", ec_cons); item.put("ec_count", ec_count); item.put("gene_cons", gene_cons); item.put("gene_count", gene_count); item.put("genome_count", genome_count); item.put("algorithm", annotation); uniquePathways.put(aPathwayId, item); } } for (Map.Entry<String, JSONObject> pathway : uniquePathways.entrySet()) { items.add(pathway.getValue()); } count_total = uniquePathways.entrySet().size(); count_unique = count_total; } } catch (IOException e) { LOGGER.error(e.getMessage(), e); } // Wrapping jsonResult try { jsonResult.put("total", count_total); jsonResult.put("results", items); jsonResult.put("unique", count_unique); } catch (Exception ex) { LOGGER.error(ex.getMessage(), ex); } return jsonResult; }