uk.ac.ebi.ep.mm
Class MegaJdbcMapper

java.lang.Object
  extended by uk.ac.ebi.ep.mm.MegaJdbcMapper
All Implemented Interfaces:
MegaMapper

public class MegaJdbcMapper
extends Object
implements MegaMapper

Plain JDBC implementation of MegaMapper.

Author:
rafa

Nested Class Summary
 
Nested classes/interfaces inherited from interface uk.ac.ebi.ep.mm.MegaMapper
MegaMapper.Constraint
 
Field Summary
static String[] ILLEGAL_COMPOUND
           
 
Constructor Summary
MegaJdbcMapper(Connection con)
           
 
Method Summary
 void closeMap()
          Closes the mega-map.
 void commit()
          Commits any pending changes to the underlying mega-map.
 void deleteEntry(Entry entry)
          Deletes one entry and all the associated accessions and xrefs.
 List<String> getAllUniProtAccessions(MmDatabase database)
          to retrieve all accessions for the given database
 List<XRef> getChMBLXrefs(MmDatabase db, String accession, MmDatabase... xDbs)
          retrieves a List of XRef with database name as ChEMBL.
 Map<String,String> getCompounds(MmDatabase db, String accessions, MmDatabase... xDbs)
           
 Map<String,String> getCompoundsNew(MmDatabase db, String accession, MmDatabase... xDbs)
           
 Map<String,String> getDisease(MmDatabase db, String accessions, MmDatabase... xDbs)
           
 Map<String,String> getDiseaseNew(MmDatabase db, String accession, MmDatabase... xDbs)
           
 Entry getEntryForAccession(MmDatabase db, String accession)
          Retrieves an entry for a given accession.
 Collection<XRef> getXrefs(Collection<Entry> entries, MmDatabase... dbs)
          Retrieves cross references from the mega-map for several entries.
 Collection<XRef> getXrefs(Entry entry)
          Retrieves cross references from the mega-map regardless of the referencing/referenced database.
 Collection<XRef> getXrefs(Entry entry, MmDatabase... dbs)
          Retrieves cross references from the mega-map.
 Collection<XRef> getXrefs(MmDatabase db, String accession)
          Retrieves cross references from the mega-map for a given accession (not ID) regardless of the referencing/referenced database..
 Collection<XRef> getXrefs(MmDatabase db, String idFragment, MegaMapper.Constraint constraint, MmDatabase... xDbs)
          Retrieves cross references from the mega-map for a given text which matches an entry ID, who is related to the given databases.
