diff --git a/uk/ac/sanger/artemis/util/DatabaseDocument.java b/uk/ac/sanger/artemis/util/DatabaseDocument.java index 32aa3832882b2b86a14abc15e1af13d9a5871493..7751d4a73e25e770f03733e30cce87991709e2fa 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.