Commit ca4d2258 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

species modifications changed in hierarchical structure

parent a83396a1
......@@ -17,6 +17,7 @@ import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.AbstractSiteModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
......@@ -98,31 +99,29 @@ public class CellDesignerElementCollection {
}
String modifications = "";
List<ModificationResidue> regions = new ArrayList<>();
if (modelElement instanceof AntisenseRna) {
AntisenseRna asAntisenseRna = ((AntisenseRna) modelElement);
for (ModificationResidue region : asAntisenseRna.getRegions()) {
modifications += region.getState();
}
regions.addAll(asAntisenseRna.getRegions());
} else if (modelElement instanceof Gene) {
Gene asGene = ((Gene) modelElement);
for (ModificationResidue region : asGene.getModificationResidues()) {
modifications += region.getState();
}
regions.addAll(asGene.getModificationResidues());
} else if (modelElement instanceof Protein) {
Protein asProtein = ((Protein) modelElement);
modifications = asProtein.getStructuralState();
for (ModificationResidue region : asProtein.getModificationResidues()) {
modifications += region.getState();
}
regions.addAll(asProtein.getModificationResidues());
} else if (modelElement instanceof Rna) {
Rna asRna = ((Rna) modelElement);
for (ModificationResidue region : asRna.getRegions()) {
modifications += region.getState();
}
regions.addAll(asRna.getRegions());
} else if (modelElement instanceof Complex) {
Complex asComplex = ((Complex) modelElement);
modifications = asComplex.getStructuralState();
}
for (ModificationResidue region : regions) {
if (region instanceof AbstractSiteModification) {
modifications += ((AbstractSiteModification) region).getState();
}
}
String complexId = "";
String homodimer = "";
......
......@@ -105,9 +105,9 @@ public class CellDesignerGeneRegion implements Serializable {
this.setIdModificationResidue(mr.getIdModificationResidue());
this.name = mr.getName();
this.angle = converter.getAngleForPoint(mr.getSpecies(), mr.getPosition());
this.state = mr.getState();
if (mr instanceof ModificationSite) {
this.setModificationType("MODIFICATION_SITE");
this.state = ((ModificationSite) mr).getState();
} else {
throw new InvalidArgumentException("Unknown gene modification: " + mr.getClass());
}
......@@ -342,6 +342,7 @@ public class CellDesignerGeneRegion implements Serializable {
throw new InvalidArgumentException("Unknown gene modification type");
} else if (modificationType.equals("MODIFICATION_SITE")) {
result = new ModificationSite();
((ModificationSite) result).setState(this.getState());
} else {
logger.debug(this);
throw new InvalidArgumentException("Unknown gene modification type: " + modificationType);
......@@ -354,7 +355,6 @@ public class CellDesignerGeneRegion implements Serializable {
angle = 0.0;
}
result.setPosition(converter.getResidueCoordinates(element, angle));
result.setState(this.getState());
return result;
}
......
......@@ -106,11 +106,12 @@ public class CellDesignerModificationResidue implements Serializable {
this.idModificationResidue = mr.getIdModificationResidue();
this.name = mr.getName();
this.angle = converter.getAngleForPoint(mr.getSpecies(), mr.getPosition());
this.state = mr.getState();
if (mr instanceof Residue) {
this.modificationType = "RESIDUE";
this.state = ((Residue) mr).getState();
} else if (mr instanceof ModificationSite) {
this.modificationType = "MODIFICATION_SITE";
this.state = ((ModificationSite) mr).getState();
} else if (mr instanceof CodingRegion) {
this.modificationType = "CODING_REGION";
} else if (mr instanceof ProteinBindingDomain) {
......@@ -347,6 +348,7 @@ public class CellDesignerModificationResidue implements Serializable {
throw new InvalidArgumentException("No type information for modification: " + idModificationResidue);
} else if (modificationType.equals("RESIDUE")) {
result = new Residue();
((Residue) result).setState(this.getState());
} else {
throw new InvalidArgumentException("Unknown protein modification type: " + modificationType);
}
......@@ -358,7 +360,6 @@ public class CellDesignerModificationResidue implements Serializable {
angle = 0.0;
}
result.setPosition(converter.getResidueCoordinates(element, angle));
result.setState(this.getState());
return result;
}
......
......@@ -275,6 +275,7 @@ public class CellDesignerRnaRegion implements Serializable {
throw new InvalidArgumentException("No type information for modification: " + idRnaRegion);
} else if (modificationType.equals("MODIFICATION_SITE")) {
result = new ModificationSite();
((ModificationSite) result).setState(this.state);
} else if (modificationType.equals("CODING_REGION")) {
result = new CodingRegion();
((CodingRegion) result).setWidth(element.getWidth() * size);
......@@ -288,7 +289,6 @@ public class CellDesignerRnaRegion implements Serializable {
result.setIdModificationResidue(this.idRnaRegion);
result.setPosition(new Point2D.Double(
element.getX() + element.getWidth() / 4.0 + element.getWidth() * 3.0 / 4.0 * pos, element.getY()));
result.setState(this.state);
result.setName(this.name);
return result;
}
......
......@@ -33,8 +33,10 @@ import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.AbstractSiteModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.Residue;
import lcsb.mapviewer.modelutils.map.ElementUtils;
public class ComplexParserTests extends CellDesignerTestFunctions {
......@@ -99,7 +101,7 @@ public class ComplexParserTests extends CellDesignerTestFunctions {
try {
Model model = getModelForFile("testFiles/elements_with_kinetic_data.xml");
model.setName(null);
String xml = new CellDesignerXmlParser().toXml(model);
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
Model model2 = new CellDesignerXmlParser()
......@@ -118,7 +120,7 @@ public class ComplexParserTests extends CellDesignerTestFunctions {
try {
Model model = getModelForFile("testFiles/reactions/kinetics.xml");
model.setName(null);
String xml = new CellDesignerXmlParser().toXml(model);
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
Model model2 = new CellDesignerXmlParser()
......@@ -222,12 +224,14 @@ public class ComplexParserTests extends CellDesignerTestFunctions {
try {
model = getModelForFile("testFiles/problematic/acetyled_protein.xml");
Set<ModificationState> residues = new HashSet<ModificationState>();
Set<ModificationState> residues = new HashSet<>();
for (Element element : model.getElements()) {
if (element instanceof Species) {
Protein p = (Protein) element;
for (ModificationResidue mr : p.getModificationResidues()) {
residues.add(mr.getState());
Protein protein = (Protein) element;
for (ModificationResidue mr : protein.getModificationResidues()) {
if (mr instanceof AbstractSiteModification) {
residues.add(((AbstractSiteModification) mr).getState());
}
}
}
}
......@@ -235,8 +239,9 @@ public class ComplexParserTests extends CellDesignerTestFunctions {
// of residues
assertEquals(2, residues.size());
assertEquals(ModificationState.ACETYLATED,
((Protein) model.getElementByElementId("sa2")).getModificationResidues().get(0).getState());
AbstractSiteModification modification = (AbstractSiteModification) ((Protein) model.getElementByElementId("sa2"))
.getModificationResidues().get(0);
assertEquals(ModificationState.ACETYLATED, modification.getState());
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -278,8 +283,8 @@ public class ComplexParserTests extends CellDesignerTestFunctions {
model = getModelForFile("testFiles/problematic/problematic_acetylation.xml");
Protein p1 = (Protein) model.getElementByElementId("sa73");
Protein p2 = (Protein) model.getElementByElementId("sa27");
assertEquals(ModificationState.ACETYLATED, p1.getModificationResidues().get(0).getState());
assertFalse(ModificationState.ACETYLATED.equals(p2.getModificationResidues().get(0).getState()));
assertEquals(ModificationState.ACETYLATED, ((Residue) p1.getModificationResidues().get(0)).getState());
assertFalse(ModificationState.ACETYLATED.equals(((Residue) p2.getModificationResidues().get(0)).getState()));
} catch (Exception e) {
e.printStackTrace();
......
......@@ -28,7 +28,7 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Protein;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.Residue;
......@@ -96,7 +96,7 @@ public class GeneXmlParserTest extends CellDesignerTestFunctions {
Model model = getModelForFile("testFiles/problematic/phosphorylated_gene.xml");
Gene gene = (Gene) model.getElementByElementId("sa1");
assertEquals(1, gene.getModificationResidues().size());
ModificationResidue residue = gene.getModificationResidues().get(0);
ModificationSite residue = (ModificationSite) gene.getModificationResidues().get(0);
assertEquals(ModificationState.PHOSPHORYLATED, residue.getState());
assertEquals("some name", residue.getName());
......
......@@ -69,6 +69,7 @@ import lcsb.mapviewer.model.map.species.SimpleMolecule;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.TruncatedProtein;
import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.model.map.species.field.AbstractSiteModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.modelutils.map.ElementUtils;
......@@ -430,11 +431,14 @@ public class SbgnmlXmlExporter {
glyph.setId(mr.getIdModificationResidue());
glyph.setClazz(GlyphClazz.STATE_VARIABLE.getClazz());
if (mr.getState() != null) {
Glyph.State state = new Glyph.State();
state.setValue(mr.getState().getAbbreviation());
state.setVariable(mr.getName());
glyph.setState(state);
if (mr instanceof AbstractSiteModification) {
AbstractSiteModification modification = (AbstractSiteModification) mr;
if (modification.getState() != null) {
Glyph.State state = new Glyph.State();
state.setValue(modification.getState().getAbbreviation());
state.setVariable(mr.getName());
glyph.setState(state);
}
}
Bbox bbox = new Bbox();
......
......@@ -800,7 +800,7 @@ public class SbgnmlXmlParser {
throw new Exception("Only macromolecule elements can have state variables.");
}
Protein protein = (Protein) newSpecies;
ModificationResidue mr = new Residue();
Residue mr = new Residue();
mr.setSpecies(protein);
mr.setIdModificationResidue(unitOfInformationGlyph.getId());
......
......@@ -19,6 +19,7 @@ import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.species.Gene;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ModificationState;
/**
......@@ -72,7 +73,7 @@ public class GeneConverter extends SpeciesConverter<Gene> {
*
* @param gene
* object that is 'parent' of the residue
* @param mr
* @param mr2
* modification to be drawn
* @param graphics
* - where the modification should be drawn
......@@ -84,39 +85,42 @@ public class GeneConverter extends SpeciesConverter<Gene> {
*/
private void drawModification(final Gene gene, final ModificationResidue mr, final Graphics2D graphics,
final boolean drawEmptyModification, final boolean drawDescription) {
if ((!drawEmptyModification) && (mr.getState() == null)) {
return;
}
double diameter = DEFAULT_MODIFICATION_DIAMETER;
double y = gene.getY();
Point2D p = mr.getPosition();
p.setLocation(p.getX(), p.getY() - DEFAULT_MODIFICATION_DIAMETER);
Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
graphics.drawLine((int) p.getX(), (int) (p.getY() + diameter / 2), (int) p.getX(), (int) y);
String text = mr.getName();
if (!text.equals("") && drawDescription) {
double textWidth = graphics.getFontMetrics().stringWidth(text);
Point2D p2 = new Point2D.Double(p.getX() - textWidth / 2, p.getY() - DEFAULT_SPECIES_MODIFIER_FONT_SIZE);
graphics.drawString(text, (int) p2.getX(), (int) p2.getY());
}
ModificationState state = mr.getState();
if (state != null) {
String str = state.getAbbreviation();
Font tmpFont = graphics.getFont();
graphics.setFont(getStructuralFont());
double textX = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2;
double textY = p.getY() + graphics.getFontMetrics().getAscent() / 2;
graphics.drawString(str, (int) textX, (int) textY);
graphics.setFont(tmpFont);
if (mr instanceof ModificationSite) {
ModificationSite modificationSite = (ModificationSite) mr;
if (!drawEmptyModification && modificationSite.getState() == null) {
return;
}
double diameter = DEFAULT_MODIFICATION_DIAMETER;
double y = gene.getY();
Point2D p = modificationSite.getPosition();
p.setLocation(p.getX(), p.getY() - DEFAULT_MODIFICATION_DIAMETER);
Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
graphics.drawLine((int) p.getX(), (int) (p.getY() + diameter / 2), (int) p.getX(), (int) y);
String text = modificationSite.getName();
if (!text.equals("") && drawDescription) {
double textWidth = graphics.getFontMetrics().stringWidth(text);
Point2D p2 = new Point2D.Double(p.getX() - textWidth / 2, p.getY() - DEFAULT_SPECIES_MODIFIER_FONT_SIZE);
graphics.drawString(text, (int) p2.getX(), (int) p2.getY());
}
ModificationState state = modificationSite.getState();
if (state != null) {
String str = state.getAbbreviation();
Font tmpFont = graphics.getFont();
graphics.setFont(getStructuralFont());
double textX = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2;
double textY = p.getY() + graphics.getFontMetrics().getAscent() / 2;
graphics.drawString(str, (int) textX, (int) textY);
graphics.setFont(tmpFont);
}
}
}
......
......@@ -29,7 +29,9 @@ import lcsb.mapviewer.model.map.species.ReceptorProtein;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.TruncatedProtein;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.Residue;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
......@@ -303,29 +305,31 @@ public class ProteinConverter extends SpeciesConverter<Protein> {
*/
private void drawModification(final Protein protein, final ModificationResidue mr, final Graphics2D graphics,
final boolean drawEmptyModification) {
if ((!drawEmptyModification) && (mr.getState() == null)) {
return;
}
double diameter = DEFAULT_MODIFICATION_DIAMETER;
Point2D p = mr.getPosition();
Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
ModificationState state = mr.getState();
if (state != null) {
String str = state.getAbbreviation();
Font tmpFont = graphics.getFont();
graphics.setFont(getStructuralFont());
double x = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2;
double y = p.getY() + graphics.getFontMetrics().getAscent() / 2;
graphics.drawString(str, (int) x, (int) y);
graphics.setFont(tmpFont);
if (mr instanceof Residue) {
Residue residue = (Residue) mr;
if (!drawEmptyModification && residue.getState() == null) {
return;
}
double diameter = DEFAULT_MODIFICATION_DIAMETER;
Point2D p = residue.getPosition();
Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
ModificationState state = residue.getState();
if (state != null) {
String str = state.getAbbreviation();
Font tmpFont = graphics.getFont();
graphics.setFont(getStructuralFont());
double x = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2;
double y = p.getY() + graphics.getFontMetrics().getAscent() / 2;
graphics.drawString(str, (int) x, (int) y);
graphics.setFont(tmpFont);
}
}
}
/**
......
......@@ -26,6 +26,7 @@ import lcsb.mapviewer.model.map.layout.ColorSchema;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.ModificationSite;
import lcsb.mapviewer.model.map.species.field.ModificationState;
/**
......@@ -113,42 +114,44 @@ public class RnaConverter extends SpeciesConverter<Rna> {
* flag that indicates if we should draw description of the
* modification
*/
private void drawModification(final Rna rna, final ModificationResidue region, final Graphics2D graphics,
private void drawModification(final Rna rna, final ModificationResidue mr, final Graphics2D graphics,
final boolean drawEmptyModification, final boolean drawDescription) {
if ((!drawEmptyModification) && (region.getState() == null)) {
return;
if (mr instanceof ModificationSite) {
ModificationSite modificationSite = (ModificationSite) mr;
if (!drawEmptyModification && modificationSite.getState() == null) {
return;
}
double diameter = DEFAULT_MODIFICATION_DIAMETER;
double y = rna.getY();
Point2D p = new Point2D.Double(modificationSite.getPosition().getX(), modificationSite.getPosition().getY() - diameter);
Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
graphics.drawLine((int) p.getX(), (int) (p.getY() + diameter / 2), (int) p.getX(), (int) y);
String text = modificationSite.getName();
if (!text.equals("") && drawDescription) {
double textWidth = graphics.getFontMetrics().stringWidth(text);
Point2D p2 = new Point2D.Double(p.getX() - textWidth / 2, p.getY() - DEFAULT_SPECIES_MODIFIER_FONT_SIZE);
graphics.drawString(text, (int) p2.getX(), (int) p2.getY());
}
ModificationState state = modificationSite.getState();
if (state != null) {
String str = state.getAbbreviation();
Font tmpFont = graphics.getFont();
graphics.setFont(getStructuralFont());
double textX = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2;
double textY = p.getY() + graphics.getFontMetrics().getAscent() / 2;
graphics.drawString(str, (int) textX, (int) textY);
graphics.setFont(tmpFont);
}
}
double diameter = DEFAULT_MODIFICATION_DIAMETER;
double y = rna.getY();
Point2D p = new Point2D.Double(region.getPosition().getX(), region.getPosition().getY() - diameter);
Ellipse2D ellipse = new Ellipse2D.Double(p.getX() - diameter / 2, p.getY() - diameter / 2, diameter, diameter);
Color c = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fill(ellipse);
graphics.setColor(c);
graphics.draw(ellipse);
graphics.drawLine((int) p.getX(), (int) (p.getY() + diameter / 2), (int) p.getX(), (int) y);
String text = region.getName();
if (!text.equals("") && drawDescription) {
double textWidth = graphics.getFontMetrics().stringWidth(text);
Point2D p2 = new Point2D.Double(p.getX() - textWidth / 2, p.getY() - DEFAULT_SPECIES_MODIFIER_FONT_SIZE);
graphics.drawString(text, (int) p2.getX(), (int) p2.getY());
}
ModificationState state = region.getState();
if (state != null) {
String str = state.getAbbreviation();
Font tmpFont = graphics.getFont();
graphics.setFont(getStructuralFont());
double textX = p.getX() - graphics.getFontMetrics().stringWidth(str) / 2;
double textY = p.getY() + graphics.getFontMetrics().getAscent() / 2;
graphics.drawString(str, (int) textX, (int) textY);
graphics.setFont(tmpFont);
}
}
}
package lcsb.mapviewer.model.map.species.field;
import java.text.DecimalFormat;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
@Entity
@DiscriminatorValue("ABSTRACT_REGION_MODIFICATION")
public abstract class AbstractRegionModification extends ModificationResidue {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default size of the object (in graphical representation).
*/
private static final double DEFAULT_SIZE = 10;
/**
* Width of the region in the graphic representation.
*/
@Column(name = "width")
private double width = DEFAULT_SIZE;
public AbstractRegionModification() {
super();
}
public AbstractRegionModification(AbstractRegionModification mr) {
super(mr);
this.width = mr.getWidth();
}
@Override
public String toString() {