canonicalSourceNameLookup.put("pdb", DBRefSource.PDB);
canonicalSourceNameLookup.put("ensembl", DBRefSource.ENSEMBL);
+ // Ensembl Gn and Tr are for Ensembl genomic and transcript IDs as served
+ // from ENA.
+ canonicalSourceNameLookup.put("ensembl-tr", DBRefSource.ENSEMBL);
+ canonicalSourceNameLookup.put("ensembl-gn", DBRefSource.ENSEMBL);
+
dasCoordinateSystemsLookup.put("pdbresnum", DBRefSource.PDB);
dasCoordinateSystemsLookup.put("uniprot", DBRefSource.UNIPROT);
}
/**
+ * Returns those DBRefEntry objects whose source identifier (once converted to
+ * Jalview's canonical form) is in the list of sources to search for. Returns
+ * null if no matches found.
*
* @param dbrefs
- * array of DBRef objects to search
+ * DBRefEntry objects to search
* @param sources
- * String[] array of source DBRef IDs to retrieve
+ * array of sources to select
* @return
*/
public static DBRefEntry[] selectRefs(DBRefEntry[] dbrefs,
}
/**
- * Returns an array of those references that match the given entry, or null if
- * no matches. Currently uses a comparator which matches if
+ * Returns a (possibly empty) list of those references that match the given
+ * entry. Currently uses a comparator which matches if
* <ul>
* <li>database sources are the same</li>
* <li>accession ids are the same</li>
* pattern to match
* @return
*/
- public static DBRefEntry[] searchRefs(DBRefEntry[] ref, DBRefEntry entry)
+ public static List<DBRefEntry> searchRefs(DBRefEntry[] ref,
+ DBRefEntry entry)
{
return searchRefs(ref, entry,
matchDbAndIdAndEitherMapOrEquivalentMapList);
}
/**
- * Returns an array of those references that match the given accession id
+ * Returns a list of those references that match the given accession id
* <ul>
* <li>database sources are the same</li>
* <li>accession ids are the same</li>
* <li>both have no mapping, or the mappings are the same</li>
* </ul>
*
- * @param ref
+ * @param refs
* Set of references to search
- * @param entry
- * pattern to match
+ * @param accId
+ * accession id to match
* @return
*/
- public static DBRefEntry[] searchRefs(DBRefEntry[] ref, String accId)
+ public static List<DBRefEntry> searchRefs(DBRefEntry[] refs, String accId)
{
- return searchRefs(ref, new DBRefEntry("", "", accId), matchId);
+ return searchRefs(refs, new DBRefEntry("", "", accId), matchId);
}
/**
- * Returns an array of those references that match the given entry, according
- * to the given comparator. Returns null if no matches.
+ * Returns a (possibly empty) list of those references that match the given
+ * entry, according to the given comparator.
*
* @param refs
* an array of database references to search
* @param comparator
* @return
*/
- static DBRefEntry[] searchRefs(DBRefEntry[] refs, DBRefEntry entry,
+ static List<DBRefEntry> searchRefs(DBRefEntry[] refs, DBRefEntry entry,
DbRefComp comparator)
{
+ List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
if (refs == null || entry == null)
{
- return null;
+ return rfs;
}
- List<DBRefEntry> rfs = new ArrayList<DBRefEntry>();
for (int i = 0; i < refs.length; i++)
{
if (comparator.matches(entry, refs[i]))
rfs.add(refs[i]);
}
}
- return rfs.size() == 0 ? null : rfs.toArray(new DBRefEntry[rfs.size()]);
+ return rfs;
}
interface DbRefComp
};
/**
- * accession ID and DB must be identical. Version is ignored. No map on either
- * or map but no maplist on either or maplist of map on a is equivalent to the
- * maplist of map on b.
+ * accession ID and DB must be identical, or null on a. Version is ignored. No
+ * map on either or map but no maplist on either or maplist of map on a is
+ * equivalent to the maplist of map on b.
*/
public static DbRefComp matchDbAndIdAndEitherMapOrEquivalentMapList = new DbRefComp()
{
&& refb.getSource().equals(refa.getSource()))
{
// We dont care about version
- if (refa.getAccessionId() != null && refb.getAccessionId() != null
- && refb.getAccessionId().equals(refa.getAccessionId()))
+
+ if (refa.getAccessionId() == null
+ || refa.getAccessionId().equals(refb.getAccessionId()))
{
if (refa.getMap() == null || refb.getMap() == null)
{
|| (refb.getMap().getMap() != null
&& refa.getMap().getMap() != null && (refb
.getMap().getMap().equals(refa.getMap().getMap()))))
- { // getMap().getMap().containsEither(false,refa.getMap().getMap())
+ {
return true;
}
}
return (o1 == null ? o2.equals(o1) : o1.equals(o2));
}
+ /**
+ * Selects just the DNA or protein references from a set of references
+ *
+ * @param selectDna
+ * if true, select references to 'standard' DNA databases, else to
+ * 'standard' peptide databases
+ * @param refs
+ * a set of references to select from
+ * @return
+ */
+ public static DBRefEntry[] selectDbRefs(boolean selectDna,
+ DBRefEntry[] refs)
+ {
+ return selectRefs(refs, selectDna ? DBRefSource.DNACODINGDBS
+ : DBRefSource.PROTEINDBS);
+ // could attempt to find other cross
+ // refs here - ie PDB xrefs
+ // (not dna, not protein seq)
+ }
+
+ /**
+ * Returns the (possibly empty) list of those supplied dbrefs which have the
+ * specified source database, with a case-insensitive match of source name
+ *
+ * @param dbRefs
+ * @param source
+ * @return
+ */
+ public static List<DBRefEntry> searchRefsForSource(DBRefEntry[] dbRefs,
+ String source)
+ {
+ List<DBRefEntry> matches = new ArrayList<DBRefEntry>();
+ if (dbRefs != null && source != null)
+ {
+ for (DBRefEntry dbref : dbRefs)
+ {
+ if (source.equalsIgnoreCase(dbref.getSource()))
+ {
+ matches.add(dbref);
+ }
+ }
+ }
+ return matches;
+ }
+
}