This method is provided in order to search for UniProt ID prefixes (ex.
 Collection<XRef> getXrefs(MmDatabase db, String idFragment, MegaMapper.Constraint constraint, Relationship rel)
          Retrieves cross references from the mega-map for a given text which matches an entry ID, who has a given relationship (if any).
This method is provided in order to search for UniProt ID prefixes (ex.
 Collection<XRef> getXrefs(MmDatabase db, String accession, MmDatabase... xDbs)
          Retrieves cross references from the mega-map for a given accession (not ID) to/from the given database(s).
 Collection<XRef> getXrefs(MmDatabase db, String accession, Relationship relationship)
          Retrieves cross references from the mega-map for a given accession (not ID) given a concrete relationship.
 int getXrefsSize(MmDatabase db, String accession, MmDatabase... xDbs)
          retrieves the total number of Xrefs found for a given accession.
 void handleError()
          Handles any errors which might affect the mega-map.
 void openMap()
          Opens the mega-map for writing.
 void rollback()
          Rolls back any pending changes to the underlying mega-map.
 void write(Collection<Entry> entries, Collection<XRef> xrefs)
          Writes entries and relationships to the mega-map.
 void writeEntries(Collection<Entry> entries)
           
 void writeEntry(Entry entry)
          Writes one entry to the mega-map.
 void writeXref(XRef xref)
          Writes one cross-reference to the mega-map.
 void writeXrefs(Collection<XRef> xrefs)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ILLEGAL_COMPOUND

public static final String[] ILLEGAL_COMPOUND
Constructor Detail

MegaJdbcMapper

public MegaJdbcMapper(Connection con)
               throws IOException
Throws:
IOException
Method Detail

openMap

public final void openMap()
                   throws IOException
Opens the mega-map for writing.
This implementation prepares the required statements.

Specified by:
openMap in interface MegaMapper
Throws:
IOException

writeEntry

public void writeEntry(Entry entry)
                throws IOException
Description copied from interface: MegaMapper
Writes one entry to the mega-map.

Specified by:
writeEntry in interface MegaMapper
Throws:
IOException

writeEntries

public void writeEntries(Collection<Entry> entries)
                  throws IOException
Specified by:
writeEntries in interface MegaMapper
Throws:
IOException

writeXref

public void writeXref(XRef xref)
               throws IOException
Writes one cross-reference to the mega-map.
This implementation writes any (or both) of the two linked entries in case they don't already exist in the database.

Specified by:
writeXref in interface MegaMapper
Throws:
IOException

writeXrefs

public void writeXrefs(Collection<XRef> xrefs)
                throws IOException
Specified by:
writeXrefs in interface MegaMapper
Throws:
IOException

write

public void write(Collection<Entry> entries,
                  Collection<XRef> xrefs)
           throws IOException
Description copied from interface: MegaMapper
Writes entries and relationships to the mega-map.

Specified by:
write in interface MegaMapper
Throws:
IOException

deleteEntry

public void deleteEntry(Entry entry)
Deletes one entry and all the associated accessions and xrefs.

Parameters:
entry -

getEntryForAccession

public Entry getEntryForAccession(MmDatabase db,
                                  String accession)
Retrieves an entry for a given accession.
Unlike the hibernate implementation, in case of getting more than one result this will will be logged as a warning, returning the first entry only.

Specified by:
getEntryForAccession in interface MegaMapper
Returns:
an Entry, or null if not found.

getXrefs

public Collection<XRef> getXrefs(Entry entry)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map regardless of the referencing/referenced database.

Specified by:
getXrefs in interface MegaMapper
Parameters:
entry - The entry we want relationships for.
Returns:
a collection of xrefs in the map, regardless of the database. Note that the entry used in the query may be either the origin or the target of an xref.

getXrefs

public Collection<XRef> getXrefs(Entry entry,
                                 MmDatabase... dbs)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map.

Specified by:
getXrefs in interface MegaMapper
Parameters:
entry - The entry we want relationships for.
dbs - The database(s) to which the entry is related.
Returns:
a collection of xrefs in the map. Note that the entry used in the query may be either the origin or the target of an xref.

getXrefs

public Collection<XRef> getXrefs(Collection<Entry> entries,
                                 MmDatabase... dbs)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map for several entries.

Specified by:
getXrefs in interface MegaMapper
Parameters:
entries - The entries we want relationships for.
dbs - The database(s) to which the entries are related.
Returns:
a collection of xrefs in the map. Note that the entries used in the query may be either the origin or the target of an xref.

getXrefs

public Collection<XRef> getXrefs(MmDatabase db,
                                 String accession)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map for a given accession (not ID) regardless of the referencing/referenced database..

Specified by:
getXrefs in interface MegaMapper
Parameters:
db - the database where the accession is from.
accession - the accession number.
Returns:
a collection of xrefs in the map. Note that the accession used in the query may be either the origin or the target of an xref.

getXrefs

public Collection<XRef> getXrefs(MmDatabase db,
                                 String accession,
                                 MmDatabase... xDbs)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map for a given accession (not ID) to/from the given database(s).

Specified by:
getXrefs in interface MegaMapper
Parameters:
db - the database where the accession is from.
accession - the accession number.
xDbs - the referencing/referenced database(s).
Returns:
a collection of xrefs in the map, or null if none found. Note that the accession used in the query may be either the origin or the target of an xref.

getXrefs

public Collection<XRef> getXrefs(MmDatabase db,
                                 String accession,
                                 Relationship relationship)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map for a given accession (not ID) given a concrete relationship.

Specified by:
getXrefs in interface MegaMapper
Parameters:
db - the database where the accession is from.
accession - the accession number.
relationship - the relationship between the given accession and its cross references.
Returns:
a collection of xrefs in the map, or null if none found. Note that the accession used in the query may be either the origin or the target of an xref.

getXrefs

public Collection<XRef> getXrefs(MmDatabase db,
                                 String idFragment,
                                 MegaMapper.Constraint constraint,
                                 Relationship rel)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map for a given text which matches an entry ID, who has a given relationship (if any).
This method is provided in order to search for UniProt ID prefixes (ex. "CFTR_") but can be used for other purposes as well.

Specified by:
getXrefs in interface MegaMapper
Parameters:
db - the Database providing IDs matching idFragment. If null, all databases will be considered.
idFragment - A text which matches entry IDs. Please note that when searching for UniProt ID prefixes it is advisable to include the underscore (_) character, so that "DHSA" won't return xrefs for "DHSA1".
constraint - the constraint to use with the given idFragment.
rel - The relationship searched, if any (can be null).
Returns:
a collection of xrefs in the map, or null if none found. Note that the entries corresponding to the query may be either the origin or the target of an xref.

getXrefs

public Collection<XRef> getXrefs(MmDatabase db,
                                 String idFragment,
                                 MegaMapper.Constraint constraint,
                                 MmDatabase... xDbs)
Description copied from interface: MegaMapper
Retrieves cross references from the mega-map for a given text which matches an entry ID, who is related to the given databases.
This method is provided in order to search for UniProt ID prefixes (ex. "CFTR_") but can be used for other purposes as well.

Specified by:
getXrefs in interface MegaMapper
Parameters:
db - the Database providing IDs matching idFragment. If null, all databases will be considered.
idFragment - A text which matches entry IDs. Please note that when searching for UniProt ID prefixes it is advisable to include the underscore (_) character, so that "DHSA" won't return xrefs for "DHSA1".
constraint - the constraint to use with the given idFragment.
xDbs - the databases for which we want cross-references to be retrieved.
Returns:
a collection of xrefs in the map, or null if none found. Note that the entries corresponding to the query may be either the origin or the target of an xref.

getChMBLXrefs

public List<XRef> getChMBLXrefs(MmDatabase db,
                                String accession,
                                MmDatabase... xDbs)
retrieves a List of XRef with database name as ChEMBL.

Specified by:
getChMBLXrefs in interface MegaMapper
Parameters:
db - database where the accession is found
accession - the accession number
xDbs - chEMBL database
Returns:
a List of XRef with database name as chEMBL. Note: the maximum number of XRef retrieved is 5.

getXrefsSize

public int getXrefsSize(MmDatabase db,
                        String accession,
                        MmDatabase... xDbs)
retrieves the total number of Xrefs found for a given accession.

Specified by:
getXrefsSize in interface MegaMapper
Parameters:
db - the database where the accession is found
accession - the accession number
xDb - the referencing/referenced database(s).
Returns:
the total number of Xrefs found or 0 if none was found.

handleError

public void handleError()
                 throws IOException
Description copied from interface: MegaMapper
Handles any errors which might affect the mega-map.

Specified by:
handleError in interface MegaMapper
Throws:
IOException

closeMap

public void closeMap()
              throws IOException
Closes the mega-map.
This implementation just closes the prepared statements. Note that the connection is not closed, that is the client's responsibility.

Specified by:
closeMap in interface MegaMapper
Throws:
IOException

commit

public void commit()
            throws IOException
Description copied from interface: MegaMapper
Commits any pending changes to the underlying mega-map.

Specified by:
commit in interface MegaMapper
Throws:
IOException

rollback

public void rollback()
              throws IOException
Description copied from interface: MegaMapper
Rolls back any pending changes to the underlying mega-map.

Specified by:
rollback in interface MegaMapper
Throws:
IOException

getAllUniProtAccessions

public List<String> getAllUniProtAccessions(MmDatabase database)
to retrieve all accessions for the given database

Specified by:
getAllUniProtAccessions in interface MegaMapper
Parameters:
database - the database with accessions
Returns:
list of accessions from a given database

getDiseaseNew

public Map<String,String> getDiseaseNew(MmDatabase db,
                                        String accession,
                                        MmDatabase... xDbs)

getCompoundsNew

public Map<String,String> getCompoundsNew(MmDatabase db,
                                          String accession,
                                          MmDatabase... xDbs)

getDisease

public Map<String,String> getDisease(MmDatabase db,
                                     String accessions,
                                     MmDatabase... xDbs)
Specified by:
getDisease in interface MegaMapper

getCompounds

public Map<String,String> getCompounds(MmDatabase db,
                                       String accessions,
                                       MmDatabase... xDbs)
Specified by:
getCompounds in interface MegaMapper


Copyright © 2012 EMBL-EBI. All Rights Reserved.