Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for a couple issues in geneontology/noctua-models#55 #3

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Set in_taxon and use context JSONLD
  • Loading branch information
dustine32 committed Mar 7, 2024
commit 3a4020db1ebb17a1ab5b992bfcd47d7428bc1861
88 changes: 70 additions & 18 deletions src/main/scala/org/geneontology/syngo2lego/LegoModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package org.geneontology.syngo2lego
import org.semanticweb.owlapi.apibinding.OWLManager
import dosumis.brainscowl.BrainScowl
import org.phenoscape.scowl._

import org.semanticweb.owlapi.model.OWLOntology
import org.semanticweb.owlapi.model.OWLClass
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.model.{IRI, OWLAnnotationProperty, OWLClass, OWLOntology}
import org.semanticweb.owlapi.search.EntitySearcher
import rapture.json._, jsonBackends.jawn._
import rapture.json._
import jsonBackends.jawn._

import scala.io.Source
import java.io.File
import java.util.Date
import java.text.SimpleDateFormat

class LegoModel (val jmodel : Json, val GO : BrainScowl, add_import_statement: Boolean) {
class LegoModel (val jmodel : Json, val GO : BrainScowl, add_import_statement: Boolean, context_lookup: Json) {
/**

Take one model worth of SynGO JSON (as Json)
Expand All @@ -36,7 +35,8 @@ class LegoModel (val jmodel : Json, val GO : BrainScowl, add_import_statement: B
val dc_date = AnnotationProperty("http://purl.org/dc/elements/1.1/date")
val model_status = AnnotationProperty("http://geneontology.org/lego/modelstate")
val provided_by = AnnotationProperty("http://purl.org/pav/providedBy")
val mods = this.jmodel.models.as[List[Json]]
val in_taxon = AnnotationProperty("https://w3id.org/biolink/vocab/in_taxon")
var mods = this.jmodel.models.as[List[Json]]
val model_ns = base + syngo_id

// val title_value = mods.head.GENENAME + "_" + aspect + "_" + mods.head.annotationid
Expand All @@ -52,7 +52,8 @@ class LegoModel (val jmodel : Json, val GO : BrainScowl, add_import_statement: B
owl_model.annotateOntology(Annotation(model_status, this.jmodel.status.as[String]))

var file_extension = ""
for (mod <- mods) {
var model_count = 0
for (mod <- mods) {
// Add in check of JSON integrity mod
var skip_model = false
val deprecated_fields = GO.getSpecAnnotationsOnEntity(
Expand All @@ -62,13 +63,60 @@ class LegoModel (val jmodel : Json, val GO : BrainScowl, add_import_statement: B
val deprecated_field = deprecated_fields.head.isDeprecatedIRIAnnotation()
println(deprecated_field)
if (deprecated_field) {
skip_model = true
println(s"Skipping ${syngo_id}.")
// Look for a "term replaced by" term
var has_replacement_term = false
val term_annotations = GO.getAnnotationsOnEntity(query_short_form = mod.goTerm.as[String].replace(":", "_"))
if (term_annotations.length > 0) {
for (ta <- term_annotations) {
val prop = ta.getProperty()
val value = ta.getValue()
if (prop.equals(AnnotationProperty("http://purl.obolibrary.org/obo/IAO_0100001"))) {
has_replacement_term = true
}
}
}
if (!has_replacement_term) {
skip_model = true
println(s"Skipping ${syngo_id}.")
}
}
}
val term_annotations = GO.getAnnotationsOnEntity(query_short_form = mod.goTerm.as[String].replace(":", "_"))
if (term_annotations.length > 0) {
for (ta <- term_annotations) {
val prop = ta.getProperty()
val value = ta.getValue()
if (prop.equals(AnnotationProperty("http://purl.obolibrary.org/obo/IAO_0100001"))) {
println(value)
}
}
}
if (!skip_model) {
var sm = new SimpleModel(model_ns, owl_model, mod, GO)
var sm = new SimpleModel(model_ns, owl_model, mod, GO, context_lookup)
sm.generate()

val taxon_prefix = "http://purl.obolibrary.org/obo/NCBITaxon_"
var taxon = mod.id_db_source.as[String] match {
case "HGNC_ID" => "9606"
case "RGD" => "10116"
case "MGI" => "10090"
case "FlyBase" => "7227"
case "WormBase" => "6239"
case "ZFIN" => "7955"
case default => ""
}
if (taxon == "") {
// Likely non-MOD and taxon_id was individually retrieved. Try fetching taxon_id key
try {
taxon = mod.taxon_id.as[String]
} catch {
case _: rapture.data.TypeMismatchException => taxon = ""
}
}
if (taxon != "") {
owl_model.annotateOntology(Annotation(in_taxon, taxon_prefix + taxon))
}
model_count+=1
}
}

Expand All @@ -77,22 +125,26 @@ class LegoModel (val jmodel : Json, val GO : BrainScowl, add_import_statement: B
file_extension = ".ttl"
}

owl_model.save(syngo_id + test + ".ttl", "ttl") //
owl_model.sleep()
// Only save if there's actually anything to say
if (model_count > 0) {
owl_model.save(syngo_id + test + ".ttl", "ttl") //
owl_model.sleep()
}

def get_title(): String = {
val found_aspects = GO.getSpecTextAnnotationsOnEntity(
val found_aspects = GO.getSpecAnnotationsOnEntity(
query_short_form = mods.head.goTerm.as[String].replace(":", "_"),
ap_short_form = "hasOBONamespace")
var aspect = ""
var found_aspect = ""
if (found_aspects.length > 0) {
aspect = found_aspects.head
found_aspect = found_aspects.head.getValue.asLiteral.get.getLiteral
}
if (aspect == "cellular_component") {
if (found_aspect == "cellular_component") {
aspect = "CC"
} else if (aspect == "molecular_function") {
} else if (found_aspect == "molecular_function") {
aspect = "MF"
} else if (aspect == "biological_process") {
} else if (found_aspect == "biological_process") {
aspect = "BP"
}
var gene_name = ""
Expand Down
7 changes: 5 additions & 2 deletions src/main/scala/org/geneontology/syngo2lego/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ object Main extends(App) {
Cli.parse(args).withCommand(new Cat) { case cat =>
// Takes full JSON file as input, splits it up into models.
// Generates individual OWL files from each model
val go = new BrainScowl("resources/go-simple.ofn") // TODO switch to pulling this dynamically from URL
val go = new BrainScowl("resources/go.owl") // TODO switch to pulling this dynamically from URL
val synGO_file = Source.fromFile(cat.json_file).getLines.mkString
val synGO_json = Json.parse(synGO_file)
val url = "https://raw.githubusercontent.com/prefixcommons/biocontext/master/registry/go_context.jsonld"
var lookup_str = scala.io.Source.fromFile("resources/go_context.jsonld").mkString
val idOrg_ns_lookup = Json.parse(lookup_str).context
// At this point - should run check of json - outer struc
// Loop over models calling genModel
// var status = "delete"
Expand All @@ -32,7 +35,7 @@ object Main extends(App) {
// status = "publish"
// }
for (a <- synGO_json.SynGO.as[List[Json]]) {
var lm = new LegoModel(a, go, cat.no_imports)
var lm = new LegoModel(a, go, cat.no_imports, idOrg_ns_lookup)
}
go.sleep()
}
Expand Down
43 changes: 26 additions & 17 deletions src/main/scala/org/geneontology/syngo2lego/SimpleModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ import java.util.Date
import java.text.SimpleDateFormat

class SimpleModel (val model_ns: String, var ont : BrainScowl,
val jmodel : Json, val go: BrainScowl) {
// Passing rather too many vars. Deeper class model with some
val jmodel : Json, val go: BrainScowl, val idOrg_ns_lookup: Json) {
// Passing rather too many vars. Deeper class model with some
// inheritance might be good here instead...

// Declare globals

// Namespaces (In the OWL sense - AKA Base IRIs)
val obo_ns = "http://purl.obolibrary.org/obo/"
val idOrg_ns = "http://identifiers.org/uniprot/"
val idOrg_ns_lookup = Map("uniprot" -> idOrg_ns,
"RGD_ID" -> "http://rgd.mcw.edu/rgdweb/report/gene/main.html?id=",
"MGI_ID" -> "http://www.informatics.jax.org/accession/MGI:",
"FLYBASE_ID" -> "http://flybase.org/reports/",
"WORMBASE_ID" -> "http://www.wormbase.org/db/gene/gene?name=",
"HGNC_ID" -> idOrg_ns)
val lookup_key_lookup = Map("uniprot" -> "UniProtKB",
"HGNC_ID" -> "UniProtKB",
"RGD" -> "RGD",
"MGI" -> "MGI",
"FlyBase" -> "FB",
"WormBase" -> "WB",
"ZFIN" -> "ZFIN")
val synGO_ns = "http://syngo.vu.nl/"

// OP vals // This should really be pulled from a config file
Expand All @@ -41,19 +42,17 @@ class SimpleModel (val model_ns: String, var ont : BrainScowl,
// Lookup needed to translate identifiers from JSON
val OP_lookup = Map( "part_of" -> part_of,
"occurs_in" -> occurs_in) // More concise way to do this?

val primary_class = Class(obo_ns + this.jmodel.goTerm.as[String].replace(":", "_"))

// Add check that primary class exists in GO!

// Annotations // Global 'cos they go on everything.

val dc_contributor = AnnotationProperty("http://purl.org/dc/elements/1.1/contributor")
// val contributor = IRI.create(synGO_ns + jmodel.username.as[String])
val comment = AnnotationProperty("http://www.w3.org/2000/01/rdf-schema#comment")
// val contributor = "SynGO:" + jmodel.username.as[String]
val contributors = jmodel.username.as[String].split(';')
val contributor_prefix = "http://orcid.org/"
val contributor_prefix = "https://orcid.org/"
val source = "PMID:" + jmodel.pmid.as[String]
val evidence = AnnotationProperty("http://geneontology.org/lego/evidence")
val provided_by = AnnotationProperty("http://purl.org/pav/providedBy")
Expand Down Expand Up @@ -85,9 +84,9 @@ class SimpleModel (val model_ns: String, var ont : BrainScowl,
// Do NOT use goDomain from the JSON as MFs are mislabelled as BPs:
// e.g. This labeled as BP GO:1905056 calcium-transporting ATPase activity involved in ...

val primary_aspect = go.getSpecTextAnnotationsOnEntity(
val primary_aspect = go.getSpecAnnotationsOnEntity(
query_short_form = this.jmodel.goTerm.as[String].replace(":", "_"),
ap_short_form = "hasOBONamespace").head // head bakes in cardinality without check!
ap_short_form = "hasOBONamespace").head.getValue.asLiteral.get.getLiteral // head bakes in cardinality without check!


def new_ind() : OWLNamedIndividual = {
Expand Down Expand Up @@ -115,8 +114,18 @@ class SimpleModel (val model_ns: String, var ont : BrainScowl,

def new_gp(): OWLNamedIndividual = {

println(this.jmodel.id_db_source.as[String])
println(idOrg_ns_lookup.MGI)
// return new_typed_ind(obo_ns + "UniProtKB_" + this.jmodel.uniprot.as[String])
val ns = idOrg_ns_lookup(this.jmodel.id_db_source.as[String])
//TODO maybe try com.google.gson.Gson?
val ns = lookup_key_lookup(this.jmodel.id_db_source.as[String]) match {
case "UniProtKB" => idOrg_ns_lookup.UniProtKB.as[String]
case "RGD" => idOrg_ns_lookup.RGD.as[String]
case "MGI" => idOrg_ns_lookup.MGI.as[String]
case "FB" => idOrg_ns_lookup.FB.as[String]
case "WB" => idOrg_ns_lookup.WB.as[String]
case "ZFIN" => idOrg_ns_lookup.ZFIN.as[String]
}
return new_typed_ind(ns + this.jmodel.noctua_gene_id.as[String])
}

Expand All @@ -128,9 +137,9 @@ class SimpleModel (val model_ns: String, var ont : BrainScowl,
if (!term.startsWith("GO:")) {
return ""
}
val aspect = go.getSpecTextAnnotationsOnEntity(
val aspect : String = go.getSpecAnnotationsOnEntity(
query_short_form = term.replace(":", "_"),
ap_short_form = "hasOBONamespace").head
ap_short_form = "hasOBONamespace").head.getValue.asLiteral.get.getLiteral
return aspect
}

Expand Down