Commit 1b12ded6 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

rna regions use x,y coordinates instead of CellDesigner angle

parent 1294cbb8
package lcsb.mapviewer.converter.model.celldesigner.structure;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerRnaRegion;
import lcsb.mapviewer.model.map.species.Rna;
/**
* Class representing CellDesigner {@link Rna}.
*
* @author Piotr Gawron
*
*/
public class CellDesignerRna extends CellDesignerSpecies<Rna> {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerRna.class.getName());
/**
* List of rna regions (some rna sequences) in this object.
*/
private List<CellDesignerRnaRegion> regions = new ArrayList<>();
/**
* Constructor that initializes rna with the data passed in the argument.
*
* @param species
* original species used for data initialization
*/
public CellDesignerRna(CellDesignerSpecies<?> species) {
super(species);
if (species instanceof CellDesignerRna) {
CellDesignerRna rna = (CellDesignerRna) species;
for (CellDesignerRnaRegion region : rna.getRegions()) {
addRegion(new CellDesignerRnaRegion(region));
}
}
}
/**
* Default constructor.
*/
public CellDesignerRna() {
super();
}
@Override
public CellDesignerRna copy() {
if (this.getClass() == CellDesignerRna.class) {
return new CellDesignerRna(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
@Override
public void update(CellDesignerSpecies<?> species) {
super.update(species);
if (species instanceof CellDesignerRna) {
CellDesignerRna rna = (CellDesignerRna) species;
for (CellDesignerRnaRegion mr : getRegions()) {
mr.setState(null);
}
for (CellDesignerRnaRegion region : rna.getRegions()) {
updateRegion(region);
}
}
}
/**
* Updates region in the rna. If region doesn't exist then it is added.
*
* @param param
* region that with the data to update
*/
private void updateRegion(CellDesignerRnaRegion param) {
for (CellDesignerRnaRegion region : regions) {
if (region.getIdRnaRegion().equals(param.getIdRnaRegion())) {
region.update(param);
return;
}
}
addRegion(new CellDesignerRnaRegion(param));
}
/**
* Adds region. If the region with given id exists then the data of this
* region is copied to the one that is already in the {@link CellDesignerRna}.
*
* @param rnaRegion
* region to add
*/
public void addRegion(CellDesignerRnaRegion rnaRegion) {
for (CellDesignerRnaRegion region2 : regions) {
if (region2.getIdRnaRegion().equals(rnaRegion.getIdRnaRegion())) {
region2.update(rnaRegion);
return;
}
}
regions.add(rnaRegion);
rnaRegion.setSpecies(this);
}
/**
* @return the regions
* @see #regions
*/
public List<CellDesignerRnaRegion> getRegions() {
return regions;
}
/**
* @param regions
* the regions to set
* @see #regions
*/
public void setRegions(List<CellDesignerRnaRegion> regions) {
this.regions = regions;
}
@Override
public Rna createModelElement(String aliasId) {
Rna result = new Rna(aliasId);
super.setModelObjectFields(result);
for (CellDesignerRnaRegion region : regions) {
result.addRegion(region.createRnaRegionAlias());
}
return result;
}
}
package lcsb.mapviewer.converter.model.celldesigner.structure;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.structure.fields.CellDesignerRnaRegion;
import lcsb.mapviewer.model.map.species.Rna;
import lcsb.mapviewer.model.map.species.Species;
/**
* Class representing CellDesigner {@link Rna}.
*
* @author Piotr Gawron
*
*/
public class CellDesignerRna extends CellDesignerSpecies<Rna> {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerRna.class.getName());
/**
* List of rna regions (some rna sequences) in this object.
*/
private List<CellDesignerRnaRegion> regions = new ArrayList<>();
/**
* Constructor that initializes rna with the data passed in the argument.
*
* @param species
* original species used for data initialization
*/
public CellDesignerRna(CellDesignerSpecies<?> species) {
super(species);
if (species instanceof CellDesignerRna) {
CellDesignerRna rna = (CellDesignerRna) species;
for (CellDesignerRnaRegion region : rna.getRegions()) {
addRegion(new CellDesignerRnaRegion(region));
}
}
}
/**
* Default constructor.
*/
public CellDesignerRna() {
super();
}
@Override
public CellDesignerRna copy() {
if (this.getClass() == CellDesignerRna.class) {
return new CellDesignerRna(this);
} else {
throw new NotImplementedException("Method copy() should be overriden in class " + this.getClass());
}
}
@Override
public void update(CellDesignerSpecies<?> species) {
super.update(species);
if (species instanceof CellDesignerRna) {
CellDesignerRna rna = (CellDesignerRna) species;
for (CellDesignerRnaRegion mr : getRegions()) {
mr.setState(null);
}
for (CellDesignerRnaRegion region : rna.getRegions()) {
updateRegion(region);
}
}
}
/**
* Updates region in the rna. If region doesn't exist then it is added.
*
* @param param
* region that with the data to update
*/
private void updateRegion(CellDesignerRnaRegion param) {
for (CellDesignerRnaRegion region : regions) {
if (region.getIdRnaRegion().equals(param.getIdRnaRegion())) {
region.update(param);
return;
}
}
addRegion(new CellDesignerRnaRegion(param));
}
/**
* Adds region. If the region with given id exists then the data of this region
* is copied to the one that is already in the {@link CellDesignerRna}.
*
* @param rnaRegion
* region to add
*/
public void addRegion(CellDesignerRnaRegion rnaRegion) {
for (CellDesignerRnaRegion region2 : regions) {
if (region2.getIdRnaRegion().equals(rnaRegion.getIdRnaRegion())) {
region2.update(rnaRegion);
return;
}
}
regions.add(rnaRegion);
rnaRegion.setSpecies(this);
}
/**
* @return the regions
* @see #regions
*/
public List<CellDesignerRnaRegion> getRegions() {
return regions;
}
/**
* @param regions
* the regions to set
* @see #regions
*/
public void setRegions(List<CellDesignerRnaRegion> regions) {
this.regions = regions;
}
@Override
public Rna createModelElement(String aliasId) {
Rna result = new Rna(aliasId);
super.setModelObjectFields(result);
return result;
}
@Override
public void updateModelElementAfterLayoutAdded(Species element) {
for (CellDesignerRnaRegion region : regions) {
Rna rna = (Rna) element;
rna.addRegion(region.createRnaRegionAlias(rna));
}
}
}
package lcsb.mapviewer.converter.model.celldesigner.structure.fields;
import java.io.Serializable;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna;
import lcsb.mapviewer.model.map.species.field.ModificationState;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* This structure contains information about rna region (rna fragment of
* interest) for a specific
* {@link lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerRna
* Rna}.
*
* @author Piotr Gawron
*
*/
public class CellDesignerRnaRegion implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Default {@link #size} of the region.
*/
private static final double DEFAULT_SIZE = 0.1;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(CellDesignerRnaRegion.class.getName());
/**
* Identifier of the region. Unique in the
* {@link lcsb.mapviewer.model.map.model.Model}.
*/
private String idRnaRegion = "";
/**
* Type of the region in the rna. There are three possible values:
* <ul>
* <li>Coding region,</li>
* <li>Protein binding domain,</li>
* <li>Modification site.</li>
* </ul>
*/
private String type = "";
/**
* Defines a state of the region (for instance ubiquitinated etc).
*
* @see ModificationState
*/
private ModificationState state = null;
/**
* Name of the region.
*/
private String name = "";
/**
* Size of the region in the graphic representation.
*/
private double size = DEFAULT_SIZE;
/**
* Position on the species in graphic representation.
*/
private Double pos;
/**
* Defines a species where the region belongs to.
*/
private CellDesignerRna species;
/**
* Default constructor.
*/
public CellDesignerRnaRegion() {
}
/**
* Creates object with the data taken from paramter region.
*
* @param mr
* original {@link CellDesignerRnaRegion}
*/
public CellDesignerRnaRegion(CellDesignerRnaRegion mr) {
this.idRnaRegion = mr.idRnaRegion;
this.size = mr.size;
setPos(mr.getPos());
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);
}
}
/**
* Sets {@link #pos}.
*
* @param text
* new {@link #pos} value in string format
*/
public void setPos(String text) {
try {
setPos(Double.parseDouble(text));
} catch (NumberFormatException e) {
throw new InvalidArgumentException("Invalid pos: " + text, e);
}
}
/**
* Updates fields in the object with the data given in the parameter rna
* region.
*
* @param mr
* {@link CellDesignerRnaRegion} from which data will be used to
* update
*/
public void update(CellDesignerRnaRegion mr) {
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();
if (mr.getState() != null) {
this.state = mr.getState();
}
if (mr.getName() != null) {
this.name = mr.getName();
}
if (mr.getPos() != null) {
this.setPos(mr.getPos());
}
}
@Override
public String toString() {
String result = "" + getIdRnaRegion() + "," + getType() + "," + getPos() + "," + getSize() + "," + getState() + ",";
return result;
}
/**
* @return the id
* @see #id
*/
public String getIdRnaRegion() {
return idRnaRegion;
}
/**
* @param id
* the id to set
* @see #id
*/
public void setIdRnaRegion(String id) {
this.idRnaRegion = id;
}
/**
* @return the type
* @see #type
*/
public String getType() {
return type;
}
/**
* @param type
* the type to set
* @see #type
*/
public void setType(String type) {
this.type = type;
}
/**
* @return the state
* @see #state
*/
public ModificationState getState() {
return state;
}
/**
* @param state
* the state to set
* @see #state
*/
public void setState(ModificationState state) {
this.state = state;
}
/**
* @return the name
* @see #name
*/
public String getName() {
return name;
}
/**
* @param name
* the name to set
* @see #name
*/
public void setName(String name) {
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 pos
* @see #pos
*/
public Double getPos() {
return pos;
}
/**
* @param pos
* the pos to set
* @see #pos
*/