Skip to content

Commit

Permalink
Some debugging and improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-brandizi committed Jul 15, 2017
1 parent 6322a50 commit 8a880db
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 50 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -33,7 +31,7 @@
*
*/
public class TabParser2 extends ONDEXParser
{
{
private Logger log = Logger.getLogger ( this.getClass() );

public String getId ()
Expand All @@ -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
),
Expand All @@ -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
)
};
}

Expand All @@ -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.<ONDEXConcept>emptySet () ).size ();
int nrelations = Optional.fromNullable ( newGraph.getRelations () ).or ( Collections.<ONDEXRelation>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 ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<column index = '0' />
</accession>
<name><column index = '0' /></name>
<parser-id><column index = '0' /></parser-id>
<data-source>ENSEMBL</data-source>
<attribute name="TAXID" type = "TEXT" indexed = 'false'>9606</attribute>
<attribute name="Chromosome" type = "INTEGER">
Expand All @@ -31,7 +32,9 @@
<accession data-source="UNIPROTKB"><!-- ambiguous is false by default -->
<column index = '1'/>
</accession>
<data-source>ENSEMBL</data-source>
<name><column index = '1' /></name>
<parser-id><column index = '1' /></parser-id>
<data-source>UNIPROTKB</data-source>
</concept>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@
<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="mergeOptions">-</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">
<Mapping name="lowmemoryaccessionbased">
<Arg name="IgnoreAmbiguity">false</Arg>
<Arg name="RelationType">same-as</Arg>
<Arg name="WithinDataSourceMapping">true</Arg>
<Arg name="graphId">default</Arg>
<Arg name="EquivalentConceptClass">Gene,Gene;Protein,Protein</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 -->

<Arg name="RelationType">same-as</Arg>
</Transformer>
</Workflow>
</Ondex>

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
<Arg name="graphId">default</Arg>
</Graph>
<Parser name="tabParser2">
<Arg name="InputFile">/Users/brandizi/Documents/Work/RRes/ondex-code/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example.tsv</Arg>
<Arg name="configFile">/Users/brandizi/Documents/Work/RRes/ondex-code/modules/tab-parser-2/src/test/resources/ondex_tutorial_2016/gene_example_parser_cfg.xml</Arg>
<Arg name="InputFile">/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</Arg>
<Arg name="configFile">/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</Arg>
<Arg name="MERGE_ON_ACCESSIONS">true</Arg>
<Arg name="MERGE_ON_NAMES">false</Arg>
<Arg name="MERGE_ON_GDS">false</Arg>
<Arg name="graphId">default</Arg>
</Parser>
</Workflow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<column index = '0' />
</accession>
<name><column index = '0' /></name>
<parser-id><column index = '0' /></parser-id>

<data-source>ENSEMBL</data-source>
<attribute name="TAXID" type = "TEXT" indexed = 'false'>9606</attribute>
<attribute name="Chromosome" type = "INTEGER">
Expand All @@ -31,7 +33,9 @@
<accession data-source="UNIPROTKB"><!-- ambiguous is false by default -->
<column index = '1'/>
</accession>
<data-source>ENSEMBL</data-source>
<data-source>UNIPROTKB</data-source>
<name><column index = '1' /></name>
<parser-id><column index = '1' /></parser-id>
</concept>


Expand Down

0 comments on commit 8a880db

Please sign in to comment.