Commit 29a98a2a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

rna region uses width instead of CellDesigner relative size

parent 1b12ded6
......@@ -376,11 +376,6 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
Point2D pointOnBorder = lineTransformation.getIntersectionWithPathIterator(line,
path.getPathIterator(new AffineTransform()));
logger.debug(pointOnBorder);
logger.debug(element.getX());
logger.debug(element.getY());
logger.debug(element.getWidth());
logger.debug(element.getHeight());
if (Math.abs(pointOnBorder.getX() - element.getX() - element.getWidth()) < Configuration.EPSILON && //
pointOnBorder.getY() - element.getY() - element.getHeight() / 2 < Configuration.EPSILON) {
......
......@@ -290,7 +290,7 @@ public class CellDesignerRnaRegion implements Serializable {
public RnaRegion createRnaRegionAlias(Rna element) {
RnaRegion result = new RnaRegion();
result.setIdRnaRegion(this.idRnaRegion);
result.setSize(this.size);
result.setWidth(this.size * element.getWidth());
result.setPosition(new Point2D.Double(
element.getX() + element.getWidth() / 4.0 + element.getWidth() * 3.0 / 4.0 * pos, element.getY()));
result.setType(this.getType());
......
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.species.Complex;
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.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* Structure for storing the state of the Species in CellDesigner format.
*
* @author Piotr Gawron
*
*/
public class SpeciesState {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(SpeciesState.class.getName());
/**
* How many dimers are in the species.
*/
private int homodimer = 1;
/**
* String state description.
*/
private String structuralState = null;
/**
* List of species modification.
*/
private List<CellDesignerModificationResidue> modifications = new ArrayList<CellDesignerModificationResidue>();
/**
* Adds modification to the state.
*
* @param modificationResidue
* modification to add
*/
public void addModificationResidue(CellDesignerModificationResidue modificationResidue) {
for (CellDesignerModificationResidue modification : modifications) {
if (modification.getIdModificationResidue().equals(modificationResidue.getIdModificationResidue())) {
modification.update(modificationResidue);
return;
}
}
modifications.add(modificationResidue);
}
/**
* Default constructor.
*/
public SpeciesState() {
}
/**
* Creates species state description from species element.
*
* @param species
* object for which description is created
*/
public SpeciesState(Species species) {
if (species instanceof Protein) {
Protein protein = (Protein) species;
setStructuralState(protein.getStructuralState());
for (ModificationResidue mr : protein.getModificationResidues()) {
addModificationResidue(new CellDesignerModificationResidue(mr));
}
} else if (species instanceof Complex) {
Complex complex = (Complex) species;
setStructuralState(complex.getStructuralState());
} else if (species instanceof Rna) {
Rna rna = (Rna) species;
for (RnaRegion region : rna.getRegions()) {
CellDesignerModificationResidue mr = new CellDesignerModificationResidue();
mr.setIdModificationResidue(region.getIdRnaRegion());
mr.setSize(region.getSize());
mr.setState(region.getState());
addModificationResidue(mr);
}
} else if (species instanceof Gene) {
Gene gene = (Gene) species;
for (ModificationResidue mr : gene.getModificationResidues()) {
addModificationResidue(new CellDesignerModificationResidue(mr));
}
}
setHomodimer(species.getHomodimer());
}
/**
*
* @param homodimer
* new {@link #homodimer} value to set (in string format)
*/
public void setHomodimer(String homodimer) {
try {
this.homodimer = Integer.parseInt(homodimer);
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid homodir value: " + homodimer);
}
}
/**
* @return the homodimer
* @see #homodimer
*/
public int getHomodimer() {
return homodimer;
}
/**
* @param homodimer
* the homodimer to set
* @see #homodimer
*/
public void setHomodimer(int homodimer) {
this.homodimer = homodimer;
}
/**
* @return the structuralState
* @see #structuralState
*/
public String getStructuralState() {
return structuralState;
}
/**
* @param structuralState
* the structuralState to set
* @see #structuralState
*/
public void setStructuralState(String structuralState) {
this.structuralState = structuralState;
}
/**
* @return the modifications
* @see #modifications
*/
public List<CellDesignerModificationResidue> getModifications() {
return modifications;
}
/**
* @param modifications
* the modifications to set
* @see #modifications
*/
public void setModifications(List<CellDesignerModificationResidue> modifications) {
this.modifications = modifications;
}
}
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.model.map.species.Complex;
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.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* Structure for storing the state of the Species in CellDesigner format.
*
* @author Piotr Gawron
*
*/
public class SpeciesState {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(SpeciesState.class.getName());
/**
* How many dimers are in the species.
*/
private int homodimer = 1;
/**
* String state description.
*/
private String structuralState = null;
/**
* List of species modification.
*/
private List<CellDesignerModificationResidue> modifications = new ArrayList<CellDesignerModificationResidue>();
/**
* Adds modification to the state.
*
* @param modificationResidue
* modification to add
*/
public void addModificationResidue(CellDesignerModificationResidue modificationResidue) {
for (CellDesignerModificationResidue modification : modifications) {
if (modification.getIdModificationResidue().equals(modificationResidue.getIdModificationResidue())) {
modification.update(modificationResidue);
return;
}
}
modifications.add(modificationResidue);
}
/**
* Default constructor.
*/
public SpeciesState() {
}
/**
* Creates species state description from species element.
*
* @param species
* object for which description is created
*/
public SpeciesState(Species species) {
if (species instanceof Protein) {
Protein protein = (Protein) species;
setStructuralState(protein.getStructuralState());
for (ModificationResidue mr : protein.getModificationResidues()) {
addModificationResidue(new CellDesignerModificationResidue(mr));
}
} else if (species instanceof Complex) {
Complex complex = (Complex) species;
setStructuralState(complex.getStructuralState());
} else if (species instanceof Rna) {
Rna rna = (Rna) species;
for (RnaRegion region : rna.getRegions()) {
CellDesignerModificationResidue mr = new CellDesignerModificationResidue();
mr.setIdModificationResidue(region.getIdRnaRegion());
mr.setSize(region.getWidth() / (rna.getWidth() * 3.0 / 4.0));
mr.setState(region.getState());
addModificationResidue(mr);
}
} else if (species instanceof Gene) {
Gene gene = (Gene) species;
for (ModificationResidue mr : gene.getModificationResidues()) {
addModificationResidue(new CellDesignerModificationResidue(mr));
}
}
setHomodimer(species.getHomodimer());
}
/**
*
* @param homodimer
* new {@link #homodimer} value to set (in string format)
*/
public void setHomodimer(String homodimer) {
try {
this.homodimer = Integer.parseInt(homodimer);
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid homodir value: " + homodimer);
}
}
/**
* @return the homodimer
* @see #homodimer
*/
public int getHomodimer() {
return homodimer;
}
/**
* @param homodimer
* the homodimer to set
* @see #homodimer
*/
public void setHomodimer(int homodimer) {
this.homodimer = homodimer;
}
/**
* @return the structuralState
* @see #structuralState
*/
public String getStructuralState() {
return structuralState;
}
/**
* @param structuralState
* the structuralState to set
* @see #structuralState
*/
public void setStructuralState(String structuralState) {
this.structuralState = structuralState;
}
/**
* @return the modifications
* @see #modifications
*/
public List<CellDesignerModificationResidue> getModifications() {
return modifications;
}
/**
* @param modifications
* the modifications to set
* @see #modifications
*/
public void setModifications(List<CellDesignerModificationResidue> modifications) {
this.modifications = modifications;
}
}
......@@ -37,9 +37,9 @@ public class RnaRegion implements Serializable, ElementModification {
private static final long serialVersionUID = 1L;
/**
* Default {@link #size} of the region.
* Default {@link #width} of the region.
*/
private static final double DEFAULT_SIZE = 0.1;
private static final double DEFAULT_WIDTH = 10;
/**
* Default class logger.
......@@ -90,8 +90,8 @@ public class RnaRegion implements Serializable, ElementModification {
/**
* Size of the region in the graphic representation.
*/
@Column(name = "size")
private double size = DEFAULT_SIZE;
@Column(name = "width")
private double width = DEFAULT_WIDTH;
/**
* Position on the species in graphic representation.
......@@ -115,7 +115,7 @@ public class RnaRegion implements Serializable, ElementModification {
}
/**
* Creates object with the data taken from paramter region.
* Creates object with the data taken from parameter region.
*
* @param mr
* original {@link RnaRegion}
......@@ -123,28 +123,13 @@ public class RnaRegion implements Serializable, ElementModification {
public RnaRegion(RnaRegion mr) {
this.id = mr.id;
this.idRnaRegion = mr.idRnaRegion;
this.size = mr.size;
this.width = mr.width;
setPosition(mr.getPosition());
this.type = mr.type;
this.state = mr.state;
this.name = mr.name;
}
/**
* Sets {@link #size}.
*
* @param text
* new size value in string format
*/
public void setSize(String text) {
try {
size = Double.parseDouble(text);
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid angle: " + text, e);
}
}
/**
* Updates fields in the object with the data given in the parameter rna region.
*
......@@ -155,7 +140,7 @@ public class RnaRegion implements Serializable, ElementModification {
if (this.idRnaRegion != null && !this.idRnaRegion.equals("") && !this.idRnaRegion.equals(mr.getIdRnaRegion())) {
throw new InvalidArgumentException("Cannot update from mr with different id");
}
this.size = mr.getSize();
this.width = mr.getWidth();
if (mr.getState() != null) {
this.state = mr.getState();
}
......@@ -170,7 +155,7 @@ public class RnaRegion implements Serializable, ElementModification {
@Override
public String toString() {
String result = "" + getIdRnaRegion() + "," + getType() + "," + getPosition() + "," + getSize() + "," + getState() + ",";
String result = "" + getIdRnaRegion() + "," + getType() + "," + getPosition() + "," + getWidth() + "," + getState() + ",";
return result;
}
......@@ -260,23 +245,6 @@ public class RnaRegion implements Serializable, ElementModification {
this.name = name;
}
/**
* @return the size
* @see #size
*/
public double getSize() {
return size;
}
/**
* @param size
* the size to set
* @see #size
*/
public void setSize(double size) {
this.size = size;
}
/**
* @return the species
* @see #species
......@@ -302,4 +270,12 @@ public class RnaRegion implements Serializable, ElementModification {
this.position = position;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
}
......@@ -86,7 +86,7 @@ public class RnaComparatorTest {
region1.setIdRnaRegion("a");
region1.setState(ModificationState.DONT_CARE);
region1.setPosition(new Point2D.Double(0, 10));
region1.setSize("2");
region1.setWidth(2.0);
region1.setType("type");
return result;
}
......
......@@ -47,23 +47,6 @@ public class RnaRegionTest {
}
}
@Test
public void testSetSize() {
try {
RnaRegion region = new RnaRegion();
try {
region.setSize("as");
fail("Exception expected");
} catch (InvalidArgumentException e) {
}
region.setSize("0.0");
assertEquals(0.0, region.getSize(), Configuration.EPSILON);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testUpdate() {
try {
......@@ -105,11 +88,11 @@ public class RnaRegionTest {
double size = 2.5;
int id = 58;
Rna species = new Rna("id");
region.setSize(size);
region.setWidth(size);
region.setSpecies(species);
region.setId(id);
assertEquals(id, region.getId());
assertEquals(size, region.getSize(), Configuration.EPSILON);
assertEquals(size, region.getWidth(), Configuration.EPSILON);
assertEquals(species, region.getSpecies());
} catch (Exception e) {
e.printStackTrace();
......
--size is changed to width for rna region
alter table rna_region_table add column width numeric(6,2);
update rna_region_table set width=element_table.width*rna_region_table.size from element_table where element_table.iddb = rna_region_table.idspeciesdb and not size is null;
alter table rna_region_table drop column size;
......@@ -143,7 +143,7 @@ public class AliasDaoTest2 extends PersistTestFunctions {
Rna sp = new Rna(testIdAlias);
RnaRegion mr = new RnaRegion();
mr.setName("name");
mr.setSize(3.0);
mr.setWidth(3.0);
mr.setState(ModificationState.DONT_CARE);
sp.addRegion(mr);
......@@ -159,7 +159,7 @@ public class AliasDaoTest2 extends PersistTestFunctions {
assertEquals(sp2.getRegions().get(0).getId(), mr.getId());
assertEquals(sp2.getRegions().get(0).getName(), mr.getName());
assertEquals(sp2.getRegions().get(0).getSize(), mr.getSize(), EPSILON);
assertEquals(sp2.getRegions().get(0).getWidth(), mr.getWidth(), EPSILON);
assertEquals(sp2.getRegions().get(0).getState(), mr.getState());
elementDao.delete(sp2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment