From: <cmu...@us...> - 2008-01-29 00:54:00
|
Revision: 1422 http://obo.svn.sourceforge.net/obo/?rev=1422&view=rev Author: cmungall Date: 2008-01-28 16:54:04 -0800 (Mon, 28 Jan 2008) Log Message: ----------- Modified Paths: -------------- obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeParser.java Added Paths: ----------- obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeOBOParser.java Added: obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeOBOParser.java =================================================================== --- obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeOBOParser.java (rev 0) +++ obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeOBOParser.java 2008-01-29 00:54:04 UTC (rev 1422) @@ -0,0 +1,170 @@ +package org.obd.parser; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; + +import org.obd.model.CompositionalDescription; +import org.obd.model.LinkStatement; +import org.obd.model.Node; +import org.obd.model.Statement; +import org.obd.model.CompositionalDescription.Predicate; +import org.obd.model.Node.Metatype; +import org.obd.query.ComparisonQueryTerm.Operator; + +/** + * + * @author cjm + * + * TODO: DRY - see also ZFINGenotypePhenotypeParser + * + */ +public class ZFINGenotypePhenotypeOBOParser extends TabularInfoParser { + + protected String src = "ZFIN"; + private String taxId = "NCBITax:7955"; + protected String defaultURL = + "http://zfin.org/data_transfer/Downloads/pheno_obo.txt"; + + + public ZFINGenotypePhenotypeOBOParser() { + super(); + } + + public ZFINGenotypePhenotypeOBOParser(String path) { + super(path); + } + + public String createId(String local) { + return "ZFIN:"+local; + } + + + public void parseColVals(String[] colVals) throws Exception { + index(); + if (colVals.length < 6) { + throw new Exception("not enough vals: "+currentLine); + } + int n = 0; + String gtId = colVals[n++]; + String gtLabel = colVals[n++]; + + String startId = colVals[n++]; + //String startLabel = colVals[3]; + String endId = colVals[n++]; + //String endLabel = colVals[5]; + String entityId = colVals[n++]; + //String entityLabel = colVals[7]; + String qualityId = colVals[n++]; + //String qualityLabel = colVals[9]; + String ab = colVals[12]; + String pubId = colVals[13]; + + Node gtNode = addNode(gtId); + gtNode.setLabel(gtLabel); + + HashSet<LinkStatement> diffs = new HashSet<LinkStatement>(); + if (startId != null && !startId.equals("ZFS:0000000")) { + LinkStatement d = new LinkStatement(); + d.setRelationId("OBO_REL:starts_during"); + d.setTargetId(entityId); + diffs.add(d); + } + if (endId != null && !endId.equals("ZFS:0000000")) { + LinkStatement d = new LinkStatement(); + d.setRelationId("OBO_REL:ends_during"); + d.setTargetId(entityId); + diffs.add(d); + } + if (entityId != null) { + LinkStatement d = new LinkStatement(); + d.setRelationId("OBO_REL:inheres_in"); + d.setTargetId(entityId); + diffs.add(d); + } + else { + return; + } + if (qualityId != null) { + CompositionalDescription desc = new CompositionalDescription(qualityId, diffs); + + String phenoId = desc.generateId(); + desc.setId(phenoId); + graph.addStatements(desc); + + + LinkStatement annot = new LinkStatement(); + annot.setNodeId(gtId); + annot.setRelationId("OBO_REL:influences"); + + LinkStatement pubLink = new LinkStatement(); + pubLink.setRelationId("oban:has_data_source"); + pubLink.setTargetId(pubId); + annot.addSubStatement(pubLink); + + LinkStatement abLink = new LinkStatement(); + pubLink.setRelationId("oban:assigned_by"); + pubLink.setTargetId("ZFIN"); + annot.addSubStatement(abLink); + + annot.setTargetId(phenoId); + annot.setSourceId(src); + this.addStatement(annot); + } + else { + warn("cannot find quality"); + } + + } + + public Node addNode(String id) { + Node node = super.addNode(id); + node.setMetatype(Metatype.CLASS); + node.setSourceId(src); + addInOrganismLink(id, taxId, src); + return node; + } + + public String lookup(String id) { + return lookup(id,null); + } + + public String lookup(String id, String label) { + if (id != null) { + if (termIndex.containsKey(id)) + return termIndex.get(id); + if (termIndex.containsKey(createId(id))) + return termIndex.get(createId(id)); + } + if (label != null) + if (termIndex.containsKey(label)) + return termIndex.get(label); + return null; + } + + Map <String,String> termIndex = new HashMap<String,String>(); + boolean isIndexed = false; + public void index() { + if (isIndexed) + return; + for (Node n : shard.getNodes()) { + String nid = n.getId(); + termIndex.put(n.getLabel(), nid); + //System.out.println("indexing: "+n.getLabel()+" "+nid); + for (Statement s : shard.getStatementsForNode(nid)) { + if (s instanceof LinkStatement) { + LinkStatement ls = (LinkStatement)s; + if (ls.isXref()) { + termIndex.put(ls.getTargetId(), nid); + } + } + } + // TODO: xrefs + } + System.err.println("index size="+termIndex.size()); + isIndexed = true; + } + + +} Modified: obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeParser.java =================================================================== --- obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeParser.java 2008-01-28 23:54:26 UTC (rev 1421) +++ obdapi/trunk/OBDAPI/src/org/obd/parser/ZFINGenotypePhenotypeParser.java 2008-01-29 00:54:04 UTC (rev 1422) @@ -18,7 +18,11 @@ protected String src = "ZFIN"; private String taxId = "NCBITax:7955"; + + protected String defaultURL = + "http://zfin.org/data_transfer/Downloads/phenotype.txt"; + public ZFINGenotypePhenotypeParser() { super(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |