[MOBY-guts] biomoby commit
Gary Schlitz
gss at pub.open-bio.org
Fri Apr 2 00:03:39 UTC 2004
gss
Thu Apr 1 19:03:39 EST 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/example-providers/acmepubs.com/src/com/acmepubs/servlets
In directory pub.open-bio.org:/tmp/cvs-serv8639/ref-impl/example-providers/acmepubs.com/src/com/acmepubs/servlets
Modified Files:
CitationSearchServlet.java
Log Message:
Major commit just before MOBY meeting at CSHL
moby-live/S-MOBY/ref-impl/example-providers/acmepubs.com/src/com/acmepubs/servlets CitationSearchServlet.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/example-providers/acmepubs.com/src/com/acmepubs/servlets/CitationSearchServlet.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/example-providers/acmepubs.com/src/com/acmepubs/servlets/CitationSearchServlet.java 2004/04/01 00:33:35 1.6
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/example-providers/acmepubs.com/src/com/acmepubs/servlets/CitationSearchServlet.java 2004/04/02 00:03:39 1.7
@@ -6,12 +6,12 @@
import javax.servlet.*;
import javax.servlet.http.*;
+import org.go.vocabulary.Go;
import org.smoby.tools.common.graph.MOBYGraph;
import org.smoby.tools.common.vocabulary.MOBY;
import org.smoby.tools.server.servlet.AbstractMobyServlet;
-
-import com.acmepubs.db.CitationDB;
import com.acmepubs.vocabulary.AcmePubs;
+
import com.hp.hpl.jena.rdf.model.*;
/**
@@ -36,125 +36,50 @@
/**
* Handle a request for a citation search by looking up
- * a gene symbol and returning a list of publication
- * abstracts. In this simplistic first cut, only look
- * at the first "hasMapping" property, find the "geneID"
- * property value as a lookup value, and for each matching
- * publication date past the first one, create a copy of
- * the entire subgraph and fill in its "pubDate" property.
+ * a gene symbol and returning a URL for querying the
+ * SGD database for literature pertaining to that URL.
*/
protected void handleRequest(MOBYGraph graph)
{
- // Retrieve the subject of the moby:mapsTo statement
+ // Retrieve the subject of the moby:operatesOn statement (there is only
+ // one operatesOn statement in a valid MOBY graph)
//
Resource mobyGraphSubject = (Resource) graph.getOperatesOnStmt().getObject();
- // Get the subject of the first hasMapping statement (the only one
- // considered in this first cut)
+ // There may be multiple moby:hasMapping statements. For each one,
+ // map its geneSymbol to a literatureGuideURL
//
- Resource start = graph.getModel()
- .listStatements(mobyGraphSubject, MOBY.hasMapping, (RDFNode) null)
- .nextStatement().getSubject();
+ StmtIterator it = graph.getModel().listStatements(
+ mobyGraphSubject, MOBY.hasMapping, (RDFNode) null);
- // Retrieve the subgraph that is "reachable" from the subject of the
- // first hasMapping statement.
- //
- Model subgraph = ModelFactory.createDefaultModel();
- subgraph.setNsPrefixes(graph.getModel().getNsPrefixMap());
- addReachableStatements(start, graph.getModel(), subgraph);
-
- // Find the "geneID" statement in the subgraph; if there isn't one,
- // then we can't handle it (really should throw an exception...)
- //
- StmtIterator it = subgraph.listStatements(null, AcmePubs.geneID, (RDFNode) null);
- if (! it.hasNext()) return;
-
- // Get the object of the geneID statement; if it isn't a String, then
- // again we can't handle it.
- //
- String geneID = null;
- try {
- geneID = it.nextStatement().getString();
- } catch (Throwable t) {
- return;
- }
-
- // Look up the gene symbol; if not found, then there's nothing to do
- //
- List pubDates = CitationDB.getCitations(geneID);
- if (pubDates == null) return;
-
- // For each publication date found, replace the object of the pubDate
- // statement with the publication date in the subgraph (for the first
- // pub date) or in a copy (for subsequent pub dates)
- //
- int i = 0;
- for (Iterator iter = pubDates.iterator(); iter.hasNext(); i++)
- {
- String pubDate = iter.next().toString();
-
- // In the first match, we use the subgraph pulled from the original
- // graph; in additional matches, we use a copy (whose statements have
- // to be added to the original model)
- //
- if (i > 0)
- {
- subgraph = copyModel(subgraph);
- graph.getModel().add(subgraph);
- }
-
- // Find the "pubDate" statement in the subgraph; if there isn't one,
- // then we can't handle it (really should throw an exception...)
- //
- it = subgraph.listStatements(null, AcmePubs.pubDate, (RDFNode) null);
- if (! it.hasNext()) return;
-
- // Replace the object of the pubDate statement with a literal value,
- // namely the publication date
- //
- Statement stmt = it.nextStatement();
- stmt.changeObject(pubDate);
- }
- }
-
- protected Model copyModel(Model model)
- {
- Model copy = ModelFactory.createDefaultModel();
- copy.setNsPrefixes(model.getNsPrefixMap());
- for (StmtIterator it = model.listStatements(); it.hasNext();)
- {
- Statement stmt = it.nextStatement();
- copy.add(copy.createStatement(
- stmt.getSubject(),
- stmt.getPredicate(),
- stmt.getObject()));
- }
- return copy;
- }
-
- /**
- * Add to a model the depth-first traversal
- * of a source graph starting from a given subject
- * @param subject the resource that is the starting poing
- * @param source the model containing a set of statements from which to add
- * @param subgraph the model to which to add reachable statements
- */
- protected void addReachableStatements(Resource subject, Model source, Model subgraph)
- {
- StmtIterator it = source.listStatements(subject, null, (RDFNode) null);
- while (it.hasNext())
- {
- Statement stmt = it.nextStatement();
- if (! subgraph.contains(stmt))
- {
- subgraph.add(stmt);
- addReachableStatements(stmt.getSubject(), source, subgraph);
- addReachableStatements(stmt.getPredicate(), source, subgraph);
- if (stmt.getObject() instanceof Resource) {
- addReachableStatements((Resource) stmt.getObject(), source, subgraph);
- }
+ while (it.hasNext())
+ {
+ try
+ {
+ Statement hasMappingStmt = it.nextStatement();
+ Resource mobySubject = (Resource) hasMappingStmt.getObject();
+
+ Statement geneSymbolStmt =
+ getFirstStatement(graph, mobySubject, AcmePubs.geneSymbol, null);
+
+ String geneSymbol = geneSymbolStmt.getString();
+
+ Statement mapsToStmt =
+ getFirstStatement(graph, mobySubject, MOBY.mapsTo, null);
+
+ Resource mobyObject = (Resource) mapsToStmt.getObject();
+
+ Statement literatureGuideURLStmt =
+ getFirstStatement(graph, mobyObject, AcmePubs.literatureGuideURL, null);
+
+ String baseURI = "http://db.yeastgenome.org/cgi-bin/SGD/reference/geneinfo.pl?locus=";
+ literatureGuideURLStmt.changeObject(baseURI + geneSymbol);
+ }
+ catch (Throwable t)
+ {
+ // Something went wrong, so proceed to next hasMapping statement
}
- }
+ }
}
/**
More information about the MOBY-guts
mailing list