8000 Add Excel format to export by beckyjackson · Pull Request #646 · ontodev/robot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Excel format to export #646

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

Merged
merged 13 commits into from
Mar 6, 2020
Merged
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Add [`export`] command [#481]
- Add JSON format to [`export`] in [#645]
- Add Excel format to [`export`] in [#646]

### Fixed
- Fix filtering axioms with multiple axiom selectors [#644]

Expand Down Expand Up @@ -158,6 +163,7 @@ First official release of ROBOT!
[`convert`]: http://robot.obolibrary.org/convert
[`diff`]: http://robot.obolibrary.org/diff
[`explain`]: http://robot.obolibrary.org/explain
[`export`]: http://robot.obolibrary.org/export
[`extract`]: http://robot.obolibrary.org/extract
[`filter`]: http://robot.obolibrary.org/filter
[`merge`]: http://robot.obolibrary.org/merge
Expand All @@ -171,6 +177,8 @@ First official release of ROBOT!
[`report`]: http://robot.obolibrary.org/report
[`template`]: http://robot.obolibrary.org/template

[#646]: https://github.com/ontodev/robot/issues/646
[#645]: https://github.com/ontodev/robot/issues/645
[#644]: https://github.com/ontodev/robot/issues/644
[#630]: https://github.com/ontodev/robot/issues/630
[#625]: https://github.com/ontodev/robot/issues/625
Expand Down Expand Up @@ -199,6 +207,7 @@ First official release of ROBOT!
[#507]: https://github.com/ontodev/robot/issues/507
[#488]: https://github.com/ontodev/robot/issues/488
[#484]: https://github.com/ontodev/robot/issues/484
[#481]: https://github.com/ontodev/robot/issues/481
[#475]: https://github.com/ontodev/robot/issues/475
[#471]: https://github.com/ontodev/robot/issues/471
[#461]: https://github.com/ontodev/robot/issues/461
Expand Down
169 changes: 169 additions & 0 deletions docs/examples/nucleus.json
10000
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
[
{
"ID": "GO:0005575",
"LABEL": [
"cellular_component"
]
},
{
"ID": "GO:0005622",
"LABEL": [
"intracellular"
],
"SubClass Of": [
"cell part"
]
},
{
"ID": "GO:0005623",
"LABEL": [
"cell"
],
"SubClass Of": [
"cellular_component"
]
},
{
"ID": "GO:0005634",
"LABEL": [
"nucleus"
],
"SubClass Of": [
"intracellular membrane-bounded organelle"
]
},
{
"ID": "GO:0031974",
"LABEL": [
"membrane-enclosed lumen"
],
"SubClass Of": [
"cellular_component"
]
},
{
"ID": "GO:0031981",
"LABEL": [
"nuclear lumen"
],
"SubClass Of": [
"'part of' some nucleus",
"intracellular organelle lumen",
"nuclear part"
]
},
{
"ID": "GO:0043226",
"LABEL": [
"organelle"
],
"SubClass Of": [
"cellular_component"
]
},
{
"ID": "GO:0043227",
"LABEL": [
"membrane-bounded organelle"
],
"SubClass Of": [
"organelle"
]
},
{
"ID": "GO:0043229",
"LABEL": [
"intracellular organelle"
],
"SubClass Of": [
"'part of' some intracellular",
"intracellular part",
"organelle"
]
},
{
"ID": "GO:0043231",
"LABEL": [
"intracellular membrane-bounded organelle"
],
"SubClass Of": [
"intracellular organelle",
"membrane-bounded organelle"
]
},
{
"ID": "GO:0043233",
"LABEL": [
"organelle lumen"
],
"SubClass Of": [
"'part of' some organelle",
"membrane-enclosed lumen",
"organelle part"
]
},
{
"ID": "GO:0044422",
"LABEL": [
"organelle part"
],
"SubClass Of": [
"'part of' some organelle",
"cellular_component"
]
},
{
"ID": "GO:0044424",
"LABEL": [
"intracellular part"
],
"SubClass Of": [
"'part of' some intracellular",
"cell part"
]
},
{
"ID": "GO:0044428",
"LABEL": [
"nuclear part"
],
"SubClass Of": [
"'part of' some nucleus",
"intracellular organelle part"
]
},
{
"ID": "GO:0044446",
"LABEL": [
"intracellular organelle part"
],
"SubClass Of": [
"'part of' some 'intracellular organelle'",
"'part of' some intracellular",
"'part of' some organelle",
"intracellular part",
"organelle part"
]
},
{
"ID": "GO:0044464",
"LABEL": [
"cell part"
],
"SubClass Of": [
"'part of' some cell",
"cellular_component"
]
},
{
"ID": "GO:0070013",
"LABEL": [
"intracellular organelle lumen"
],
"SubClass Of": [
"'part of' some 'intracellular organelle'",
"intracellular organelle part",
"organelle lumen"
]
}
]
18 changes: 11 additions & 7 deletions docs/export.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@ robot export --input nucleus_part_of.owl \

The following formats are currently supported:

* `tsv`
* `csv`
* `html`
* `tsv` - tab-separated file, default format for unknown extensions
* `csv` - comma-separated file
* `html` - HTML table with with [Bootstrap](https://getbootstrap.com/) styling
* `json` - JSON file with values as arrays (except for ID/CURIE and IRI, which are single strings)
* `xlsx` - Excel workbook with contents on first sheet

These can be specified with the `--format` option:

robot export --input nucleus_part_of.owl \
--header "LABEL|SubClass Of" \
--format html --export results/nucleus.html

If this option is not included, `export` will predict the format based on the file extension. If the extension does not match with an existing format, it will default to `tsv`.

The `html` format will output an HTML table with [Bootstrap](https://getbootstrap.com/) styling. All entities referenced will be rendered as clickable li 9E7A nks.
If this option is not included, `export` will predict the format based on the file extension:

robot export --input nucleus_part_of.owl \
--header "ID|LABEL|SubClass Of" \
--export results/nucleus.json

### Columns

Expand Down Expand Up @@ -160,7 +164,7 @@ A property cannot be resolved, usually meaning that the label cannot be resolved

### Unknown Format Error

The following formats are currently supported: `tsv`, `csv`, and `html`. Please make sure you are using one of these formats.
The following formats are currently supported: `tsv`, `csv`, `html`, `json`, and `xlsx`. Please make sure you are using one of these formats.

### Unknown Tag Error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
package org.obolibrary.robot;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.io.FilenameUtils;
import org.obolibrary.robot.export.Table;
import org.semanticweb.owlapi.model.OWLOntology;

public class ExportCommand implements Command {

/** Store the command-line options for the command. */
private Options options;

/** Namespace for error messages. */
private static final String NS = "export#";

private static final String unknownFormatError =
NS + "UNKNOWN FORMAT ERROR --format %s must be one of: csv, html, json, tsv, or xlsx";

/** Supported output formats. If the output format is not one of these, it will default to TSV. */
private final List<String> supportedFormats = Arrays.asList("csv", "html", "json", "tsv", "xlsx");

/** Initialize the command. */
public ExportCommand() {
Options o = CommandLineHelper.getCommonOptions();
Expand All @@ -24,7 +34,7 @@ public ExportCommand() {
o.addOption("A", "exclude-anonymous", true, "if true, exclude anonymous entities");
o.addOption("s", "sort", true, "column to sort on (default: first column)");
o.addOption("n", "include", true, "groups of terms to include");
o.addOption("f", "format", true, "output file format (TSV, CSV, or HTML)");
o.addOption("f", "format", true, "output file format");
o.addOption("S", "split", true, "character to split multiple values on (default: |)");
o.addOption(
"E",
Expand Down Expand Up @@ -131,16 +141,23 @@ public CommandState execute(CommandState state, String[] args) throws Exception
String format = CommandLineHelper.getOptionalValue(line, "format");
if (format == null) {
// Use the path to determine the format (default is TSV)
if (exportPath.endsWith(".csv")) {
exportOptions.put("format", "csv");
} else if (exportPath.endsWith(".html")) {
exportOptions.put("format", "html");
String ext = FilenameUtils.getExtension(exportPath).toLowerCase();
if (supportedFormats.contains(ext)) {
exportOptions.put("format", ext);
} else {
// Unknown extension, use tab-separated
exportOptions.put("format", "tsv");
}
} else if (!supportedFormats.contains(format)) {
// If a format WAS provided and it's not in the supported formats, throw an error
throw new Exception(String.format(unknownFormatError, format));
}

// Get the split columns
List<String> columns = Arrays.asList(headerString.split("\\|"));

ExportOperation.export(ontology, ioHelper, columns, new File(exportPath), exportOptions);
Table t = ExportOperation.createExportTable(ontology, ioHelper, columns, exportOptions);
ExportOperation.saveTable(t, exportPath, exportOptions);
return state;
}
}
15 changes: 15 additions & 0 deletions robot-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
<artifactId>jena-tdb</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>com.github.jsonld-java</groupId>
<artifactId>jsonld-java</artifactId>
Expand Down Expand Up @@ -153,5 +163,10 @@
<artifactId>owl-diff_2.12</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
</dependencies>
</project>
Loading
0