Skip to content

Commit

Permalink
Maven CheckStyle plugin has been added to force the code to be clean, c…
Browse files Browse the repository at this point in the history
…loses #27
  • Loading branch information
imedina committed Sep 21, 2015
1 parent 02309f7 commit b6f3dfd
Show file tree
Hide file tree
Showing 19 changed files with 473 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public static void main(String[] args) {
}

String parsedCommand = cliOptionsParser.getCommand();
if(parsedCommand == null || parsedCommand.isEmpty()) {
if(cliOptionsParser.getGeneralOptions().help) {
if (parsedCommand == null || parsedCommand.isEmpty()) {
if (cliOptionsParser.getGeneralOptions().help) {
cliOptionsParser.printUsage();
System.exit(0);
} else {
if(cliOptionsParser.getGeneralOptions().version) {
if (cliOptionsParser.getGeneralOptions().version) {
System.out.println("Version " + VERSION);
System.exit(0);
} else {
Expand All @@ -36,7 +36,7 @@ public static void main(String[] args) {
}
} else {
CommandExecutor commandExecutor = null;
if(cliOptionsParser.isHelp()) {
if (cliOptionsParser.isHelp()) {
cliOptionsParser.printUsage();
System.exit(0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,23 @@ enum NetworkQueryParams implements QueryParam {
private Type type;
private String description;

@Override public String key() {return key;}
@Override public String description() {return description;}
@Override public Type type() {return type;}
@Override public String key() {
return key;
}

@Override public String description() {
return description;
}

@Override public Type type() {
return type;
}
}


void insert(Network network, QueryOptions queryOptions) throws NetworkDBException;

void addXrefs(String nodeID, List<Xref> xref_list) throws NetworkDBException;
void addXrefs(String nodeID, List<Xref> xrefList) throws NetworkDBException;

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opencb.bionetdb.core.io;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.biopax.paxtools.io.BioPAXIOHandler;
import org.biopax.paxtools.io.SimpleIOHandler;
import org.biopax.paxtools.model.BioPAXElement;
Expand Down Expand Up @@ -103,6 +102,8 @@ public Network parse(Path path) throws IOException {
case "TemplateReactionRegulation":
network.setInteraction(createRegulation(bioPAXElement));
break;
default:
break;
}

}
Expand Down Expand Up @@ -302,9 +303,8 @@ private org.opencb.bionetdb.core.models.Complex createComplex(BioPAXElement bioP
}

private void setPhysicalEntityCommonProperties(PhysicalEntity physicalEntityBP,
org.opencb.bionetdb.core.models.PhysicalEntity physicalEntity) {
org.opencb.bionetdb.core.models.PhysicalEntity physicalEntity) {
// = SPECIFIC PROPERTIES =

// id
physicalEntity.setId(physicalEntityBP.getRDFId().split("#")[1]);

Expand All @@ -321,7 +321,6 @@ private void setPhysicalEntityCommonProperties(PhysicalEntity physicalEntityBP,
physicalEntity.setXref(xref);
}


// cellularLocation
CellularLocation cellularLocation = new CellularLocation();
CellularLocationVocabulary cellularLocationVocabulary = physicalEntityBP.getCellularLocation();
Expand Down Expand Up @@ -472,7 +471,7 @@ private org.opencb.bionetdb.core.models.Reaction createReaction(BioPAXElement bi
// TemplateReaction properties

// Reactants
if(templateReactBP.getTemplate() != null){
if (templateReactBP.getTemplate() != null) {
reaction.getReactants().add(templateReactBP.getTemplate().getRDFId().split("#")[1]);
}

Expand Down Expand Up @@ -502,6 +501,8 @@ private org.opencb.bionetdb.core.models.Reaction createReaction(BioPAXElement bi
case "TransportWithBiochemicalReaction":
reaction.setReactionType(Reaction.ReactionType.TRANSPORT);
break;
default:
break;
}

// Common Interaction properties
Expand Down Expand Up @@ -536,6 +537,8 @@ private org.opencb.bionetdb.core.models.Reaction createReaction(BioPAXElement bi
reaction.setReactants(rightItems);
reaction.setProducts(leftItems);
break;
default:
break;
}
} else {
reaction.setReactants(leftItems);
Expand Down Expand Up @@ -583,6 +586,8 @@ private org.opencb.bionetdb.core.models.Reaction createReaction(BioPAXElement bi
// Common Interaction properties
setInteractionCommonProperties(molecularInteractionBP, reaction);
break;
default:
break;
}
return reaction;
}
Expand Down Expand Up @@ -650,7 +655,7 @@ private org.opencb.bionetdb.core.models.Regulation createRegulation(BioPAXElemen
}

private void setInteractionCommonProperties(Interaction interactionBP,
org.opencb.bionetdb.core.models.Interaction interaction) {
org.opencb.bionetdb.core.models.Interaction interaction) {
// = SPECIFIC PROPERTIES =

// id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public ExpressionParser(Path metadata) throws IOException {
timeSeries = new HashMap<>();
}
timeSeries.put(fields[1], metadata.getParent().toString() + "/" + fields[2]);
if (!myFiles.containsKey(fields[0]))
if (!myFiles.containsKey(fields[0])) {
myFiles.put(fields[0], timeSeries);
}
}
}

Expand Down Expand Up @@ -81,21 +82,21 @@ public List<Expression> parse(String tissue, String time) throws IOException {
}

// It we have the geneID at least and some expression, pvalues, odds or upregulations...
if (colId != -1 && (colExpr != -1 ||colOdds != -1 ||colPval != -1 ||colUpreg != -1)) {
if (colId != -1 && (colExpr != -1 || colOdds != -1 || colPval != -1 || colUpreg != -1)) {
while ((currentLine = br.readLine()) != null) {
String[] line_spl = currentLine.split("\t", -1);
Expression myExpr = new Expression(line_spl[colId]);
String[] lineSpl = currentLine.split("\t", -1);
Expression myExpr = new Expression(lineSpl[colId]);
if (colExpr != -1) {
myExpr.setExpression(Double.parseDouble(line_spl[colExpr]));
myExpr.setExpression(Double.parseDouble(lineSpl[colExpr]));
}
if (colOdds != -1) {
myExpr.setOdds(Double.parseDouble(line_spl[colOdds]));
myExpr.setOdds(Double.parseDouble(lineSpl[colOdds]));
}
if (colPval != -1) {
myExpr.setPvalue(Double.parseDouble(line_spl[colPval]));
myExpr.setPvalue(Double.parseDouble(lineSpl[colPval]));
}
if (colUpreg != -1) {
myExpr.setUpregulated(Integer.parseInt(line_spl[colUpreg]));
myExpr.setUpregulated(Integer.parseInt(lineSpl[colUpreg]));
}
myExpressionList.add(myExpr);
}
Expand All @@ -107,9 +108,10 @@ public List<Expression> parse(String tissue, String time) throws IOException {

@Override
public String toString() {
return "ExpressionParser{" +
"myFiles=" + myFiles +
'}';
final StringBuilder sb = new StringBuilder("ExpressionParser{");
sb.append("myFiles=").append(myFiles);
sb.append('}');
return sb.toString();
}

public Map<String, Map<String, String>> getMyFiles() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.opencb.bionetdb.core.io;

import org.neo4j.cypher.internal.compiler.v2_0.ast.In;
import org.opencb.bionetdb.core.models.*;
import psidev.psi.mi.tab.PsimiTabReader;
import psidev.psi.mi.tab.model.*;

import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -12,16 +13,21 @@
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;

import psidev.psi.mi.tab.PsimiTabReader;
import psidev.psi.mi.tab.model.*;

/**
* Created by dapregi on 8/09/15.
*/
public class PsiMiTabParser {

private static final String INTACT_FEAT = "intact.";

private static final Pattern REACTION_PATTERN =
Pattern.compile("(?m)^(?=.*reaction|.*cleavage|lipid addition"
+ "|.*elongation|phosphopantetheinylation)((?!transglutamination reaction).)*$");

private static final Pattern ASSEMBLY_PATTERN =
Pattern.compile("(.*association|direct interaction|"
+ "transglutamination reaction|disulfide bond|covalent binding)");

public PsiMiTabParser() {
init();
}
Expand Down Expand Up @@ -145,6 +151,8 @@ private PhysicalEntity createPhysicalEntity(Interactor interactor) {
case "undefined":
physicalEntity = createUndefinedEntity(interactor);
break;
default:
break;

}
return physicalEntity;
Expand Down Expand Up @@ -186,6 +194,8 @@ private Rna createRna(Interactor interactor) {
case "long non-coding ribonucleic acid":
rna.setRnaType(Rna.RnaType.LNCRNA);
break;
default:
break;
}

// Common properties
Expand Down Expand Up @@ -310,7 +320,7 @@ private void setPhysicalEntityCommonProperties(Interactor interactor, PhysicalEn
// TODO

// comments
List <String> comments = new ArrayList<>();
List<String> comments = new ArrayList<>();
for (Annotation annotation : interactor.getAnnotations()) {
String comment = annotation.getText();
if (comment != null && (comment.equals("mint") || comment.equals("homomint") || comment.equals("domino"))) {
Expand All @@ -333,10 +343,10 @@ private Interaction createInteraction(BinaryInteraction binaryInteraction) {
interactionType = crossReference.getText();
}

if (Pattern.matches("(?m)^(?=.*reaction|.*cleavage|lipid addition|.*elongation|phosphopantetheinylation)((?!transglutamination reaction).)*$", interactionType)) {
if (REACTION_PATTERN.matcher(interactionType).matches()) {
// http://stackoverflow.com/questions/406230/regular-expression-to-match-line-that-doesnt-contain-a-word
interaction = createReaction(binaryInteraction);
} else if (Pattern.matches("(.*association|direct interaction|transglutamination reaction|disulfide bond|covalent binding)", interactionType)) {
} else if (ASSEMBLY_PATTERN.matcher(interactionType).matches()) {
interaction = createAssembly(binaryInteraction);
} else if (Pattern.matches("colocalization", interactionType)) {
interaction = createColocalization(binaryInteraction);
Expand All @@ -354,8 +364,8 @@ private Reaction createReaction(BinaryInteraction binaryInteraction) {
setInteractionCommonProperties(binaryInteraction, reaction);

// Stoichiometry
if (!binaryInteraction.getInteractorA().getStoichiometry().isEmpty() &&
!binaryInteraction.getInteractorB().getStoichiometry().isEmpty()) {
if (!binaryInteraction.getInteractorA().getStoichiometry().isEmpty()
&& !binaryInteraction.getInteractorB().getStoichiometry().isEmpty()) {
Map stoichiometryA = new HashMap<String, Object>();
stoichiometryA.put("component", binaryInteraction.getInteractorA().getIdentifiers().get(0).getIdentifier());
stoichiometryA.put("coefficient", binaryInteraction.getInteractorA().getStoichiometry());
Expand All @@ -377,8 +387,8 @@ private Reaction createAssembly(BinaryInteraction binaryInteraction) {
setInteractionCommonProperties(binaryInteraction, assembly);

// Stoichiometry
if (!binaryInteraction.getInteractorA().getStoichiometry().isEmpty() &&
!binaryInteraction.getInteractorB().getStoichiometry().isEmpty()) {
if (!binaryInteraction.getInteractorA().getStoichiometry().isEmpty()
&& !binaryInteraction.getInteractorB().getStoichiometry().isEmpty()) {
Map stoichiometryA = new HashMap<String, Object>();
stoichiometryA.put("component", binaryInteraction.getInteractorA().getIdentifiers().get(0).getIdentifier());
stoichiometryA.put("coefficient", binaryInteraction.getInteractorA().getStoichiometry());
Expand Down Expand Up @@ -451,7 +461,7 @@ private void setInteractionCommonProperties(BinaryInteraction binaryInteraction,
}

// comments
List <String> comments = new ArrayList<>();
List<String> comments = new ArrayList<>();
List<Annotation> annotations = binaryInteraction.getAnnotations();
for (Annotation annotation : annotations) {
String comment = annotation.getText();
Expand All @@ -463,7 +473,7 @@ private void setInteractionCommonProperties(BinaryInteraction binaryInteraction,
interaction.getAttributes().put(INTACT_FEAT + "comment", comments);
}

private void setparticipantOfInteraction (Network network) {
private void setparticipantOfInteraction(Network network) {
for (Interaction interaction : network.getInteractions()) {
for (String peId : interaction.getParticipants()) {
network.getPhysicalEntity(peId).getParticipantOfInteraction().add(interaction.getId());
Expand Down
Loading

0 comments on commit b6f3dfd

Please sign in to comment.