From d431fb5ea35e3c49dff193764916a21fa6496bdf Mon Sep 17 00:00:00 2001 From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04> Date: Thu, 3 Sep 2009 10:44:13 +0000 Subject: [PATCH] add getChadoGeneByAnyCurrentName() git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@11694 ee4ac58c-ac51-4696-9907-e4b3aa274f04 --- .../sanger/artemis/util/DatabaseDocument.java | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/uk/ac/sanger/artemis/util/DatabaseDocument.java b/uk/ac/sanger/artemis/util/DatabaseDocument.java index 32aa38328..7751d4a73 100644 --- a/uk/ac/sanger/artemis/util/DatabaseDocument.java +++ b/uk/ac/sanger/artemis/util/DatabaseDocument.java @@ -999,7 +999,7 @@ public class DatabaseDocument extends Document final List schema_search, GmodDAO dao, final boolean readChildren) - throws SQLException, ReadFormatException, ConnectException + throws SQLException, ReadFormatException, ConnectException, IOException { CvTermThread cvThread = null; if(DatabaseDocument.cvterms == null) @@ -1028,8 +1028,11 @@ public class DatabaseDocument extends Document else reset((String)getLocation(), (String)schema_search.get(0)); dao = getDAO(); - Feature chadoFeature = - (Feature)(dao.getFeaturesByUniqueName(search_gene).get(0)); + + List features = dao.getFeaturesByUniqueName(search_gene); + if(features == null || features.size() == 0) + throw new IOException(); + Feature chadoFeature = (Feature)(features.get(0)); ChadoCanonicalGene chado_gene = new ChadoCanonicalGene(); id_store.put(Integer.toString(chadoFeature.getFeatureId()), @@ -2099,6 +2102,31 @@ public class DatabaseDocument extends Document return feature; } + /** + * Find the gene by the ID or synonym on the gene or transcript. + * @param id + * @return + */ + public Feature getChadoGeneByAnyCurrentName(String id) + { + Feature chadoFeature = + (Feature)(getDAOOnly().getFeaturesByAnyCurrentName(id).get(0)); + + if(!chadoFeature.getCvTerm().equals("gene")) + { + Iterator<FeatureRelationship> parents = + chadoFeature.getFeatureRelationshipsForSubjectId().iterator(); + while(parents.hasNext()) + { + FeatureRelationship fr = parents.next(); + Feature parent = fr.getFeatureByObjectId(); + if(parent.getCvTerm().getName().equals("gene")) + chadoFeature = parent; + } + } + return chadoFeature; + } + /** * Get the sequence for a feature. -- GitLab