Skip to content

Commit

Permalink
Parameterising parser merge options (PathParser.setProcessingOptions()).
Browse files Browse the repository at this point in the history
This is possibly related to #8.
  • Loading branch information
marco-brandizi committed Jul 14, 2017
1 parent 2266a8e commit c0d907b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
21 changes: 21 additions & 0 deletions modules/tab-parser-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sourceforge.ondex.modules</groupId>
<artifactId>generic</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sourceforge.ondex.core</groupId>
<artifactId>lucene</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<!-- Cute utility that allows for quick handling of exceptions (eg, checked/unchecked wrapping) -->
<groupId>com.machinezoo.noexception</groupId>
<artifactId>noexception</artifactId>
<version>1.1.0</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import java.io.File;
import java.util.Collections;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.log4j.Logger;

import com.google.common.base.Optional;
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;
Expand Down Expand Up @@ -58,18 +63,40 @@ public ArgumentDefinition<?>[] getArgumentDefinitions ()
true, // required
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 )
};
}

public void start () throws Exception
{
String tabInputPath = (String) getArguments().getUniqueValue( FileArgumentDefinition.INPUT_FILE );
String tabConfigXmlPath = (String) getArguments().getUniqueValue( "configFile" );
ONDEXPluginArguments args = getArguments ();
String tabInputPath = (String) args.getUniqueValue( FileArgumentDefinition.INPUT_FILE );
String tabConfigXmlPath = (String) args.getUniqueValue( "configFile" );

// 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 );

Subgraph newGraph = tabParser.parse ();
int nconcepts = Optional.fromNullable ( newGraph.getConcepts () ).or ( Collections.<ONDEXConcept>emptySet () ).size ();
int nrelations = Optional.fromNullable ( newGraph.getRelations () ).or ( Collections.<ONDEXRelation>emptySet () ).size ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.Set;

import org.apache.log4j.Logger;
import org.junit.Ignore;
import org.junit.Test;

import com.google.common.io.Resources;
Expand Down Expand Up @@ -188,6 +187,15 @@ public void testDupedRelation () throws Exception
pp.setProcessingOptions ( new String [ 0 ] );
pp.parse ();

// Mapping cmap = new Mapping ();
// ONDEXPluginArguments args = new ONDEXPluginArguments ( cmap.getArgumentDefinitions () );
// args.addOption ( ArgumentNames.IGNORE_AMBIGUOUS_ARG, false );
// args.addOption ( ArgumentNames.RELATION_TYPE_ARG, "enc" );
// args.addOption ( ArgumentNames.WITHIN_DATASOURCE_ARG, true );
// cmap.setArguments ( args );;
// cmap.setONDEXGraph ( graph );
// cmap.start ();

log.info ( "Concepts: " + graph.getConcepts ().size () );
log.info ( "Relations: " + graph.getRelations ().size () );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,26 @@
<Parser name="tabParser2">
<Arg name="InputFile">/Users/brandizi/Documents/Work/RRes/ondex_git/ondex-full/ondex-knet-builder/modules/tab-parser-2/src/test/resources/duped_relations/duped_rels.tsv</Arg>
<Arg name="configFile">/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</Arg>
<Arg name="MERGE_ON_ACCESSIONS">false</Arg>
<Arg name="MERGE_ON_NAMES">false</Arg>
<Arg name="MERGE_ON_GDS">false</Arg>
<Arg name="graphId">default</Arg>
</Parser>

<!-- Mapping name="lowmemoryaccessionbased">
<Arg name="IgnoreAmbiguity">false</Arg>
<!- - Arg name="RelationType">collapse_me</Arg - ->
<Arg name="WithinDataSourceMapping">false</Arg>
<Arg name="graphId">default</Arg>
</Mapping -->

<!-- Transformer name="relationcollapser">
<Arg name="CloneAttributes">true</Arg>
<Arg name="CopyTagReferences">true</Arg>
<Arg name="graphId">default</Arg>
<Arg name="RelationType">enc</Arg>
</Transformer -->

</Workflow>
</Ondex>

0 comments on commit c0d907b

Please sign in to comment.