Last active
May 10, 2021 12:53
-
-
Save cannin/b6f7ba64e1156b001282 to your computer and use it in GitHub Desktop.
BioPAX Tutorial; Examples from the Paxtools User's Guide. (PubMed ID: 24068901 Link: https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1003194)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//BASIC TRAVERSAL | |
// Get names for all elements in a BioPAX OWL file and then for just Proteins | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.model.BioPAXElement; | |
import org.biopax.paxtools.model.level3.Protein; | |
// Load a sample test BioPAX File via Simple IO Handler | |
InputStream f = new FileInputStream(new File("data/biopax3-short-metabolic-pathway.owl")); | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
// Iterate through all BioPAX Elements and print basic info | |
println "ALL ELEMENTS:\n"; | |
Set<BioPAXElement> elementSet = model.getObjects(); | |
for (BioPAXElement currentElement : elementSet) { | |
String rdfId = currentElement.getRDFId(); | |
String className = currentElement.getClass().getName(); | |
println("Element: " + rdfId + ": " + className); | |
} | |
// Get Proteins Only | |
println "\nPROTEINS ONLY:\n"; | |
Set<Protein> proteinSet = model.getObjects(Protein.class); | |
for (Protein currentProtein : proteinSet) { | |
println(currentProtein.getName() + ": " + currentProtein.getDisplayName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//COMBINED EXAMPLE | |
// Combined example | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.model.BioPAXElement; | |
import org.biopax.paxtools.model.level3.Interaction; | |
import org.biopax.paxtools.model.level3.Xref; | |
import org.biopax.paxtools.query.QueryExecuter; | |
import org.biopax.paxtools.query.algorithm.Direction; | |
import org.biopax.paxtools.query.algorithm.LimitType; | |
import org.biopax.paxtools.controller.EditorMap; | |
import org.biopax.paxtools.controller.SimpleEditorMap; | |
import org.biopax.paxtools.controller.Completer; | |
import org.biopax.paxtools.controller.Cloner; | |
import org.biopax.paxtools.pattern.miner.SIFSearcher; | |
import org.biopax.paxtools.pattern.miner.SIFEnum; | |
import org.biopax.paxtools.model.BioPAXLevel; | |
Set<BioPAXElement> findElements(Model model, String[] ids) { | |
Set<BioPAXElement> set = new HashSet<BioPAXElement>(); | |
for (String id : ids) { | |
BioPAXElement bpe = model.getByID(id); | |
if (bpe != null) { | |
set.add(bpe); | |
} | |
} | |
return set; | |
} | |
// READ FILE | |
InputStream f = new FileInputStream(new File("data/raf_map_kinase_cascade_reactome.owl")); | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
// RUN GRAPH QUERY | |
source = findElements(model, "HTTP://WWW.REACTOME.ORG/BIOPAX/48887#PROTEIN1630_1_9606"); //phospho-Cdc2 | |
target = findElements(model, "HTTP://WWW.REACTOME.ORG/BIOPAX/48887#PROTEIN1624_1_9606"); //MEK1 | |
result = QueryExecuter.runPathsFromTo(source, target, model, LimitType.NORMAL, 3); | |
// COMPLETE MODEL | |
Completer c = new Completer(SimpleEditorMap.L3); | |
result = c.complete(result, model); | |
Cloner cln = new Cloner(SimpleEditorMap.L3, BioPAXLevel.L3.getDefaultFactory()); | |
Model excisedModel = cln.clone(model, result) | |
// EXTRACT PUBMED XREFS FOR REMAINING INTERACTIONS | |
for (Interaction interaction : excisedModel.getObjects(Interaction.class)) { | |
// Print the name of the interaction | |
System.out.println("* " + interaction.getDisplayName()); | |
// Get all external references | |
for (Xref xref : interaction.getXref()) { | |
String db = xref.getDb(); | |
String id = xref.getId(); | |
String url = ""; | |
// Convert PubMed ids to URLs for easy access | |
if (db.equalsIgnoreCase("PubMed")) { | |
url = " (http://www.ncbi.nlm.nih.gov/pubmed/" + id + ")"; | |
// Print the external reference information | |
System.out.println("\t" + xref.getDb() + ":" + xref.getId() + url); | |
} | |
} | |
} | |
// SIF CONVERSION | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
// null in first pattern forces return HGNC IDs | |
SIFSearcher searcher = new SIFSearcher(null, SIFEnum.values()); | |
searcher.searchSIF(excisedModel, os, false); | |
System.out.println("\nCONTENTS:\n\n" + os); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EXCISOR | |
// Excise a ProteinReference from the model | |
import org.biopax.paxtools.controller.EditorMap; | |
import org.biopax.paxtools.controller.SimpleEditorMap; | |
import org.biopax.paxtools.controller.Completer; | |
import org.biopax.paxtools.controller.Cloner; | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.BioPAXLevel; | |
import org.biopax.paxtools.model.BioPAXElement; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.model.level3.ProteinReference; | |
import org.biopax.paxtools.model.level3.UnificationXref; | |
Model excise(Model model, Set<BioPAXElement> result) { | |
Completer c = new Completer(SimpleEditorMap.L3); | |
result = c.complete(result, model); | |
Cloner cln = new Cloner(SimpleEditorMap.L3, BioPAXLevel.L3.getDefaultFactory()); | |
return cln.clone(model, result); | |
} | |
Set<BioPAXElement> findElements(Model model, String[] ids) { | |
Set<BioPAXElement> set = new HashSet<BioPAXElement>(); | |
for (String id : ids) { | |
BioPAXElement bpe = model.getByID(id); | |
if (bpe != null) { | |
set.add(bpe); | |
} | |
} | |
return set; | |
} | |
InputStream f = new FileInputStream(new File("data/intrinsic_apoptosis_reactome.owl")) | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
//MEK1 | |
String[] ids = ["http://www.reactome.org/biopax/52/109606#ProteinReference1"]; | |
Set<BioPAXElement> result = findElements(model, ids); | |
Model clonedModel = excise(model, result); | |
System.out.println("UnificationXref COUNT:"); | |
System.out.println("ORIGINAL MODEL: " + model.getObjects(UnificationXref.class).size()); | |
System.out.println("EXTRACTED MODEL: " + clonedModel.getObjects(UnificationXref.class).size()); | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
handler.convertToOWL(clonedModel, os); | |
String output = new String(os.toByteArray()); | |
System.out.println("\nCONTENTS:\n\n" + output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EXPORT SIF | |
// Export model to SIF | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.pattern.miner.SIFSearcher; | |
import org.biopax.paxtools.pattern.miner.SIFEnum; | |
InputStream f = new FileInputStream(new File("data/raf_map_kinase_cascade_reactome.owl")); | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
// null in first pattern forces return HGNC IDs | |
SIFSearcher searcher = new SIFSearcher(null, SIFEnum.values()); | |
searcher.searchSIF(model, os, false); | |
System.out.println("CONTENTS:\n\n" + os); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First Model | |
// Create a simple model with one protein and one reaction where the protein as a reaction participant | |
import org.biopax.paxtools.model.BioPAXFactory; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.model.BioPAXLevel; | |
import org.biopax.paxtools.model.level3.Protein; | |
import org.biopax.paxtools.model.level3.BiochemicalReaction; | |
import org.biopax.paxtools.model.level3.PhysicalEntity; | |
BioPAXFactory factory = BioPAXLevel.L3.getDefaultFactory(); | |
Model model = factory.createModel(); | |
model.setXmlBase("http://biopax.org/tutorial/"); | |
Protein protein1 = model.addNew(Protein.class, "http://biopax.org/tutorial/test1"); | |
protein1.addName("Tutorial Example Some Transporter 1"); | |
protein1.setDisplayName("TEST1"); | |
Protein retrievedProtein = model.getByID("http://biopax.org/tutorial/test1"); | |
println("DISPLAY NAME: " + retrievedProtein.getDisplayName()); | |
BiochemicalReaction rxn1 = model.addNew(BiochemicalReaction.class, "http://biopax.org/tutorial/rxn1"); | |
rxn1.addLeft(protein1); | |
Set<PhysicalEntity> reactants = rxn1.getLeft(); | |
for(reactant in reactants) { | |
println("LEFT REACTANT: " + reactant.getDisplayName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//GRAPH QUERY | |
// Run graph queries: "Paths From To" and "Neighborhood" | |
import org.biopax.paxtools.controller.Cloner; | |
import org.biopax.paxtools.controller.Completer; | |
import org.biopax.paxtools.controller.SimpleEditorMap; | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.BioPAXElement; | |
import org.biopax.paxtools.model.BioPAXLevel; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.query.QueryExecuter; | |
import org.biopax.paxtools.query.algorithm.Direction; | |
import org.biopax.paxtools.query.algorithm.LimitType; | |
import org.biopax.paxtools.io.sif.SimpleInteractionConverter; | |
Set<BioPAXElement> findElements(Model model, String[] ids) { | |
Set<BioPAXElement> set = new HashSet<BioPAXElement>(); | |
for (String id : ids) { | |
BioPAXElement bpe = model.getByID(id); | |
if (bpe != null) { | |
set.add(bpe); | |
} | |
} | |
return set; | |
} | |
InputStream f = new FileInputStream(new File("data/raf_map_kinase_cascade_reactome.owl")) | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
source = findElements(model, "HTTP://WWW.REACTOME.ORG/BIOPAX/48887#PROTEIN1630_1_9606"); //phospho-Cdc2 | |
target = findElements(model, "HTTP://WWW.REACTOME.ORG/BIOPAX/48887#PROTEIN1624_1_9606"); //MEK1 | |
result1 = QueryExecuter.runPathsFromTo(source, target, model, LimitType.NORMAL, 3); | |
System.out.println("RS: " + result1.size()); | |
for (BioPAXElement currentElement : result1) { | |
String rdfId = currentElement.getRDFId(); | |
String className = currentElement.getClass().getName(); | |
println("Element: " + rdfId + ": " + className); | |
} | |
Set<BioPAXElement> source = findElements(model, "HTTP://WWW.REACTOME.ORG/BIOPAX/48887#PROTEIN2360_1_9606"); //MEK2 | |
Set<BioPAXElement> result2 = QueryExecuter.runNeighborhood(source, model, 1, Direction.BOTHSTREAM); | |
System.out.println("RS2: " + result2.size()); | |
for (BioPAXElement currentElement : result2) { | |
String rdfId = currentElement.getRDFId(); | |
String className = currentElement.getClass().getName(); | |
println("Element: " + rdfId + ": " + className); | |
} | |
Completer c = new Completer(SimpleEditorMap.get(BioPAXLevel.L3)); | |
result2 = c.complete(result2, model); | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
SimpleInteractionConverter sifConverter = new SimpleInteractionConverter(); | |
sifConverter.writeInteractionsInSIF(result, os); | |
System.out.println("CONTENTS:\n\n" + os); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// List files in directory | |
File folder = new File("data"); | |
File[] files = folder.listFiles(); | |
for(File file in files) { | |
System.out.println(file.getName()) | |
} | |
// Get file contents | |
String fileContents = new File('data/biopax3-short-metabolic-pathway.owl').text | |
System.out.println("Contents:\n\n" + fileContents) | |
// Load file as InputStream | |
InputStream f = new FileInputStream(new File("data/biopax3-short-metabolic-pathway.owl")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//LIST PROPERTIES | |
// Display all properties for model objects | |
import org.biopax.paxtools.controller.EditorMap; | |
import org.biopax.paxtools.controller.SimpleEditorMap; | |
import org.biopax.paxtools.controller.PropertyEditor; | |
import org.biopax.paxtools.model.BioPAXElement; | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
String[][] listProperties(BioPAXElement bpe) { | |
// In order to use properties we first need an EditorMap | |
EditorMap editorMap = SimpleEditorMap.L3; | |
// And then get all the editors for our biopax element | |
Set<PropertyEditor> editors = editorMap.getEditorsOf(bpe); | |
// For each property | |
for (PropertyEditor editor : editors) { | |
// First column is the name of the property, e.g. "Name" | |
// Second column is the value e.g. "p53" | |
println("Property: " + editor.getProperty() + | |
" Value: " + editor.getValueFromBean(bpe).toString()); | |
} | |
} | |
// Load a sample test BioPAX File via Simple IO Handler | |
InputStream f = new FileInputStream(new File("data/biopax3-short-metabolic-pathway.owl")); | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
Set<BioPAXElement> elementSet = model.getObjects(); | |
for (BioPAXElement currentElement : elementSet) { | |
listProperties(currentElement); | |
println("\n") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MERGER | |
// Merge to BioPAX OWL files | |
import org.biopax.paxtools.controller.EditorMap; | |
import org.biopax.paxtools.controller.SimpleEditorMap; | |
import org.biopax.paxtools.controller.Merger; | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.model.BioPAXElement; | |
EditorMap editorMap = SimpleEditorMap.L3; | |
InputStream f1 = new FileInputStream(new File("data/biopax3-short-metabolic-pathway.owl")) | |
InputStream f2 = new FileInputStream(new File("data/raf_map_kinase_cascade_reactome.owl")) | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model srcModel1 = handler.convertFromOWL(f1); | |
Model srcModel2 = handler.convertFromOWL(f2); | |
Model targetModel = editorMap.getLevel().getDefaultFactory().createModel(); | |
Merger merger = new Merger(editorMap); | |
merger.merge(targetModel, srcModel1, srcModel2); | |
String id1 = "http://www.biopax.org/examples/myExampleProtein_54"; | |
String id2 = "HTTP://WWW.REACTOME.ORG/BIOPAX/48887#PROTEIN1643_1_9606"; | |
BioPAXElement bpe1 = targetModel.getByID(id1); | |
BioPAXElement bpe2 = targetModel.getByID(id2); | |
if (bpe1 != null && bpe2 != null) { | |
System.out.println("BOTH FOUND\n"); | |
} else { | |
System.out.println("ERROR\n"); | |
} | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
handler.convertToOWL(targetModel, os); | |
String output = new String(os.toByteArray()); | |
System.out.println("CONTENTS:\n\n" + output); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PATHACCESSORS | |
// Extract UnificationXRefs for Proteins that pathwayComponents | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.model.level3.Pathway; | |
import org.biopax.paxtools.model.level3.Xref; | |
import org.biopax.paxtools.controller.PathAccessor; | |
InputStream f = new FileInputStream(new File("data/akt_signaling_pathway.owl")) | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
// Set up the Path Accessor | |
PathAccessor pathAccessor = new PathAccessor("Pathway/pathwayComponent*:Protein/entityReference/xref:UnificationXref"); | |
// Iterate through all proteins in the model | |
for(Pathway currentPathway : model.getObjects(Pathway.class)) { | |
println("Pathway:" + currentPathway.getName()); | |
Set<Xref> unificationXrefs = pathAccessor.getValueFromBean(currentPathway); | |
for(Xref currentRef : unificationXrefs) { | |
println("Unification XRef: " + currentRef.getDb() + ": " + currentRef.getId()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//PATTERNS | |
// Print protein pairs that are in the same complex | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
import org.biopax.paxtools.model.level3.ProteinReference; | |
import org.biopax.paxtools.pattern.constraint.*; | |
import org.biopax.paxtools.pattern.*; | |
import org.biopax.paxtools.model.level3.Complex; | |
InputStream f = new FileInputStream(new File("data/akt_signaling_pathway.owl")) | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
// Set up the pattern | |
Pattern p = new Pattern(ProteinReference.class, "Protein 1"); | |
p.add(ConBox.erToPE(), "Protein 1", "SPE1"); | |
p.add(ConBox.linkToComplex(), "SPE1", "Complex"); | |
p.add(new Type(Complex.class), "Complex"); | |
p.add(ConBox.linkToSimple(), "Complex", "SPE2"); | |
p.add(ConBox.peToER(), "SPE2", "Protein 2"); | |
p.add(ConBox.equal(false), "Protein 1", "Protein 2"); | |
p.add(new Type(ProteinReference.class), "Protein 2"); | |
List<Match> matches = Searcher.searchPlain(model, p); | |
for (Match match : matches) | |
{ | |
ProteinReference pr1 = (ProteinReference) match.get("Protein 1", p); | |
ProteinReference pr2 = (ProteinReference) match.get("Protein 2", p); | |
println(pr1.getDisplayName() + " is in same complex with " + pr2.getDisplayName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SIMPLEIO | |
// Read BioPAX OWL file and extract properties for a given protein | |
import org.biopax.paxtools.io.BioPAXIOHandler; | |
import org.biopax.paxtools.io.SimpleIOHandler; | |
import org.biopax.paxtools.model.Model; | |
InputStream f = new FileInputStream(new File("data/biopax3-short-metabolic-pathway.owl")) | |
BioPAXIOHandler handler = new SimpleIOHandler(); | |
Model model = handler.convertFromOWL(f); | |
String id1 = "http://www.biopax.org/examples/myExampleProtein_54"; | |
ByteArrayOutputStream os = new ByteArrayOutputStream(); | |
handler.convertToOWL(model, os, id1); | |
String output = new String(os.toByteArray()); | |
println("CONTENTS:\n\n" + output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment