Commit e367d4be authored by piotr.gawron's avatar piotr.gawron
Browse files

all clases compile

parent d357d2b2
......@@ -21,7 +21,6 @@ import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.structure.Compartment;
import lcsb.mapviewer.converter.model.celldesigner.structure.Element;
import lcsb.mapviewer.converter.model.celldesigner.structure.GenericProtein;
import lcsb.mapviewer.converter.model.celldesigner.structure.Species;
......@@ -116,35 +115,21 @@ public class ConsoleConverter {
Model model = new ModelFullIndexed(null);
model.setWidth(inputOptions.getModelSize());
model.setHeight(inputOptions.getModelSize());
model.addCompartment(new Compartment("default"));
Set<Element> elements = null;
Set<Alias> elements = null;
try {
elements = getNodes(nodesFilename);
} catch (IOException e) {
throw new InvalidInputDataExecption("Problem with input file: " + nodesFilename, e);
}
for (Element element : elements) {
model.addElement(element);
}
double middleX = inputOptions.getModelSize() / 2;
double middleY = inputOptions.getModelSize() / 2;
double size = model.getSpecies().size();
double size = elements.size();
double x = 0;
for (Species species : model.getSpecies()) {
SpeciesAlias alias = null;
if (species instanceof GenericProtein) {
alias = new GenericProteinAlias((GenericProtein) species);
} else {
// TODO fix after refactoring
throw new NotImplementedException("Don't know how to deal with class: " + species.getClass());
}
alias.setAliasId("al" + species.getElementId());
for (Alias alias: model.getAliases()) {
alias.setWidth(inputOptions.getAliasWidth());
alias.setHeight(inputOptions.getAliasHeight());
double angle = x / size * 2 * Math.PI;
......@@ -260,9 +245,8 @@ public class ConsoleConverter {
String productString = cols[productsColumn];
for (String string : productString.split(",")) {
if (!string.isEmpty()) {
Element element = model.getSpeciesBySpeciesId(string.trim());
SpeciesAlias alias = model.getAliasesBySpeciesId(string.trim()).get(0);
Product product = new Product(alias, element);
SpeciesAlias alias = model.getAliasByAliasId(string.trim());
Product product = new Product(alias);
products.add(product);
}
}
......@@ -274,9 +258,8 @@ public class ConsoleConverter {
String reactantString = cols[reactantsColumn];
for (String string : reactantString.split(",")) {
if (!string.isEmpty()) {
Element element = model.getSpeciesBySpeciesId(string.trim());
SpeciesAlias alias = model.getAliasesBySpeciesId(string.trim()).get(0);
Reactant product = new Reactant(alias, element);
SpeciesAlias element = model.getAliasByAliasId(string.trim());
Reactant product = new Reactant(element);
reactants.add(product);
}
}
......@@ -288,9 +271,8 @@ public class ConsoleConverter {
String modifierString = cols[modifiersColumn];
for (String string : modifierString.split(",")) {
if (!string.isEmpty()) {
Element element = model.getSpeciesBySpeciesId(string.trim());
SpeciesAlias alias = model.getAliasesBySpeciesId(string.trim()).get(0);
Modifier modifier = new Catalysis(alias, element);
SpeciesAlias element = model.getAliasByAliasId(string.trim());
Modifier modifier = new Catalysis(element);
modifiers.add(modifier);
}
}
......@@ -331,7 +313,7 @@ public class ConsoleConverter {
reaction.addModifier(modifier);
}
reaction.addMiriamData(annotations);
reaction.setElementId(id);
reaction.setIdReaction(id);
result.add(reaction);
} catch (InstantiationException e) {
throw new InvalidStateException(e);
......@@ -358,11 +340,11 @@ public class ConsoleConverter {
* @throws IOException
* thrown when there is a problem with input file
*/
private Set<Element> getNodes(String filename) throws InvalidInputDataExecption, IOException {
private Set<Alias> getNodes(String filename) throws InvalidInputDataExecption, IOException {
ElementUtils elementUtils = new ElementUtils();
Set<Element> result = new HashSet<Element>();
Set<String> ids = new HashSet<String>();
Set<Alias> result = new HashSet<>();
Set<String> ids = new HashSet<>();
Integer identifierColumn = null;
Integer typeColumn = null;
......@@ -438,14 +420,11 @@ public class ConsoleConverter {
if (!Element.class.isAssignableFrom(clazz)) {
throw new InvalidInputDataExecption("Invliad element type: " + className, filename);
}
Element element = (Element) clazz.newInstance();
Alias element = (Alias) clazz.getConstructor(String.class).newInstance(id);
element.setName(name);
element.addMiriamData(annotations);
element.setElementId(id);
result.add(element);
} catch (InstantiationException e) {
throw new InvalidStateException(e);
} catch (IllegalAccessException e) {
} catch (ReflectiveOperationException | SecurityException e) {
throw new InvalidStateException(e);
}
row++;
......
package lcsb.mapviewer.run;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.structure.Compartment;
import lcsb.mapviewer.converter.model.celldesigner.structure.GenericProtein;
import lcsb.mapviewer.converter.model.celldesigner.structure.Species;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.layout.alias.Alias;
import lcsb.mapviewer.model.map.layout.alias.GenericProteinAlias;
import lcsb.mapviewer.model.map.layout.alias.SpeciesAlias;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.type.NegativeInfluenceReaction;
import lcsb.mapviewer.model.map.reaction.type.PositiveInfluenceReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownPositiveInfluenceReaction;
import lcsb.mapviewer.model.map.reaction.type.UnknownTransitionReaction;
import lcsb.mapviewer.persist.ApplicationContextLoader;
import org.apache.log4j.Logger;
/**
* This class prepare simple model from list of reactions given in input files.
*
* @author Piotr Gawron
*
*/
public class DiabetesTest {
/**
* Identifier of the column used for types of the reaction in the input file.
*/
private static final int REACTION_TYPE_COLUMN_ID = 3;
/**
* Default width of created alias.
*/
private static final int ALIAS_WIDTH = 80;
/**
* Default height of created alias.
*/
private static final int ALIAS_HEIGHT = 20;
/**
* Size of the model (width/height).
*/
private static final int MODEL_SIZE = 8000;
/**
* What is the radius of the circle used for positioning elements.
*/
private static final double RADIUS = 3500;
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(DiabetesTest.class.getName());
/**
* Static main method used to run this stand alone code.
*
* @param args
* command line arguments
*/
public static void main(String[] args) {
ApplicationContextLoader.loadApplicationContext("consoleApplicationContext.xml");
DiabetesTest main = new DiabetesTest();
ApplicationContextLoader.injectDependencies(main);
main.run();
}
/**
* Default constructor.
*/
public DiabetesTest() {
}
/**
* Method that creates set of maps from list of reactions.
*/
private void run() {
try {
generateNetwork1("pparg_network_net");
generateNetwork2("sum_ariadne_unique");
generateNetwork2("sum_Maria_notexpanded");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
/**
* Creates model from pparg network.
*
* @param name
* name of the model
* @throws IOException
* thrown when there is a problem with input/output file.
* @throws InconsistentModelException
* thrown when there is a problem with model
*
*/
protected void generateNetwork1(String name) throws IOException, InconsistentModelException {
int speciesCounter = 0;
String filename = "data/" + name + ".txt";
File file = new File(filename);
CellDesignerXmlParser p = new CellDesignerXmlParser();
Model model = new ModelFullIndexed(null);
model.addCompartment(new Compartment("default"));
BufferedReader br = new BufferedReader(new FileReader(file));
br.readLine();
String line;
List<Pair<Pair<Species, Species>, String>> connections = new ArrayList<Pair<Pair<Species, Species>, String>>();
while ((line = br.readLine()) != null) {
String[] tmp = line.split("\t");
List<Species> list = model.getSpeciesByName(tmp[0]);
GenericProtein species1 = null;
if (list.size() == 0) {
species1 = new GenericProtein();
species1.setName(tmp[0]);
species1.setElementId("sp" + speciesCounter);
model.addElement(species1);
speciesCounter++;
} else {
species1 = (GenericProtein) list.get(0);
}
list = model.getSpeciesByName(tmp[1]);
GenericProtein species2 = null;
if (list.size() == 0) {
species2 = new GenericProtein();
species2.setName(tmp[1]);
species2.setElementId("sp" + speciesCounter);
model.addElement(species2);
speciesCounter++;
} else {
species2 = (GenericProtein) list.get(0);
}
Pair<Pair<Species, Species>, String> connection = new Pair<Pair<Species, Species>, String>(new Pair<Species, Species>(species1, species2), tmp[2]);
connections.add(connection);
}
br.close();
model.setWidth(MODEL_SIZE);
model.setHeight(MODEL_SIZE);
double middleX = MODEL_SIZE / 2;
double middleY = MODEL_SIZE / 2;
double size = model.getSpecies().size();
double x = 0;
for (Species species : model.getSpecies()) {
SpeciesAlias alias = null;
if (species instanceof GenericProtein) {
alias = new GenericProteinAlias((GenericProtein) species);
} else {
// TODO fix after refactoring
throw new NotImplementedException("Don't know how to deal with class: " + species.getClass());
}
alias.setAliasId("al" + x);
alias.setWidth(ALIAS_WIDTH);
alias.setHeight(ALIAS_HEIGHT);
double angle = x / size * 2 * Math.PI;
alias.setX(middleX + Math.sin(angle) * RADIUS);
alias.setY(middleY + Math.cos(angle) * RADIUS);
model.addAlias(alias);
x++;
}
for (Pair<Pair<Species, Species>, String> connection : connections) {
Reaction reaction = null;
if (connection.getRight().trim().equals("+")) {
reaction = new PositiveInfluenceReaction();
} else if (connection.getRight().trim().equals("-")) {
reaction = new NegativeInfluenceReaction();
} else if (connection.getRight().trim().equals("?")) {
reaction = new UnknownTransitionReaction();
} else {
if (!connection.getRight().trim().equals("0")) {
logger.warn("Unknown type: " + connection.getRight());
}
}
if (reaction == null) {
continue;
}
Species species1 = connection.getLeft().getLeft();
Alias alias1 = model.getAliasesForElement(species1).iterator().next();
Species species2 = connection.getLeft().getRight();
Alias alias2 = model.getAliasesForElement(species2).iterator().next();
Reactant reactant = new Reactant((SpeciesAlias) alias1, species1);
Point2D middle = new Point2D.Double((alias1.getCenterX() + alias2.getCenterX()) / 2, (alias1.getCenterY() + alias2.getCenterY()) / 2);
PolylineData p1 = new PolylineData(alias1.getCenter(), middle);
reactant.setLine(p1);
Product product = new Product((SpeciesAlias) alias2, species2);
PolylineData p2 = new PolylineData(middle, alias2.getCenter());
product.setLine(p2);
reaction.addReactant(reactant);
reaction.addProduct(product);
reaction.setIdReaction("re" + x++);
model.addReaction(reaction);
}
String xml = p.toXml(model);
PrintWriter writer = new PrintWriter(name + ".xml", "UTF-8");
writer.println(xml);
writer.close();
}
/**
* Creates model from network.
*
* @param name
* name of the model
* @throws IOException
* thrown when there is a problem with input/output file.
* @throws InconsistentModelException
* thrown when there is a problem with model
*
*/
protected void generateNetwork2(String name) throws IOException, InconsistentModelException {
int speciesCounter = 0;
String filename = "data/" + name + ".txt";
File file = new File(filename);
CellDesignerXmlParser p = new CellDesignerXmlParser();
Model model = new ModelFullIndexed(null);
model.addCompartment(new Compartment("default"));
BufferedReader br = new BufferedReader(new FileReader(file));
br.readLine();
String line;
List<Pair<Pair<Species, Species>, String>> connections = new ArrayList<Pair<Pair<Species, Species>, String>>();
while ((line = br.readLine()) != null) {
String[] tmp = line.split("\t");
List<Species> list = model.getSpeciesByName(tmp[0]);
GenericProtein species1 = null;
if (list.size() == 0) {
species1 = new GenericProtein();
species1.setName(tmp[0]);
species1.setElementId("sp" + speciesCounter);
model.addElement(species1);
speciesCounter++;
} else {
species1 = (GenericProtein) list.get(0);
}
list = model.getSpeciesByName(tmp[1]);
GenericProtein species2 = null;
if (list.size() == 0) {
species2 = new GenericProtein();
species2.setName(tmp[1]);
species2.setElementId("sp" + speciesCounter);
model.addElement(species2);
speciesCounter++;
} else {
species2 = (GenericProtein) list.get(0);
}
Pair<Pair<Species, Species>, String> connection = new Pair<Pair<Species, Species>, String>(new Pair<Species, Species>(species1, species2), tmp[2] + "\t"
+ tmp[REACTION_TYPE_COLUMN_ID]);
connections.add(connection);
}
br.close();
model.setWidth(MODEL_SIZE);
model.setHeight(MODEL_SIZE);
double middleX = MODEL_SIZE / 2;
double middleY = MODEL_SIZE / 2;
double size = model.getSpecies().size();
double x = 0;
for (Species species : model.getSpecies()) {
SpeciesAlias alias = null;
if (species instanceof GenericProtein) {
alias = new GenericProteinAlias((GenericProtein) species);
} else {
// TODO fix after refactoring
throw new NotImplementedException("Don't know how to deal with class: " + species.getClass());
}
alias.setAliasId("al" + x);
alias.setWidth(ALIAS_WIDTH);
alias.setHeight(ALIAS_HEIGHT);
double angle = x / size * 2 * Math.PI;
alias.setX(middleX + Math.sin(angle) * RADIUS);
alias.setY(middleY + Math.cos(angle) * RADIUS);
model.addAlias(alias);
x++;
}
for (Pair<Pair<Species, Species>, String> connection : connections) {
Reaction reaction = null;
String type = connection.getRight().split("\t")[0];
String annotation = connection.getRight().split("\t")[1];
if (type.trim().equals("--+>")) {
reaction = new PositiveInfluenceReaction();
} else if (type.trim().equals("---|")) {
reaction = new NegativeInfluenceReaction();
} else if (type.trim().equals("--->")) {
reaction = new UnknownPositiveInfluenceReaction();
} else {
logger.warn("Unknown type: " + connection.getRight());
}
if (reaction == null) {
continue;
}
Species species1 = connection.getLeft().getLeft();
Alias alias1 = model.getAliasesForElement(species1).iterator().next();
Species species2 = connection.getLeft().getRight();
Alias alias2 = model.getAliasesForElement(species2).iterator().next();
Reactant reactant = new Reactant((SpeciesAlias) alias1, species1);
Point2D middle = new Point2D.Double((alias1.getCenterX() + alias2.getCenterX()) / 2, (alias1.getCenterY() + alias2.getCenterY()) / 2);
PolylineData p1 = new PolylineData(alias1.getCenter(), middle);
reactant.setLine(p1);
Product product = new Product((SpeciesAlias) alias2, species2);
PolylineData p2 = new PolylineData(middle, alias2.getCenter());
product.setLine(p2);
reaction.addReactant(reactant);
reaction.addProduct(product);
reaction.setIdReaction("re" + x++);
annotation = annotation.replaceAll("\\\"", "");
String[] entries = annotation.split(",");
for (String string : entries) {
String miriam = string.split(":")[0];
reaction.addMiriamData(new MiriamData(MiriamType.PUBMED, miriam));
}
model.addReaction(reaction);
}
String xml = p.toXml(model);
PrintWriter writer = new PrintWriter(name + ".xml", "UTF-8");
writer.println(xml);
writer.close();
}
/**
* ???
*
* @param name
* name of the model
* @throws IOException
* thrown when there is a problem with input/output file.
* @throws InconsistentModelException
* thrown when there is a problem with model
*/
protected void generateNetwork3(String name) throws IOException, InconsistentModelException {
int speciesCounter = 0;
String filename = "data/" + name + ".txt";
File file = new File(filename);
CellDesignerXmlParser p = new CellDesignerXmlParser();
Model model = new ModelFullIndexed(null);
model.addCompartment(new Compartment("default"));
BufferedReader br = new BufferedReader(new FileReader(file));
br.readLine();
String line;
List<Pair<Pair<Species, Species>, String>> connections = new ArrayList<Pair<Pair<Species, Species>, String>>();
while ((line = br.readLine()) != null) {
String[] tmp = line.split("\t");
List<Species> list = model.getSpeciesByName(tmp[0]);
GenericProtein species1 = null;
if (list.size() == 0) {
species1 = new GenericProtein();
species1.setName(tmp[0]);
species1.setElementId("sp" + speciesCounter);
model.addElement(species1);
speciesCounter++;
} else {
species1 = (GenericProtein) list.get(0);
}
list = model.getSpeciesByName(tmp[1]);
GenericProtein species2 = null;
if (list.size() == 0) {
species2 = new GenericProtein();
species2.setName(tmp[1]);
species2.setElementId("sp" + speciesCounter);
model.addElement(species2);
speciesCounter++;
} else {
species2 = (GenericProtein) list.get(0);
}
Pair<Pair<Species, Species>, String> connection = new Pair<Pair<Species, Species>, String>(new Pair<Species, Species>(species1, species2), tmp[2] + "\t"
+ tmp[REACTION_TYPE_COLUMN_ID]);
connections.add(connection);
}
br.close();
model.setWidth(MODEL_SIZE);
model.setHeight(MODEL_SIZE);
double middleX = MODEL_SIZE / 2;
double middleY = MODEL_SIZE / 2;
double size = model.getSpecies().size();
double x = 0;
for (Species species : model.getSpecies()) {
SpeciesAlias alias = null;
if (species instanceof GenericProtein) {
alias = new GenericProteinAlias((GenericProtein) species);
} else {
// TODO fix after refactoring
throw new NotImplementedException("Don't know how to deal with class: " + species.getClass());
}
alias.setAliasId("al" + x);
alias.setWidth(ALIAS_WIDTH);
alias.setHeight(ALIAS_HEIGHT);
double angle = x / size * 2 * Math.PI;
alias.setX(middleX + Math.sin(angle) * RADIUS);
alias.setY(middleY + Math.cos(angle) * RADIUS);
model.addAlias(alias);
x++;
}
for (Pair<Pair<Species, Species>, String> connection : connections) {
Reaction reaction = null;
String type = connection.getRight().split("\t")[0];
String annotation = connection.getRight().split("\t")[1];
if (type.trim().equals("--+>")) {
reaction = new PositiveInfluenceReaction();
} else if (type.trim().equals("---|"