+ * Converts a query, which may contain one or more gene or transcript
+ * identifiers, into a non-redundant list of gene identifiers.
+ *
+ * @param accessions
+ * @return
+ */
+ List<String> getGeneIds(String accessions)
+ {
+ List<String> geneIds = new ArrayList<String>();
+
+ for (String acc : accessions.split(getAccessionSeparator()))
+ {
+ if (isGeneIdentifier(acc))
+ {
+ if (!geneIds.contains(acc))
+ {
+ geneIds.add(acc);
+ }
+ }
+
+ /*
+ * if given a transcript id, look up its gene parent
+ */
+ else if (isTranscriptIdentifier(acc))
+ {
+ String geneId = new EnsemblLookup(getDomain()).getParent(acc);
+ if (geneId != null && !geneIds.contains(geneId))
+ {
+ geneIds.add(geneId);
+ }
+ }
+ else if (isProteinIdentifier(acc))
+ {
+ String tscriptId = new EnsemblLookup(getDomain()).getParent(acc);
+ if (tscriptId != null)
+ {
+ String geneId = new EnsemblLookup(getDomain())
+ .getParent(tscriptId);
+
+ if (geneId != null && !geneIds.contains(geneId))
+ {
+ geneIds.add(geneId);
+ }
+ }
+ // NOTE - acc is lost if it resembles an ENS.+ ID but isn't actually
+ // resolving to one... e.g. ENSMICP00000009241
+ }
+ /*
+ * if given a gene or other external name, lookup and fetch
+ * the corresponding gene for all model organisms
+ */
+ else
+ {
+ List<String> ids = new EnsemblSymbol(getDomain(), getDbSource(),
+ getDbVersion()).getIds(acc);
+ for (String geneId : ids)
+ {
+ if (!geneIds.contains(geneId))
+ {
+ geneIds.add(geneId);
+ }
+ }
+ }
+ }
+ return geneIds;
+ }
+
+ /**
+ * Attempts to get Ensembl stable identifiers for model organisms for a gene
+ * name by calling the xrefs symbol REST service to resolve the gene name.
+ *
+ * @param query
+ * @return
+ */
+ protected String getGeneIdentifiersForName(String query)
+ {
+ List<String> ids = new EnsemblSymbol(getDomain(), getDbSource(),
+ getDbVersion()).getIds(query);
+ if (ids != null)
+ {
+ for (String id : ids)
+ {
+ if (isGeneIdentifier(id))
+ {
+ return id;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**