diff --git a/modules/tab-parser-2/src/main/java/net/sourceforge/ondex/plugins/tab_parser_2/TabParser2.java b/modules/tab-parser-2/src/main/java/net/sourceforge/ondex/plugins/tab_parser_2/TabParser2.java index 354dd6e5..059278f9 100644 --- a/modules/tab-parser-2/src/main/java/net/sourceforge/ondex/plugins/tab_parser_2/TabParser2.java +++ b/modules/tab-parser-2/src/main/java/net/sourceforge/ondex/plugins/tab_parser_2/TabParser2.java @@ -1,21 +1,19 @@ package net.sourceforge.ondex.plugins.tab_parser_2; import java.io.File; +import java.util.Arrays; import java.util.Collections; -import java.util.stream.Collectors; -import java.util.stream.Stream; +import java.util.Optional; import org.apache.log4j.Logger; -import com.google.common.base.Optional; +import com.machinezoo.noexception.CheckedExceptionHandler; import com.machinezoo.noexception.Exceptions; import net.sourceforge.ondex.ONDEXPluginArguments; import net.sourceforge.ondex.args.ArgumentDefinition; -import net.sourceforge.ondex.args.BooleanArgumentDefinition; import net.sourceforge.ondex.args.FileArgumentDefinition; -import net.sourceforge.ondex.core.ONDEXConcept; -import net.sourceforge.ondex.core.ONDEXRelation; +import net.sourceforge.ondex.args.StringArgumentDefinition; import net.sourceforge.ondex.parser.ONDEXParser; import net.sourceforge.ondex.plugins.tab_parser_2.config.ConfigParser; import net.sourceforge.ondex.tools.subgraph.Subgraph; @@ -33,7 +31,7 @@ * */ public class TabParser2 extends ONDEXParser -{ +{ private Logger log = Logger.getLogger ( this.getClass() ); public String getId () @@ -53,7 +51,7 @@ public String getVersion () public ArgumentDefinition[] getArgumentDefinitions () { - return new ArgumentDefinition[] { + return new ArgumentDefinition[] { new FileArgumentDefinition ( FileArgumentDefinition.INPUT_FILE, FileArgumentDefinition.INPUT_FILE_DESC, true, true, false, false ), @@ -64,9 +62,16 @@ public ArgumentDefinition[] getArgumentDefinitions () true, // preExisting false // isDirectory ), - new BooleanArgumentDefinition ( PathParser.MERGE_ACC, "Accession-based concept merging in the parser", false, true ), - new BooleanArgumentDefinition ( PathParser.MERGE_NAME, "Name-based concept merging in the parser", false, false ), - new BooleanArgumentDefinition ( PathParser.MERGE_GDS, "Data source-based concept merging in the parser", false, false ) + new StringArgumentDefinition ( + "mergeOptions", + "Merging options passed to PathParser, valid values are: " + + Arrays.toString ( PathParser.validFlags.toArray ( new String[ 0 ] ) ) + + ", default is " + PathParser.MERGE_ACC + + ", use '-' to specify none", + false, // required + PathParser.MERGE_ACC, // default + true // multiple vals + ) }; } @@ -79,33 +84,21 @@ public void start () throws Exception // The mapping parser returns an ONDEX parser straight PathParser tabParser = ConfigParser.parseConfigXml ( tabConfigXmlPath, graph, tabInputPath ); - // Merging flags - // - String[] mergeFlags = (String[]) Stream.of ( PathParser.MERGE_ACC, PathParser.MERGE_NAME, PathParser.MERGE_GDS ) - .filter ( flag -> - // Keeps it if it's true, else this kind of merging won't happen, because it won't be in the final - // processing options. - Boolean.TRUE.equals ( - Exceptions - // Wraps InvalidPluginArgumentException for getUniqueValue() into a RuntimeException - .wrap ( ex -> new IllegalArgumentException ( "Plug-in argument error: " + ex.getMessage (), ex ) ) - .get ( () -> (Boolean) args.getUniqueValue ( flag ) ) - ) - ) - .collect ( Collectors.toList () ) - .toArray ( new String [ 0 ] ); - - tabParser.setProcessingOptions ( mergeFlags ); + String[] mergeFlags = (String[]) args.getObjectValueArray ( "mergeOptions" ); + if ( ! ( mergeFlags == null || mergeFlags.length == 1 && "-".equals ( mergeFlags [ 0 ] ) ) ) + // Consider them if non null and non default + tabParser.setProcessingOptions ( mergeFlags ); Subgraph newGraph = tabParser.parse (); - int nconcepts = Optional.fromNullable ( newGraph.getConcepts () ).or ( Collections.emptySet () ).size (); - int nrelations = Optional.fromNullable ( newGraph.getRelations () ).or ( Collections.emptySet () ).size (); + int nconcepts = Optional.ofNullable ( newGraph.getConcepts () ).orElse ( Collections.emptySet () ).size (); + int nrelations = Optional.ofNullable ( newGraph.getRelations () ).orElse ( Collections.emptySet () ).size (); log.info ( String.format ( "Got %d concepts and %d relations from '%s'", nconcepts, nrelations, new File ( tabInputPath ).getAbsolutePath () )); } + public String[] requiresValidators () { diff --git a/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels.tsv b/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels.tsv index ad925a56..b8b9a75c 100755 --- a/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels.tsv +++ b/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels.tsv @@ -2,4 +2,4 @@ Ensembl Gene ID UniProt/SwissProt Accession Chromosome Name Gene Start (bp) Gene ENSG00000137845 O14672 15 58588807 58749978 Note 1 ENSG00000137845 O14672 15 58588807 58749978 Note 2 ENSG00000159082 O43426 21 32628759 32728048 Note 3 -ENSG00000115317 O43464 2 74529377 74533348 +ENSG00000115317 O43464 2 74529377 74533348 \ No newline at end of file diff --git a/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_cfg.xml b/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_cfg.xml index c24241ff..cc18b614 100644 --- a/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_cfg.xml +++ b/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_cfg.xml @@ -12,6 +12,7 @@ + ENSEMBL 9606 @@ -31,7 +32,9 @@ - ENSEMBL + + + UNIPROTKB diff --git a/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_wf.xml b/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_wf.xml index 428316fa..3c99ba8f 100644 --- a/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_wf.xml +++ b/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_wf.xml @@ -8,26 +8,22 @@ /Users/brandizi/Documents/Work/RRes/ondex_git/ondex-full/ondex-knet-builder/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels.tsv /Users/brandizi/Documents/Work/RRes/ondex_git/ondex-full/ondex-knet-builder/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels_cfg.xml - false - false - false + - default - - - - - + same-as + diff --git a/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_import_wf.xml b/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_import_wf.xml index c7e9127b..ac1c780c 100644 --- a/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_import_wf.xml +++ b/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_import_wf.xml @@ -6,8 +6,11 @@ default - /Users/brandizi/Documents/Work/RRes/ondex-code/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example.tsv - /Users/brandizi/Documents/Work/RRes/ondex-code/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_parser_cfg.xml + /Users/brandizi/Documents/Work/RRes/ondex_git/ondex-full/ondex-knet-builder/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example.tsv + /Users/brandizi/Documents/Work/RRes/ondex_git/ondex-full/ondex-knet-builder/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_parser_cfg.xml + true + false + false default diff --git a/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_parser_cfg.xml b/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_parser_cfg.xml index 88e25815..18f50cf7 100644 --- a/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_parser_cfg.xml +++ b/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_parser_cfg.xml @@ -12,6 +12,8 @@ + + ENSEMBL 9606 @@ -31,7 +33,9 @@ - ENSEMBL + UNIPROTKB + +