Skip to content

Commit

Permalink
Fixed some bugs in the console app during "postmerge" stage (while bu…
Browse files Browse the repository at this point in the history
…ilding actual data model...)
  • Loading branch information
IgorRodchenkov committed Feb 17, 2024
1 parent 3bf2758 commit b320921
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/main/java/cpath/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public static void main(String[] args) {
} else {
application.setWebApplicationType(WebApplicationType.NONE);
if (ArrayUtils.contains(args, "-b") || ArrayUtils.contains(args, "--build")) {
//enable biopax-validator context
//enable biopax-validator context (and LTW)
application.setAdditionalProfiles("admin", "premerge");
} else {
} else { //app run from console with -e or -a option (i.e. not as web app, not building the data instance)
application.setAdditionalProfiles("admin");
}
ConfigurableApplicationContext applicationContext = application.run(args);
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/cpath/service/CPathUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cpath.service;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand All @@ -15,7 +14,6 @@
import cpath.service.api.Cleaner;
import cpath.service.api.Converter;
import cpath.service.api.RelTypeVocab;
import cpath.service.metadata.Datasource;
import cpath.service.metadata.Metadata;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -83,7 +81,7 @@ static void saveMetadata(Metadata metadata, String path) {
path = StringUtils.substringAfter(path, ":");
}
try {
new ObjectMapper().writeValue(Files.newOutputStream(Paths.get(path)), metadata);
new ObjectMapper().writerWithDefaultPrettyPrinter().writeValue(Files.newOutputStream(Paths.get(path)), metadata);
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -345,15 +343,6 @@ static InputStream gzipInputStream(String gzPath) {
}


/**
* Generate a URI (for a Provenance instance.)
*
* @return URI
*/
static String getMetadataUri(Model model, Datasource datasource) {
return model.getXmlBase() + datasource.getIdentifier();
}

/**
* For the given converter class name,
* returns an instance of a class which
Expand Down
57 changes: 30 additions & 27 deletions src/main/java/cpath/service/ConsoleApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ public class ConsoleApplication implements CommandLineRunner {
enum Stage {
PREMERGE,
MERGE,
POSTMERGE
POSTMERGE;

static Stage toType(String stage) {
return Arrays.stream(Stage.values()).filter(s -> s.name().equalsIgnoreCase(stage)).findFirst().orElse(PREMERGE);
}
}

@Override
Expand Down Expand Up @@ -104,25 +108,21 @@ public void run(String... args) throws Exception {

if (cmd.hasOption("build")) {
//Perform the data build from given stage (or from "premerge" when no value provided) to the end.
Stage stage;
try {
stage = Stage.valueOf(cmd.getOptionValue("build").toUpperCase());
} catch (Exception e) {
stage = Stage.PREMERGE;
}
String optVal = cmd.getOptionValue("build");
Stage stage = Stage.toType(optVal);
switch ((stage != null) ? stage : Stage.PREMERGE) {
case PREMERGE:
premerge(); //, and continue to "merge"
premerge(); //and continue to "merge"
case MERGE:
merge();
merge(); //and continue to "postmerge"
case POSTMERGE:
postmerge(); //is the final stage
postmerge(); //the final stage
}
} else if (cmd.hasOption("export")) {
}
else if (cmd.hasOption("export")) {
String[] uris = new String[]{};
String[] datasources = new String[]{};
String[] types = new String[]{};

if (cmd.hasOption("F")) {
Properties properties = cmd.getOptionProperties("F");
if (properties.contains("uris")) {
Expand All @@ -134,9 +134,11 @@ public void run(String... args) throws Exception {
}
}
exportData(cmd.getOptionValue("export"), uris, datasources, types);
} else if (cmd.hasOption("analyze")) {
}
else if (cmd.hasOption("analyze")) {
executeAnalysis(cmd.getOptionValue("analyze"), true);
} else {
}
else {
new HelpFormatter().printHelp("cPath2", options);
}
}
Expand Down Expand Up @@ -279,7 +281,6 @@ private Class<? extends BioPAXElement> biopaxTypeFromSimpleName(String type) {

private void postmerge() throws IOException {
LOG.info("postmerge: started");
Model model;
// Updates counts of pathways, etc. and saves in the Metadata table.
// This depends on the full-text index created already
LOG.info("updating pathway/interaction/participant counts per data source...");
Expand All @@ -289,17 +290,17 @@ private void postmerge() throws IOException {
if(ds.getType().isNotPathwayData()) {
continue;
}
model = service.loadBiopaxModelByDatasource(ds);
Model model = service.loadBiopaxModelByDatasource(ds);
ds.setNumPathways(model.getObjects(Pathway.class).size());
ds.setNumInteractions(model.getObjects(Interaction.class).size());
ds.setNumPhysicalEntities(model.getObjects(PhysicalEntity.class).size() + model.getObjects(Gene.class).size());
}
CPathUtils.saveMetadata(service.metadata(), service.settings().getMetadataLocation()); //update the json file

//load the main model
LOG.info("loading the Main BioPAX Model...");
model = CPathUtils.importFromTheArchive(service.settings().mainModelFile());
LOG.info("loaded");
//init the service - load main model and index
service.init();
final Model mainModel = service.getModel();
LOG.info("loaded main model:{} biopax elements", mainModel.getObjects().size());

// create an imported data summary file.txt (issue#23)
PrintWriter writer = new PrintWriter(new OutputStreamWriter(Files.newOutputStream(
Expand All @@ -311,9 +312,11 @@ private void postmerge() throws IOException {
writer.println("#Columns:\t" + String.join("\t", Arrays.asList(
"ID", "DESCRIPTION", "TYPE", "HOMEPAGE", "PATHWAYS", "INTERACTIONS", "PARTICIPANTS")));
for (Datasource d : service.metadata().getDatasources()) {
writer.println(StringUtils.join(Arrays.asList(
CPathUtils.getMetadataUri(model, d), d.getDescription(), d.getType(), d.getHomepageUrl(),
d.getNumPathways(), d.getNumInteractions(), d.getNumPhysicalEntities()), "\t"));
String record = StringUtils.join(Arrays.asList(
service.settings().getXmlBase()+d.getIdentifier(), d.getDescription(), d.getType(), d.getHomepageUrl(),
d.getNumPathways(), d.getNumInteractions(), d.getNumPhysicalEntities()), "\t");
writer.println(record);
LOG.info(record);
}
writer.flush();
writer.close();
Expand All @@ -322,8 +325,8 @@ private void postmerge() throws IOException {
LOG.info("creating the list of primary uniprot ACs...");
Set<String> acs = new TreeSet<>();
//exclude publication xrefs
Set<Xref> xrefs = new HashSet<>(model.getObjects(UnificationXref.class));
xrefs.addAll(model.getObjects(RelationshipXref.class));
Set<Xref> xrefs = new HashSet<>(mainModel.getObjects(UnificationXref.class));
xrefs.addAll(mainModel.getObjects(RelationshipXref.class));
for (Xref x : xrefs) {
String id = x.getId();
if (CPathUtils.startsWithAnyIgnoreCase(x.getDb(), "uniprot")
Expand All @@ -343,9 +346,9 @@ private void postmerge() throws IOException {
LOG.info("generated uniprot.txt");

LOG.info("init the full-text search engine...");
final Index index = new IndexImpl(model, service.settings().indexDir(), false);
final Index index = new IndexImpl(mainModel, service.settings().indexDir(), false);
// generate the "Detailed" pathway data file:
createDetailedBiopax(model, index);
createDetailedBiopax(mainModel, index);

// generate the export.sh script (to run Paxtools commands for exporting the BioPAX files to other formats)
LOG.info("writing 'export.sh' script to convert the BioPAX models to SIF, GSEA, SBGN...");
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cpath/service/ServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public ServiceImpl() {
/**
* Loads the main BioPAX model, full-text index, blacklist.
* Call this only after the web service is up and running.
* (This is not called for the console app)
*/
synchronized public void init() {
if(paxtoolsModel == null) {
Expand Down
2 changes: 1 addition & 1 deletion work/metadata.v14.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"UniProtKB"
],
"converterClass": "cpath.converter.UniprotConverter",
"description": "UniProtKB/Swiss-Prot (human), v246, 24-Jan-2024",
"description": "UniProtKB/Swiss-Prot (human), release 2024_01",
"iconUrl": "https://pathwaycommons.github.io/cpath2/logos/uniprot.png",
"availability": "free",
"type": "WAREHOUSE",
Expand Down

0 comments on commit b320921

Please sign in to comment.