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

javadocs

parent 668e2a0e
......@@ -69,6 +69,10 @@ public class ChEMBLParser extends DrugAnnotation implements IExternalService {
* Url that list of all child nodes for chembl ontology term.
*/
private static final String PARENT_CHILD_API_URL = "https://www.ebi.ac.uk/chembl/api/data/molecule_form/";
/**
* Suffix that should be added to {@link #PARENT_CHILD_API_URL}.
*/
private static final String PARENT_CHILD_API_URL_SUFFIX = ".xml";
/**
......
......@@ -4,6 +4,12 @@ import java.awt.Color;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
/**
* Parser clas to extract {@link Color} objects from {@link String}.
*
* @author Piotr Gawron
*
*/
public class ColorParser {
/**
......@@ -31,6 +37,13 @@ public class ColorParser {
*/
private static final int COLOR_SUBSTRING_START_BLUE = 5;
/**
* Extracts {@link Color} from input {@link String}.
*
* @param string
* text to process
* @return {@link Color} obtained from input text
*/
public Color parse(String string) {
if (string.charAt(0) != '#') {
string = "#" + string;
......
......@@ -27,6 +27,7 @@ import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Complex;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
* This class is responsible for creation of the image from the model. It's an
......@@ -94,8 +95,16 @@ public abstract class AbstractImageGenerator {
*/
private Rectangle2D.Double border = null;
/**
* Object that helps to convert {@link ColorSchema} values into colors.
*/
private ColorExtractor colorExtractor = null;
/**
* Util class for simple operations on {@link Element elements}.
*/
private ElementUtils eu = new ElementUtils();
/**
* This class contains a list of params that are used for drawing.
*
......@@ -173,8 +182,14 @@ public abstract class AbstractImageGenerator {
*/
private List<Map<Object, ColorSchema>> visibleLayouts = new ArrayList<>();
/**
* Color that should be used for drawing overlays with minimum value.
*/
private Color minColor = null;
/**
* Color that should be used for drawing overlays with maximum value.
*/
private Color maxColor = null;
/**
......@@ -488,19 +503,45 @@ public abstract class AbstractImageGenerator {
return result;
}
/**
* Returns {@link Color} that should be used for drawing overlays with
* maximum value.
*
* @return {@link Color} that should be used for drawing overlays with
* maximum value
*/
public Color getMaxColor() {
return maxColor;
}
/**
* Returns {@link Color} that should be used for drawing overlays with
* minimum value.
*
* @return {@link Color} that should be used for drawing overlays with
* minimum value
*/
public Color getMinColor() {
return minColor;
}
/**
* @param minColor
* minColor to set
* @return object with all parameters
* @see #minColor
*/
public Params minColor(Color minColor) {
this.minColor = minColor;
return this;
}
/**
* @param maxColor
* maxColor to set
* @return object with all parameters
* @see #maxColor
*/
public Params maxColor(Color maxColor) {
this.maxColor = maxColor;
return this;
......@@ -584,17 +625,18 @@ public abstract class AbstractImageGenerator {
// Get the SBGN display format option from the model
this.sbgnFormat = params.getModel().isSbgnFormat();
// Correct order of displaying is: aliases, reactions, compartments, layers.
// Correct order of displaying is: elements, reactions, compartments,
// layers.
// In this way we can display all reactions and overlay them by compartments
// or layers if they should be solid and hide complexity behind it
// draw all aliases
for (Element alias : params.getModel().getSortedSpeciesList()) {
// draw only aliases that don't have parents (aren't included in any
// draw all elements
for (Element element : params.getModel().getSortedSpeciesList()) {
// draw only elements that don't have parents (aren't included in any
// compartment/complexes)
if (alias instanceof Species) {
if (((Species) alias).getComplex() == null) {
drawAlias((Species) alias, params.getVisibleLayoutsForElement(alias));
if (element instanceof Species) {
if (((Species) element).getComplex() == null) {
drawSpecies((Species) element, params.getVisibleLayoutsForElement(element));
}
}
}
......@@ -603,11 +645,11 @@ public abstract class AbstractImageGenerator {
drawReaction(reaction, params.getVisibleLayoutsForElement(reaction));
}
// draw all compartments
for (Compartment ca : params.getModel().getSortedCompartments()) {
// draw only aliases that don't have parents (aren't included in any
for (Compartment compartment : params.getModel().getSortedCompartments()) {
// draw only compartment that don't have parents (aren't included in any
// compartment/complexes)
if (ca.getCompartment() == null) {
drawCompartmentAlias(ca, params.isNested(), params.getVisibleLayoutsForElement(ca), params);
if (compartment.getCompartment() == null) {
drawCompartment(compartment, params.isNested(), params.getVisibleLayoutsForElement(compartment), params);
}
}
......@@ -638,25 +680,26 @@ public abstract class AbstractImageGenerator {
}
/**
* This method draw a compartment alias on a graphics.
* This method draw a {@link Compartment} on a graphics.
*
* @param compAlias
* @param compartment
* object that we want to draw
* @param nested
* are the compartments drawn in hierarchical view
* @param visibleLayouts
* list of {@link ColorSchema} used for coloring alias in layouts
* list of {@link ColorSchema} used for coloring element in layouts
* @param params
* list of all params to create apropriate image
* @throws DrawingException
* thrown when there was a problem with drawing compartment alias
* thrown when there was a problem with drawing {@link Compartment}
*/
protected void drawCompartmentAlias(final Compartment compAlias, final boolean nested, List<ColorSchema> visibleLayouts, Params params)
protected void drawCompartment(final Compartment compartment, final boolean nested, List<ColorSchema> visibleLayouts, Params params)
throws DrawingException {
// If 'compAlias' has not the big enough visibility level then should not be
// If 'compartment' has not the big enough visibility level then should not
// be
// visible.
if (compAlias.getVisibilityLevel() > level) {
if (compartment.getVisibilityLevel() > level) {
return;
}
......@@ -667,25 +710,25 @@ public abstract class AbstractImageGenerator {
*/
boolean fill = true;
if (compAlias.getTransparencyLevel() <= level) {
if (compartment.getTransparencyLevel() <= level) {
fill = false;
}
// get a converter for this compartment
AliasConverter converter = new AliasConverter(compAlias, colorExtractor);
ElementConverterImpl converter = new ElementConverterImpl(compartment, colorExtractor);
ConverterParams compartmentParams = new ConverterParams().textCentered(fill).level(level);
if (nested) {
compartmentParams.fill(fill).scale(Math.max(scale, 1));
}
// we draw compartment alias only when we have hierarchical view or it's
// standard compartment (not the artifital pathway)
if (nested || !(compAlias instanceof PathwayCompartment)) {
// we draw compartment only when we have hierarchical view or it's
// standard compartment (not the pathway)
if (nested || !(compartment instanceof PathwayCompartment)) {
try {
converter.drawAlias(compAlias, graphics, compartmentParams, visibleLayouts);
converter.drawElement(compartment, graphics, compartmentParams, visibleLayouts);
} catch (Exception e) {
throw new DrawingException("Problem with drawing alias \"" + compAlias.getElementId() + "\" (name: \"" + compAlias.getName() + "\").", e);
throw new DrawingException(eu.getElementTag(compartment) + "Problem with drawing element.", e);
}
}
......@@ -695,48 +738,48 @@ public abstract class AbstractImageGenerator {
if (fill) {
return;
}
List<Element> result = new ArrayList<Element>();
result.addAll(compAlias.getElements());
List<Element> result = new ArrayList<>();
result.addAll(compartment.getElements());
Collections.sort(result, Element.SIZE_COMPARATOR);
// draw all children of this compartment
for (Element alias : result) {
// if a child is a standard alias
if (alias instanceof Species) {
drawAlias((Species) alias, params.getVisibleLayoutsForElement(alias));
} else if (alias instanceof Compartment) {
drawCompartmentAlias((Compartment) alias, nested, params.getVisibleLayoutsForElement(alias), params);
for (Element element : result) {
// if a child is a standard species
if (element instanceof Species) {
drawSpecies((Species) element, params.getVisibleLayoutsForElement(element));
} else if (element instanceof Compartment) {
drawCompartment((Compartment) element, nested, params.getVisibleLayoutsForElement(element), params);
} else {
// if a child is not a compartment or an alias then we have a
// if a child is not a compartment or a species then we have a
// problem
throw new DrawingException("Unknown AliasType: " + alias.getClass().getName());
throw new DrawingException(eu.getElementTag(compartment) + "Unknown Element type");
}
}
if (!compAlias.containsIdenticalSpecies()) {
if (!(compAlias instanceof PathwayCompartment)) {
converter.drawText(compAlias, graphics, compartmentParams);
if (!compartment.containsIdenticalSpecies()) {
if (!(compartment instanceof PathwayCompartment)) {
converter.drawText(compartment, graphics, compartmentParams);
}
}
}
/**
* This method draw a species alias on a graphics.
* This method draw a {@link Species} on a graphics.
*
* @param alias
* @param species
* object to be drawn
* @param visibleLayouts
* list of {@link ColorSchema} used for coloring alias in layouts
* list of {@link ColorSchema} used for coloring species in layouts
* @throws DrawingException
* thrown when there was a problem with drawing an alias
* thrown when there was a problem with drawing a {@link Species}
*/
protected void drawAlias(final Species alias, List<ColorSchema> visibleLayouts) throws DrawingException {
protected void drawSpecies(final Species species, List<ColorSchema> visibleLayouts) throws DrawingException {
// The displaying of alias is indicated by values of VisibilityLevel. If
// The displaying of species is indicated by values of VisibilityLevel. If
// VisibilityLevel is big enough, then it is
// displayed.
if (alias.getVisibilityLevel() > level) {
if (species.getVisibilityLevel() > level) {
return;
}
......@@ -745,42 +788,43 @@ public abstract class AbstractImageGenerator {
* most bottom Complexes.
*/
if (!cross(alias.getBorder())) {
if (!cross(species.getBorder())) {
return;
}
boolean rescale = false;
if (alias instanceof Complex) {
if (((Complex) alias).getElements().size() == 0) {
if (species instanceof Complex) {
if (((Complex) species).getElements().size() == 0) {
rescale = true;
} else if (((Complex) alias).getElements().get(0).getVisibilityLevel() > level) {
} else if (((Complex) species).getElements().get(0).getVisibilityLevel() > level) {
rescale = true;
}
}
// at the beginning try to find an appropriate converter
AliasConverter converter = new AliasConverter(alias, sbgnFormat, colorExtractor);
ElementConverterImpl converter = new ElementConverterImpl(species, sbgnFormat, colorExtractor);
double customScale = 1;
if (rescale) {
customScale = scale;
}
try {
converter.drawAlias(alias, graphics, new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat), visibleLayouts);
converter
.drawElement(species, graphics, new ConverterParams().scale(customScale).textCentered(rescale).level(level).sbgnFormat(sbgnFormat), visibleLayouts);
} catch (Exception e) {
throw new DrawingException("Problem with drawing alias \"" + alias.getElementId() + "\".", e);
throw new DrawingException(eu.getElementTag(species) + "Problem with drawing element.", e);
}
// if the alias is a complex alias then we may want to draw children
// if the species is a complex then we may want to draw children
// objects
if (alias instanceof Complex) {
Complex complex = (Complex) alias;
if (species instanceof Complex) {
Complex complex = (Complex) species;
// before drawing children check if the view is not set to brief
// mode
if (!complex.getState().equalsIgnoreCase("brief")) {
// depending on current zoom level, children are drawn or not
if (complex.getTransparencyLevel() <= level) {
for (Species a : complex.getElements()) {
drawAlias(a, visibleLayouts);
drawSpecies(a, visibleLayouts);
}
}
}
......
......@@ -15,7 +15,7 @@ import lcsb.mapviewer.model.map.species.Element;
* @param <T>
* class of alias to convert
*/
public interface IAliasConverter<T extends Element> {
public interface ElementConverter<T extends Element> {
/**
* Alpha value (0..255) used for visualizing layout data that are normally
* visualized in javascript.
......@@ -35,7 +35,7 @@ public interface IAliasConverter<T extends Element> {
* {@link ConverterParams}
*
*/
void drawAlias(T alias, Graphics2D graphics, ConverterParams params);
void drawElement(T alias, Graphics2D graphics, ConverterParams params);
/**
* This function draw representation of the alias on the graphics object.
......@@ -53,7 +53,7 @@ public interface IAliasConverter<T extends Element> {
* alias in different layouts that should be overlayed on the alias
*
*/
void drawAlias(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas);
void drawElement(T alias, Graphics2D graphics, ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas);
/**
* This function will find proper font size to display text within it. Then it
......
......@@ -53,136 +53,140 @@ import lcsb.mapviewer.model.map.species.Unknown;
import lcsb.mapviewer.modelutils.map.ElementUtils;
/**
* This class is designed to convert any type of alias into a graphic glyph that
* will be visualized on the graphgics2d object. It contains static instances of
* converter for every type and use one that is needed for currently processed
* alias.
* This class is designed to convert any type of {@link Element} into a graphic
* glyph that will be visualized on the {@link Graphics2D} object.
*
* @author Piotr Gawron
*
*/
public class AliasConverter implements IAliasConverter<Element> {
public class ElementConverterImpl implements ElementConverter<Element> {
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(AliasConverter.class.getName());
private static Logger logger = Logger.getLogger(ElementConverterImpl.class.getName());
/**
* Returns a converter for given alias. If converter doesn't exist then null
* is returned.
* Returns a converter for given element. If converter doesn't exist then
* exception is thrown.
*
* @param alias
* alias for which we are loooking for a converter
* @return converter that can be applied for the given alias; null if such
* converter doesn't exist
* @param element
* {@link Element} for which we are loooking for a converter
* @param colorExtractor
* object that helps to convert overlay values into colors
* @return converter that can be applied for the given element
*/
private IAliasConverter<? extends Element> getConverterForAlias(Element alias, ColorExtractor colorExtractor) {
if (alias == null) {
throw new InvalidArgumentException("alias cannot be null");
private ElementConverter<? extends Element> getConverterForElement(Element element, ColorExtractor colorExtractor) {
if (element == null) {
throw new InvalidArgumentException("element cannot be null");
}
if (alias instanceof GenericProtein) {
if (element instanceof GenericProtein) {
return new ProteinConverter(colorExtractor);
} else if (alias instanceof IonChannelProtein) {
} else if (element instanceof IonChannelProtein) {
return new ProteinConverter(colorExtractor);
} else if (alias instanceof ReceptorProtein) {
} else if (element instanceof ReceptorProtein) {
return new ProteinConverter(colorExtractor);
} else if (alias instanceof TruncatedProtein) {
} else if (element instanceof TruncatedProtein) {
return new ProteinConverter(colorExtractor);
} else if (alias instanceof Degraded) {
} else if (element instanceof Degraded) {
return new DegradedConverter(colorExtractor);
} else if (alias instanceof Complex) {
} else if (element instanceof Complex) {
return new ComplexConverter(colorExtractor);
} else if (alias instanceof SimpleMolecule) {
} else if (element instanceof SimpleMolecule) {
return new SimpleMoleculeConverter(colorExtractor);
} else if (alias instanceof Drug) {
} else if (element instanceof Drug) {
return new DrugConverter(colorExtractor);
} else if (alias instanceof Ion) {
} else if (element instanceof Ion) {
return new IonConverter(colorExtractor);
} else if (alias instanceof Phenotype) {
} else if (element instanceof Phenotype) {
return new PhenotypeConverter(colorExtractor);
} else if (alias instanceof Rna) {
} else if (element instanceof Rna) {
return new RnaConverter(colorExtractor);
} else if (alias instanceof AntisenseRna) {
} else if (element instanceof AntisenseRna) {
return new AntisenseRnaConverter(colorExtractor);
} else if (alias instanceof Gene) {
} else if (element instanceof Gene) {
return new GeneConverter(colorExtractor);
} else if (alias instanceof Unknown) {
} else if (element instanceof Unknown) {
return new UnknownConverter(colorExtractor);
} else if (alias instanceof SquareCompartment) {
} else if (element instanceof SquareCompartment) {
return new SquareCompartmentConverter(colorExtractor);
} else if (alias instanceof OvalCompartment) {
} else if (element instanceof OvalCompartment) {
return new OvalCompartmentConverter(colorExtractor);
} else if (alias instanceof PathwayCompartment) {
} else if (element instanceof PathwayCompartment) {
return new PathwayCompartmentConverter(colorExtractor);
} else if (alias instanceof BottomSquareCompartment) {
} else if (element instanceof BottomSquareCompartment) {
return new BottomSquareCompartmentConverter(colorExtractor);
} else if (alias instanceof TopSquareCompartment) {
} else if (element instanceof TopSquareCompartment) {
return new TopSquareCompartmentConverter(colorExtractor);
} else if (alias instanceof LeftSquareCompartment) {
} else if (element instanceof LeftSquareCompartment) {
return new LeftSquareCompartmentConverter(colorExtractor);
} else if (alias instanceof RightSquareCompartment) {
} else if (element instanceof RightSquareCompartment) {
return new RightSquareCompartmentConverter(colorExtractor);
} else {
throw new NotImplementedException(new ElementUtils().getElementTag(alias) + "Unknown element class");
throw new NotImplementedException(new ElementUtils().getElementTag(element) + "Unknown element class");
}
}
/**
* Converter used for conversion of the alias given in constructor.
* Converter used for conversion of the {@link Element} given in constructor.
*/
@SuppressWarnings("rawtypes")
private IAliasConverter aliasConverter = null;
private ElementConverter elementConverter = null;
/**
* Support constructor. Used in case of SBGN format display
*
* @param alias
* alias for which this converter will be used
* @param element
* {@link Element} for which this converter will be used
* @param colorExtractor
* object that helps to convert overlay values into colors
* @param sbgnFormat
* boolean value indicating if SBGN display format should be used
*/
public AliasConverter(final Element alias, final boolean sbgnFormat, ColorExtractor colorExtractor) {
public ElementConverterImpl(final Element element, final boolean sbgnFormat, ColorExtractor colorExtractor) {
// If alias is a nucleic acid feature to be displayed in SBGN
if (sbgnFormat && (alias instanceof AntisenseRna || alias instanceof Rna || alias instanceof Gene)) {
aliasConverter = new SBGNNucleicAcidFeatureConverter(colorExtractor);
// If element is a nucleic acid feature to be displayed in SBGN
if (sbgnFormat && (element instanceof AntisenseRna || element instanceof Rna || element instanceof Gene)) {
elementConverter = new SBGNNucleicAcidFeatureConverter(colorExtractor);
} else {
// If not, at the beginning try to find an appropriate converter
aliasConverter = getConverterForAlias(alias, colorExtractor);
elementConverter = getConverterForElement(element, colorExtractor);
}
// if we don't know which converter to use then throw an exception
if (aliasConverter == null) {
throw new InvalidArgumentException("Unknown converter for class: " + alias.getClass() + ". Alias id: " + alias.getElementId());
if (elementConverter == null) {
throw new InvalidArgumentException("Unknown converter for class: " + element.getClass() + ". Element id: " + element.getElementId());
}
}
/**
* Default constructor.
*
* @param alias
* alias for which this converter will be used
* @param colorExtractor
* object that helps to convert overlay values into colors
* @param element
* {@link Element} for which this converter will be used
*/
public AliasConverter(final Element alias, ColorExtractor colorExtractor) {
this(alias, false, colorExtractor);
public ElementConverterImpl(final Element element, ColorExtractor colorExtractor) {
this(element, false, colorExtractor);
}