- * Answers the value of 'attribute' from the JSON response, or null if not
- * found
- *
- * @param br
- * @param attribute
- * @return
- */
- protected String getAttribute(BufferedReader br, String attribute)
- {
- String value = null;
- JSONParser jp = new JSONParser();
- try
- {
- JSONObject val = (JSONObject) jp.parse(br);
- value = val.get(attribute).toString();
- } catch (ParseException | NullPointerException | IOException e)
- {
- // ignore
- }
- return value;
- }
-
- /**
- * Parses the JSON response and returns the gene identifier, or null if not
- * found. If the returned object_type is Gene, returns the id, if Transcript
- * returns the Parent. If it is Translation (peptide identifier), then the
- * Parent is the transcript identifier, so we redo the search with this value,
- * specifying that object_type should be Transcript.
- *
- * @param br
- * @return
- */
- protected String parseGeneId(BufferedReader br)
- {
- String geneId = null;
- JSONParser jp = new JSONParser();
- try
- {
- JSONObject val = (JSONObject) jp.parse(br);
- String type = val.get(OBJECT_TYPE).toString();
- if (OBJECT_TYPE_GENE.equalsIgnoreCase(type))
- {
- // got the gene - just returns its id
- geneId = val.get(JSON_ID).toString();
- }
- else if (OBJECT_TYPE_TRANSCRIPT.equalsIgnoreCase(type))
- {
- // got the transcript - return its (Gene) Parent
- geneId = val.get(PARENT).toString();
- }
- else if (OBJECT_TYPE_TRANSLATION.equalsIgnoreCase(type))
- {
- // got the protein - get its Parent, restricted to type Transcript
- String transcriptId = val.get(PARENT).toString();
- geneId = (String) getResult(transcriptId, OBJECT_TYPE_TRANSCRIPT,
- reader -> parseGeneId(reader));
- }
- } catch (ParseException | IOException e)
- {
- // ignore
- }
- return geneId;
- }
-
- /**