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

Update #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Binary file modified OWLmaker.jar
Binary file not shown.
54 changes: 37 additions & 17 deletions src/ontoTool/OntologyClassGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
*/

public class OntologyClassGenerator {
public static final String CNAME_IRI = "iri";
public static final String CNAME_LABEL = "label";
public static final String CNAME_PARENT_IRI = "parentiri";
public static final String CNAME_PARENT_LABEL = "parentlabel";

public static void main(String[] args) {
OntologyClassGeneratorOptions bean = new OntologyClassGeneratorOptions();
CmdLineParser parser = new CmdLineParser(bean);
Expand All @@ -73,25 +78,28 @@ public static void main(String[] args) {

// path of input file
String path = config.getPath();

// tab-delimited file for conversion
String inputFilename = config.getInputFilename();

// ontology IRI of converted OWL file
String ontoIRIstr = config.getOntologyIRIstr();

// output converted OWL file name
String outputFilename = config.getOutputFilename();

// base URL of new term IRIs
String idBase = config.getIdBase();

// prefix for new term ID
String prefix = config.getPrefix();

// start ID number
int startNum = config.getStartNum();
// index for term label, term IRI, term parent label or IRI in the tab-delimited file
int iriPos = config.getIriPos();
int labelPos = config.getLabelPos();
int parentIriPos = config.getParentIriPos();
int parentPos = config.getParentPos();

// external ontology as reference of existing ontology class and annotation property
String externalOntologyFilename = config.getExternalOntologyFilename();

// labels/IRI of annotation properties that will be used in conversion
ArrayList<String> annotLabels = config.getAnnotLabels();

Expand Down Expand Up @@ -169,27 +177,37 @@ public static void main(String[] args) {

//annotation Property IRI and its index in the input file
Hashtable<Integer, String> annotProps = new Hashtable<Integer, String>();

// Find annotation property index from header of input file, any column name is not specified as

// index for term label, term IRI, term parent label or IRI in the tab-delimited file
int iriPos = -1;
int labelPos = -1;
int parentIriPos = -1;
int parentPos = -1;

// Find term and its parent IRI and label position, and annotation property index from header of input file, any column name is not specified as
// annotation property in the setting file will be skipped
String[] items = matrix.get(0);

for (int k = 0; k< items.length; k++) {
String item = items[k].trim();

if (item != null && !item.isEmpty() && labelIriObjects.containsKey(item.toLowerCase())) {
annotProps.put(new Integer(k), labelIriObjects.get(item.toLowerCase()));
}
for (int k = 0; k< items.length; k++) {
String item = items[k];

if (item != null && !item.isEmpty()) {
if (item.toLowerCase().equals(CNAME_IRI)) iriPos = k;
else if (item.toLowerCase().equals(CNAME_LABEL)) labelPos = k;
else if (item.toLowerCase().equals(CNAME_PARENT_IRI)) parentIriPos = k;
else if (item.toLowerCase().equals(CNAME_PARENT_LABEL)) parentPos = k;
else if (labelIriObjects.containsKey(item.toLowerCase())) annotProps.put(new Integer(k), labelIriObjects.get(item.toLowerCase()));
}
}

// create classes
for (int i = 1; i < matrix.size(); i++) {
items = matrix.get(i);

String termLabel = "";
String termIRIstr = "";
String parentLabel = "";
String parentIRIstr = "";
String termLabel = "";
String termIRIstr = "";
String parentLabel = "";
String parentIRIstr = "";

// -- get term label and IRIstr --
// Term label must be provided in the input file
Expand Down Expand Up @@ -422,6 +440,8 @@ public static void printHashtable (Hashtable<String,String> pairs, String messag

public static String cleanString (String s) {
s = s.trim().replaceAll("^\"|\"$", "");

if (s.toUpperCase().equals("NA")) s = "";

return s;
}
Expand Down
53 changes: 0 additions & 53 deletions src/ontoTool/OntologyClassGeneratorConfiguration.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ public class OntologyClassGeneratorConfiguration {
private String idBase = "http://purl.obolibrary.org/obo/"; // base URL of new term IRIs
private String prefix = ""; // prefix for new term ID
private int startNum = 1; // start ID number
// index for term label, term IRI, term parent label or IRI in the tab-delimited file
private int iriPos = -1;
private int labelPos = -1;
private int parentIriPos = -1;
private int parentPos = -1;
private String externalOntologyFilename = "";
private ArrayList<String> annotLabels;

Expand All @@ -40,10 +35,6 @@ public class OntologyClassGeneratorConfiguration {
this.idBase = "http://purl.obolibrary.org/obo/";
this.prefix = "";
this.startNum = 1;
this.iriPos = -1;
this.labelPos = -1;
this.parentIriPos = -1;
this.parentPos = -1;
this.externalOntologyFilename = "";
this.annotLabels = new ArrayList<String>();
}
Expand Down Expand Up @@ -86,18 +77,6 @@ public void parseSetting(String settingFilename) {
break;
case "start ID":
setStartNum(Integer.parseInt(value));
break;
case "term position":
setLabelPos(Integer.parseInt(value)-1);
break;
case "term IRI position":
setIriPos(Integer.parseInt(value)-1);
break;
case "term parent position":
setParentPos(Integer.parseInt(value)-1);
break;
case "term parent IRI position":
setParentIriPos(Integer.parseInt(value)-1);
break;
case "external ontology file":
setExternalOntologyFilename(value);
Expand Down Expand Up @@ -154,22 +133,6 @@ public int getStartNum () {
return this.startNum;
}

public int getIriPos () {
return this.iriPos;
}

public int getLabelPos () {
return this.labelPos;
}

public int getParentIriPos () {
return this.parentIriPos;
}

public int getParentPos () {
return this.parentPos;
}

public String getExternalOntologyFilename () {
return this.externalOntologyFilename;
}
Expand Down Expand Up @@ -206,23 +169,7 @@ public void setStartNum (int startNum) {
this.startNum = startNum;
}

public void setIriPos (int iriPos) {
this.iriPos = iriPos;
}

public void setLabelPos (int labelPos) {
this.labelPos = labelPos;
}

public void setParentIriPos (int parentIriPos) {
this.parentIriPos = parentIriPos;
}

public void setExternalOntologyFilename (String externalOntologyFilename) {
this.externalOntologyFilename = externalOntologyFilename;
}

public void setParentPos (int parentPos) {
this.parentPos = parentPos;
}
}
6 changes: 4 additions & 2 deletions src/ontoTool/OntologyClassGeneratorOptions.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
*/
public class OntologyClassGeneratorOptions {
@Option(name="-settingFilename", usage ="the configuration used to set all variables required for the OWL conversion", required = false)
private String settingFilename = "./test/setting.txt";

private String settingFilename = "/Users/jiezheng/Documents/VEuPathDB-git/ApiCommonData/Load/ontology/script/test-local/setting_test.txt";

//private String settingFilename = "/Users/jiezheng/Documents/ontology/DTO/proteoCommons/class/setting.txt";

public String getSettingFilename () {
return this.settingFilename;
}
Expand Down
66 changes: 35 additions & 31 deletions src/owlUtil/OntologyEditor.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,54 @@
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyChange;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.RemoveAxiom;
import org.semanticweb.owlapi.search.EntitySearcher;
import org.semanticweb.owlapi.util.OWLEntityRenamer;
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;

public class OntologyEditor {
// add an instance, specify its class type and add label annotation if available
public static void addInstance(OWLOntologyManager manager, OWLOntology ontology, String instanceIRIstr, String classIRIstr, String instanceLabel) {
// Create factory to obtain a reference to a class
OWLDataFactory df = manager.getOWLDataFactory();

public static void cleanEmptyAnnotationFields() {

}

public static void addAnnotations(OWLOntologyManager manager, OWLOntology ontology, String annotPropIRI, HashMap<String, String> annotationList) {
// Create instance
OWLNamedIndividual ins = df.getOWLNamedIndividual(IRI.create(instanceIRIstr));

// Add asserted class type
OWLClass cls = df.getOWLClass(IRI.create(classIRIstr));
OWLClassAssertionAxiom classTypeAxiom = df.getOWLClassAssertionAxiom(cls, ins);
manager.applyChange(new AddAxiom(ontology, classTypeAxiom));

// Add label if it is not null
if (instanceLabel.length() > 0 ) {
OWLAnnotationProperty labelProp = df.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
OWLAnnotation labelAnnot = df.getOWLAnnotation(labelProp, df.getOWLLiteral(instanceLabel));
OWLAxiom labelAxiom = df.getOWLAnnotationAssertionAxiom(IRI.create(instanceIRIstr), labelAnnot);
manager.applyChange(new AddAxiom(ontology, labelAxiom));
}
}

// add relation between two instances
public static void addRelation (OWLOntologyManager manager, OWLOntology ontology, String subjectIRIstr, String objectIRIstr, String objectPropIRIstr) {
// Create factory to obtain a reference to a class
OWLDataFactory df = manager.getOWLDataFactory();
OWLNamedIndividual subject = df.getOWLNamedIndividual(IRI.create(subjectIRIstr));
OWLNamedIndividual object = df.getOWLNamedIndividual(IRI.create(objectIRIstr));
OWLObjectProperty predicate = df.getOWLObjectProperty(IRI.create(objectPropIRIstr));
OWLObjectPropertyAssertionAxiom propAssertion = df.getOWLObjectPropertyAssertionAxiom(predicate, subject, object);
manager.applyChange(new AddAxiom(ontology,propAssertion));
}

// update annotation properties
public static void updateAnnotations(OWLOntologyManager manager, OWLOntology ontology, String annotPropIRI, HashMap<String, String> annotationList) {
// Create factory to obtain a reference to a class
OWLDataFactory df = manager.getOWLDataFactory();
Expand Down Expand Up @@ -61,32 +91,6 @@ public static void updateAnnotations(OWLOntologyManager manager, OWLOntology ont
System.out.println(entityIRIstr + " is not in the given ontology");
}
}


// go through each class in the ontology, if they are in the list for editing,
// remove any associate annotation property value(s) of the class if there are any
// and add new annotation values to the class
/*
for (OWLClass cls : ontology.getClassesInSignature()) {
String termIRIstr = cls.getIRI().toString();

if (annotationList.containsKey(termIRIstr)) {
// remove specified annotation property if it has been defined
Collection<OWLAnnotation> owlAnnots = EntitySearcher.getAnnotations(cls, ontology, annotProp);

if(!owlAnnots.isEmpty()) {
for (OWLAnnotation owlAnnot : owlAnnots) {
OWLAxiom ax = df.getOWLAnnotationAssertionAxiom(cls.getIRI(), owlAnnot);
manager.applyChange(new RemoveAxiom(ontology, ax));
}
}

OWLAnnotation newAnnot = df.getOWLAnnotation(annotProp, df.getOWLLiteral(annotationList.get(termIRIstr)));
OWLAxiom ax = df.getOWLAnnotationAssertionAxiom(cls.getIRI(), newAnnot);
manager.applyChange(new AddAxiom(ontology, ax));
}
}
*/
}

// update IRIs based on mapping file
Expand Down
Empty file modified src/owlUtil/OntologyEntityIriLabel.java
100644 → 100755
Empty file.
30 changes: 0 additions & 30 deletions src/owlUtil/OntologyManipulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.OWLOntologyMerger;
import com.google.common.base.Optional;

import java.io.File;
import java.util.Set;
Expand Down Expand Up @@ -143,33 +142,4 @@ public static OWLOntology merge (OWLOntologyManager manager, String mergeOntURIs

return mergedOnt;
}

public static OWLOntology mergeToTargetOnt (OWLOntologyManager manager, OWLOntology targetOnt, OWLOntology ont) {
Set<OWLAxiom> axs = ont.getAxioms();
for(OWLAxiom ax : axs) {
if (!targetOnt.containsAxiom(ax)) {
manager.applyChange(new AddAxiom(targetOnt, ax));
}
}

Optional<IRI> targetOntIRI = targetOnt.getOntologyID().getOntologyIRI();
Optional<IRI> ontIRI = ont.getOntologyID().getOntologyIRI();

System.out.println("All axioms in ontology " + ontIRI.toString() + " have been merged to the ontology " + targetOntIRI.toString());

return targetOnt;
}

public static OWLOntology setOntologyID (OWLOntologyManager manager, OWLOntology ont, String newIRIstr) {
String oldIRIstr = ont.getOntologyID().getOntologyIRI().toString();

if (newIRIstr.equals(oldIRIstr)) {
System.out.println("The new IRI: " + newIRIstr + " is same to the original one.");
} else {
SetOntologyID setOntoID =new SetOntologyID(ont,IRI.create(newIRIstr));
manager.applyChange(setOntoID);
}

return ont;
}
}