Commit 26e89d1e authored by cfrainay's avatar cfrainay
Browse files

Merge branch 'develop' into feature/mergedSideCompounds

parents c3850ec4 bf25b558
......@@ -19,8 +19,6 @@ test:
- mvn clean test
- cat coverage/target/site/jacoco-aggregate/index.html | grep -o '<tfoot>.*</tfoot>'
deploySnapshot:
stage: deploy
script:
......
......@@ -55,27 +55,49 @@ import fr.inrae.toulouse.metexplore.met4j_io.jsbml.attributes.Notes;
*/
public class GenericAttributes {
/** Constant <code>SBML_UNIT_DEFINITIONS="unit_definitions"</code> */
/**
* Constant <code>SBML_UNIT_DEFINITIONS="unit_definitions"</code>
*/
public static final String SBML_UNIT_DEFINITIONS = "unit_definitions";
/** Constant <code>SBML_NOTES="notes"</code> */
/**
* Constant <code>SBML_NOTES="notes"</code>
*/
public static final String SBML_NOTES = "notes";
/** Constant <code>PMIDS="pmids"</code> */
/**
* Constant <code>PMIDS="pmids"</code>
*/
public static final String PMIDS = "pmids";
/** Constant <code>COMMENT="comment"</code> */
/**
* Constant <code>COMMENT="comment"</code>
*/
public static final String COMMENT = "comment";
/** Constant <code>SBO_TERM="sbo_term"</code> */
/**
* Constant <code>SBO_TERM="sbo_term"</code>
*/
public static final String SBO_TERM = "sbo_term";
/** Constant <code>CONSTANT="constant"</code> */
/**
* Constant <code>CONSTANT="constant"</code>
*/
public static final String CONSTANT = "constant";
/** Constant <code>SBML_ANNOTATION="annotation"</code> */
/**
* Constant <code>SBML_ANNOTATION="annotation"</code>
*/
public static final String SBML_ANNOTATION = "annotation";
/** Constant <code>GENERIC="generic"</code> */
/**
* Constant <code>GENERIC="generic"</code>
*/
public static final String GENERIC = "generic";
/** Constant <code>TYPE="type"</code> */
/**
* Constant <code>TYPE="type"</code>
*/
public static final String TYPE = "type";
/** Constant <code>ANNOTATOR_COMMENTS="annotator_comments"</code> */
/**
* Constant <code>ANNOTATOR_COMMENTS="annotator_comments"</code>
*/
public static final String ANNOTATOR_COMMENTS = "annotator_comments";
/** Constant <code>AUTHORS="AUTHORS"</code> */
/**
* Constant <code>AUTHORS="AUTHORS"</code>
*/
public static final String AUTHORS = "AUTHORS";
......@@ -212,7 +234,8 @@ public class GenericAttributes {
public static void setSboTerm(BioEntity e, String sboTerm) {
if (!StringUtils.isValidSboTerm(sboTerm)) {
System.err.println("[Warning] SBO term badly formatted for " + e.getId()
+ " ("+sboTerm+", must be in the format SBO:1234567). It has not been set.");
+ " (" + sboTerm + ", must be in the format SBO:1234567). It has been set to null.");
e.getAttributes().remove(SBO_TERM);
} else {
e.setAttribute(SBO_TERM, sboTerm);
}
......
......@@ -37,10 +37,6 @@ package fr.inrae.toulouse.metexplore.met4j_io.jsbml.errors;
public class GeneSetException extends Exception {
public GeneSetException(String message) {
super(message);
}
public GeneSetException() {
super("Not possible to transform gene set since it has been added in a gene association");
}
......
......@@ -64,7 +64,7 @@ public class FluxReaction extends BioEntity {
* The actual {@link BioReaction} that is behind this
* {@link FluxReaction}
*/
private BioReaction underlyingReaction;
private final BioReaction underlyingReaction;
/**
* The object holding the Gene Association
*
......@@ -151,16 +151,6 @@ public class FluxReaction extends BioEntity {
bn.affectEnzyme(rxn, enz);
}
/**
* <p>createIdFromProteins.</p>
*
* @param proteins a {@link fr.inrae.toulouse.metexplore.met4j_core.biodata.collection.BioCollection} object.
* @return a {@link java.lang.String} object.
*/
public static String createIdFromProteins(BioCollection<BioProtein> proteins) {
return proteins.getIds().stream().sorted().collect(Collectors.joining("_AND_"));
}
/**
* Get the {@link #underlyingReaction}
*
......
......@@ -39,18 +39,15 @@ package fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.stream.XMLStreamException;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.errors.JSBMLPackageReaderException;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.SBMLDocument;
import org.sbml.jsbml.SBMLError;
import org.sbml.jsbml.SBMLError.SEVERITY;
import org.sbml.jsbml.SBMLReader;
import org.sbml.jsbml.validator.SBMLValidator;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioNetwork;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.dataTags.AdditionalDataTag;
......@@ -66,8 +63,8 @@ import fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.plugin.PackageParser;
* depending on the SBML level defined in the file
*
* @author Benjamin Merlet
* @since 3.0
* @version $Id: $Id
* @since 3.0
*/
public class JsbmlReader {
......@@ -80,7 +77,7 @@ public class JsbmlReader {
* The list of errors and/or warnings found by jsbml while parsing the SBML
* File
*/
public ArrayList<String> errorsAndWarnings = new ArrayList<String>();
public ArrayList<String> errorsAndWarnings = new ArrayList<>();
/**
* The SBML filename
*/
......@@ -89,16 +86,8 @@ public class JsbmlReader {
* The SBML Model retrieved through jsbml's
*/
private Model model;
/**
* Attribute that specifies if the input sbml is valid or not
*/
private boolean validSBML = true;
/**
* Set to true to use SBML online validator
*/
private boolean useValidator = true;
private String xml = null;
private String xmlString = null;
/**
* Constructor
......@@ -108,19 +97,6 @@ public class JsbmlReader {
*/
public JsbmlReader(String filename) throws IOException {
this.filename = filename;
this.useValidator = false;
}
/**
* Constructor
*
* @param filename the filename
* @param useValidator set the {@link #useValidator} attribute
* @throws java.io.IOException if any.
*/
public JsbmlReader(String filename, boolean useValidator) throws IOException {
this.filename = filename;
this.useValidator = useValidator;
}
/**
......@@ -130,43 +106,28 @@ public class JsbmlReader {
* @throws java.io.IOException if any.
*/
public JsbmlReader(InputStream inputStream) throws IOException {
this.xml = this.inputStreamToString(inputStream);
this.useValidator = false;
this.xmlString = this.inputStreamToString(inputStream);
}
/**
* <p>Constructor for JsbmlReader.</p>
*
* @param inputStream a {@link java.io.InputStream} object.
* @param useValidator a boolean.
* @throws java.io.IOException if any.
*/
public JsbmlReader(InputStream inputStream, boolean useValidator) throws IOException {
this.xml = this.inputStreamToString(inputStream);
this.useValidator = useValidator;
}
private String inputStreamToString(InputStream inputStream) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line + System.lineSeparator());
sb.append(line).append(System.lineSeparator());
}
return sb.toString();
}
/**
/*
* A test main method
*
* @param args the arguments
* @throws fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.Met4jSbmlReaderException if any.
* @throws java.io.IOException if any.
*/
public static void main(String[] args) throws Met4jSbmlReaderException, IOException, JSBMLPackageReaderException {
/* public static void main(String[] args) throws Met4jSbmlReaderException, IOException, JSBMLPackageReaderException {
// String
String inputFile = args[0];
......@@ -205,7 +166,7 @@ public class JsbmlReader {
System.err.println("End :" + new Date());
}
}*/
/**
* <p>read.</p>
......@@ -218,18 +179,16 @@ public class JsbmlReader {
* @throws fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.Met4jSbmlReaderException if any.
*/
public BioNetwork read(ArrayList<PackageParser> userEnabledPackages) throws Met4jSbmlReaderException {
try {
this.initiateModel();
} catch (IOException | XMLStreamException e) {
e.printStackTrace();
this.setValidSBML(false);
}
if (this.isValidSBML()) {
System.err.println("Verifying enabled Plugins...");
ArrayList<PackageParser> verifiedPkgs = this
.verifyPackages(userEnabledPackages);
ArrayList<PackageParser> verifiedPkgs = this.verifyPackages(userEnabledPackages);
JsbmlToBioNetwork converter = new JsbmlToBioNetwork(this.getModel());
......@@ -239,9 +198,13 @@ public class JsbmlReader {
converter.setPackages(verifiedPkgs);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
throw new Met4jSbmlReaderException("Problem while setting the JSBML packages");
}
return parseModel();
}
protected BioNetwork parseModel() throws Met4jSbmlReaderException {
System.err.println("Parsing model " + this.getModel().getId());
this.getConverter().parseModel();
......@@ -251,10 +214,6 @@ public class JsbmlReader {
this.errorsAndWarnings.addAll(PackageParser.errorsAndWarnings);
return this.getConverter().getNetwork();
} else {
return null;
}
}
/**
......@@ -264,9 +223,7 @@ public class JsbmlReader {
* @throws fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.Met4jSbmlReaderException if any.
*/
public BioNetwork read() throws Met4jSbmlReaderException {
ArrayList<PackageParser> pkgs = new ArrayList<PackageParser>(Arrays.asList(
new NotesParser(true), new FBCParser(), new GroupPathwayParser(), new AnnotationParser(
true)));
ArrayList<PackageParser> pkgs = new ArrayList<>(Arrays.asList(new NotesParser(true), new FBCParser(), new GroupPathwayParser(), new AnnotationParser(true)));
return this.read(pkgs);
}
......@@ -278,25 +235,22 @@ public class JsbmlReader {
* @throws fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.Met4jSbmlReaderException if any.
*/
public BioNetwork readWithoutNotes() throws Met4jSbmlReaderException {
ArrayList<PackageParser> pkgs = new ArrayList<PackageParser>(Arrays.asList( new FBCParser(), new GroupPathwayParser(), new AnnotationParser(
true)));
ArrayList<PackageParser> pkgs = new ArrayList<>(Arrays.asList(new FBCParser(), new GroupPathwayParser(), new AnnotationParser(true)));
return this.read(pkgs);
}
/**
* Verifies the Set of user defined packages and orders them
*
* @param userEnabledPackages the packages enabled by the user
* @return the ordered list of packages
*/
private ArrayList<PackageParser> verifyPackages(
ArrayList<PackageParser> userEnabledPackages) {
private ArrayList<PackageParser> verifyPackages(ArrayList<PackageParser> userEnabledPackages) {
ArrayList<PackageParser> start = new ArrayList<PackageParser>();
ArrayList<PackageParser> end = new ArrayList<PackageParser>();
ArrayList<PackageParser> start = new ArrayList<>();
ArrayList<PackageParser> end = new ArrayList<>();
if (userEnabledPackages == null) {
System.err.println("No user package defined");
......@@ -330,90 +284,22 @@ public class JsbmlReader {
*/
private void initiateModel() throws IOException, XMLStreamException {
SBMLDocument doc;
if(this.xml == null) {
File sbmlFile = new File(this.getFilename());
doc = SBMLReader.read(sbmlFile);
}
else {
doc = SBMLReader.read(xml);
}
if (this.useValidator) {
System.err.println("Validating Input SBML..");
this.setValidSBML(this.validateSBML(doc));
System.err.println("Validation of input SBML done : " + this.validSBML);
}
SBMLDocument doc = sbmlRead();
this.setModel(doc.getModel());
}
/**
* Validates the SBML document using the online validator
*
* @param doc the SBMLDocument object
* @return true if SBMLValidator returns no errors, false otherwise. This
* method returns true if the Validator only returns warnings
*/
public boolean validateSBML(SBMLDocument doc) {
// TODO test if the validator is working properly before checking
// consistency.
doc.setConsistencyChecks(
SBMLValidator.CHECK_CATEGORY.GENERAL_CONSISTENCY, true);
doc.setConsistencyChecks(
SBMLValidator.CHECK_CATEGORY.IDENTIFIER_CONSISTENCY, true);
doc.setConsistencyChecks(
SBMLValidator.CHECK_CATEGORY.UNITS_CONSISTENCY, false);
doc.setConsistencyChecks(SBMLValidator.CHECK_CATEGORY.SBO_CONSISTENCY,
false);
doc.setConsistencyChecks(
SBMLValidator.CHECK_CATEGORY.MATHML_CONSISTENCY, true);
doc.setConsistencyChecks(
SBMLValidator.CHECK_CATEGORY.OVERDETERMINED_MODEL, true);
doc.setConsistencyChecks(
SBMLValidator.CHECK_CATEGORY.MODELING_PRACTICE, false);
// Online validator
Integer code = doc.checkConsistency();
if (code > 0) {
HashMap<Integer, String> parsedErrors = new HashMap<Integer, String>();
for (SBMLError err : doc.getErrorLog().getValidationErrors()) {
StringBuilder sb = new StringBuilder();
if (parsedErrors.containsKey(err.getCode())) {
sb.append(parsedErrors.get(err.getCode())).append(", ")
.append(err.getLine()).toString();
protected SBMLDocument sbmlRead() throws XMLStreamException, IOException {
SBMLDocument doc;
if (this.xmlString == null) {
File sbmlFile = new File(this.getFilename());
doc = SBMLReader.read(sbmlFile);
} else {
sb.append("SBML ").append(err.getSeverity()).append(" #")
.append(err.getCode()).append(" on ");
sb.append(err.getCategory()).append(":");
sb.append(err.getShortMessage().getMessage()).append("\n")
.append("Line(s): ").append(err.getLine());
doc = SBMLReader.read(xmlString);
}
String newMessage = sb.toString();
parsedErrors.put(err.getCode(), newMessage);
}
errorsAndWarnings.addAll(parsedErrors.values());
if (doc.getErrorLog().getNumFailsWithSeverity(SEVERITY.ERROR) != 0) {
return false;
}
}
return true;
return doc;
}
/**
......@@ -470,24 +356,6 @@ public class JsbmlReader {
this.converter = converter;
}
/**
* <p>isValidSBML.</p>
*
* @return the validSBML
*/
public boolean isValidSBML() {
return validSBML;
}
/**
* <p>Setter for the field <code>validSBML</code>.</p>
*
* @param validSBML the validSBML to set
*/
public void setValidSBML(boolean validSBML) {
this.validSBML = validSBML;
}
/**
* <p>Getter for the field <code>errorsAndWarnings</code>.</p>
*
......@@ -505,23 +373,4 @@ public class JsbmlReader {
public void setErrorsAndWarnings(ArrayList<String> errorsAndWarnings) {
this.errorsAndWarnings = errorsAndWarnings;
}
/**
* <p>isUseValidator.</p>
*
* @return the useValidator
*/
public boolean isUseValidator() {
return useValidator;
}
/**
* <p>Setter for the field <code>useValidator</code>.</p>
*
* @param useValidator the useValidator to set
*/
public void setUseValidator(boolean useValidator) {
this.useValidator = useValidator;
}
}
......@@ -40,7 +40,6 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import fr.inrae.toulouse.metexplore.met4j_core.utils.StringUtils;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.dataTags.AdditionalDataTag;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.plugin.tags.ReaderSBML1Compatible;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.reader.plugin.tags.ReaderSBML2Compatible;
......@@ -52,11 +51,9 @@ import org.sbml.jsbml.UniqueNamedSBase;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioReaction;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.collection.BioCollection;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioCompartment;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioEntity;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioMetabolite;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioNetwork;
import fr.inrae.toulouse.metexplore.met4j_core.biodata.BioPhysicalEntity;
import static fr.inrae.toulouse.metexplore.met4j_core.utils.StringUtils.*;
......@@ -152,8 +149,6 @@ public class AnnotationParser implements PackageParser, AdditionalDataTag, Reade
this.parseSbmlAnnotations(bionetwork.getReactionsView());
this.parseSbmlAnnotations(bionetwork.getMetabolitesView());
this.parseSbmlAnnotations(bionetwork.getGenesView());
// this.parseSbmlAnnotations(bionetwork.getProteinsView());
// this.parseSbmlAnnotations(bionetwork.getEnzymesView());
this.parseSbmlAnnotations(bionetwork.getCompartmentsView());
}
......@@ -194,7 +189,7 @@ public class AnnotationParser implements PackageParser, AdditionalDataTag, Reade
Matcher m;
for (CVTerm cv : annot.getListOfCVTerms()) {
String qual = "NA";
String qual;
if(cv.isBiologicalQualifier()) {
......
......@@ -47,7 +47,6 @@ import fr.inrae.toulouse.metexplore.met4j_io.jsbml.attributes.Notes;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.dataTags.AdditionalDataTag;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.errors.GeneSetException;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.errors.MalformedGeneAssociationStringException;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.fbc.FluxReaction;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.fbc.GeneAssociation;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.fbc.GeneAssociations;
import fr.inrae.toulouse.metexplore.met4j_io.jsbml.fbc.GeneSet;
......@@ -226,11 +225,11 @@ public class NotesParser implements PackageParser, AdditionalDataTag, ReaderSBML
GeneAssociation geneAssociation = new GeneAssociation();
ArrayList<String> subAssos = new ArrayList<String>();
ArrayList<String> subAssos = new ArrayList<>();
String tmpAssos = assosString;
/**
/*
* This Allows to separate parenthesis block.
*/
while (tmpAssos.contains("(")) {
......@@ -245,7 +244,7 @@ public class NotesParser implements PackageParser, AdditionalDataTag, ReaderSBML
subAssos.add(subAsso);
tmpAssos = tmpAssos.substring(0, i) + tmpAssos.substring(end + 1, tmpAssos.length());
tmpAssos = tmpAssos.substring(0, i) + tmpAssos.substring(end + 1);
} catch (ArrayIndexOutOfBoundsException e) {
throw new MalformedGeneAssociationStringException("Malformed Gene Association");
......@@ -267,14 +266,14 @@ public class NotesParser implements PackageParser, AdditionalDataTag, ReaderSBML
StringUtils.addAllNonEmpty(subAssos, Arrays.asList(tmpAssos.split("(?i) and ")));
// foreach items in "and" block
ArrayList<GeneAssociation> geneAssociations = new ArrayList<GeneAssociation>();
ArrayList<GeneAssociation> geneAssociations = new ArrayList<>();
for (String s : subAssos) {
geneAssociations.add(computeGeneAssociation(s, network));
}
// Merge the geneAssociations
geneAssociation = GeneAssociations.merge(geneAssociations.stream().toArray(GeneAssociation[]::new));
geneAssociation = GeneAssociations.merge(geneAssociations.toArray(GeneAssociation[]::new));
} else {
tmpAssos = tmpAssos.replaceAll(" ", "");
......@@ -497,8 +496,8 @@ public class NotesParser implements PackageParser, AdditionalDataTag, ReaderSBML
String[] pmids = pmidsStr.split(this.separator);
for (int i = 0; i < pmids.length; i++) {
String pmid = pmids[i].trim();
for (String s : pmids) {
String pmid = s.trim();