Commit 7c40dabc authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '370-genes-annotations' into 'master'

Resolve "Genes annotations don't show"

Closes #370 and #19

See merge request !345
parents 221341ba 4e9f4bf0
Pipeline #5772 passed with stage
in 1 minute and 56 seconds
......@@ -401,7 +401,11 @@ public class ChemicalParser extends CachableInterface implements IExternalServic
}
if (result != null) {
MeSH mesh = meshParser.getMeSH(result.getChemicalId());
if (mesh!=null) {
result.addSynonyms(mesh.getSynonyms());
} else {
logger.warn("Problematic mesh id: "+result.getChemicalId());
}
}
} catch (IOException e) {
......
......@@ -237,17 +237,17 @@ public class HgncAnnotator extends ElementAnnotator implements IExternalService
}
}
}
}
}
}
} catch (WrongResponseCodeIOException e) {
logger.warn(prefix + "Cannot find information for element.");
} catch (Exception e) {
throw new AnnotatorException(e);
}
}
}
}
}
}
}
} catch (WrongResponseCodeIOException e) {
logger.warn(prefix + "Cannot find information for element.");
} catch (Exception e) {
throw new AnnotatorException(e);
}
}
}
/**
* Creates query url for given {@link MiriamType#HGNC} identifier.
......@@ -265,10 +265,12 @@ public class HgncAnnotator extends ElementAnnotator implements IExternalService
*
* @param name
* {@link MiriamType#HGNC_SYMBOL}
* @return url to restful api webpage for given hgnc symbol
* @return url to restful API web page for given HGNC symbol
*/
private String getHgncNameUrl(String name) {
return REST_API_URL + "symbol/" + name;
String hgncSymbol = "" + name;
hgncSymbol = hgncSymbol.split("\\s+")[0];
return REST_API_URL + "symbol/" + hgncSymbol;
}
/**
......@@ -304,34 +306,34 @@ public class HgncAnnotator extends ElementAnnotator implements IExternalService
} else {
Node entry = getNode("doc", resultNode.getChildNodes());
NodeList list = entry.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("arr")) {
String type = getNodeAttr("name", node);
if (type.equals("uniprot_ids")) {
NodeList uniprotList = node.getChildNodes();
for (int j = 0; j < uniprotList.getLength(); j++) {
Node uniprotNode = uniprotList.item(j);
if (uniprotNode.getNodeType() == Node.ELEMENT_NODE) {
if (uniprotNode.getNodeName().equals("str")) {
result.add(createMiriamData(MiriamType.UNIPROT, uniprotNode.getTextContent()));
}
}
}
}
}
}
}
}
return result;
} catch (WrongResponseCodeIOException e) {
logger.warn("No HGNC data found for id: "+miriamData);
return new ArrayList<>();
} catch (Exception e) {
throw new AnnotatorException(e);
}
NodeList list = entry.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equals("arr")) {
String type = getNodeAttr("name", node);
if (type.equals("uniprot_ids")) {
NodeList uniprotList = node.getChildNodes();
for (int j = 0; j < uniprotList.getLength(); j++) {
Node uniprotNode = uniprotList.item(j);
if (uniprotNode.getNodeType() == Node.ELEMENT_NODE) {
if (uniprotNode.getNodeName().equals("str")) {
result.add(createMiriamData(MiriamType.UNIPROT, uniprotNode.getTextContent()));
}
}
}
}
}
}
}
}
return result;
} catch (WrongResponseCodeIOException e) {
logger.warn("No HGNC data found for id: " + miriamData);
return new ArrayList<>();
} catch (Exception e) {
throw new AnnotatorException(e);
}
}
/**
......
......@@ -127,7 +127,7 @@ public interface ReferenceGenomeConnector {
* @param version
* version of the reference genome
* @throws IOException
* thrown when there is a problem with removeing file
* thrown when there is a problem with removing file
*/
void removeGenomeVersion(MiriamData organism, String version) throws IOException;
......@@ -135,7 +135,7 @@ public interface ReferenceGenomeConnector {
* Returns url to the file that describes reference genome.
*
* @param organism
* organism of redference genome
* organism of reference genome
* @param version
* version of the reference genome
* @return url to the file that describes reference genome
......
package lcsb.mapviewer.common.comparator;
import java.util.Comparator;
import java.util.Set;
import org.apache.log4j.Logger;
/**
* Comparator used for comparing sets of strings.
*
* @author Piotr Gawron
*
*/
public class StringSetComparator implements Comparator<Set<String>> {
/**
* Default class logger.
*/
private Logger logger = Logger.getLogger(StringSetComparator.class);
@Override
public int compare(Set<String> arg0, Set<String> arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
for (String string : arg1) {
if (!arg0.contains(string)) {
logger.debug(string + " couldn't be found in " + arg0);
return 1;
}
}
for (String string : arg0) {
if (!arg1.contains(string)) {
logger.debug(string + " couldn't be found in " + arg1);
return -1;
}
}
return 0;
}
}
package lcsb.mapviewer.common.comparator;
import java.util.Comparator;
import java.util.Set;
import org.apache.log4j.Logger;
/**
* Comparator used for comparing sets of strings.
*
* @author Piotr Gawron
*
*/
public class StringSetComparator implements Comparator<Set<String>> {
/**
* Default class logger.
*/
private Logger logger = Logger.getLogger(StringSetComparator.class);
@Override
public int compare(Set<String> arg0, Set<String> arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
for (String string : arg1) {
if (!arg0.contains(string)) {
logger.debug(string + " couldn't be found in " + arg0);
return 1;
}
}
for (String string : arg0) {
if (!arg1.contains(string)) {
logger.debug(string + " couldn't be found in " + arg1);
return -1;
}
}
return 0;
}
}
package lcsb.mapviewer.common.geometry;
import java.awt.geom.Line2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import lcsb.mapviewer.common.Configuration;
import org.apache.log4j.Logger;
/**
* Class with basic operators on lines.
*
* @author Piotr Gawron
*
*/
public class LineTransformation {
/**
* Which value in the PathIterartor segment information array corrsepond to X
* coordinate in the cubicTo type.
*/
private static final int SEG_CUBICTO_END_Y_COORDINATE_INDEX = 5;
/**
* Which value in the PathIterartor segment information array corrsepond to Y
* coordinate in the cubicTo type.
*/
private static final int SEG_CUBICTO_END_X_COORDINATE_INDEX = 4;
/**
* Length of the PathIterartor segment information array.
*/
private static final int PATH_ITERATOR_COORDINATES_STRUCT_SIZE = 6;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(LineTransformation.class.getName());
/**
* Returns a cross point between path and a line.
*
* @param line
* line for which we are looking for the intersection
* @param pi
* PathIterator for which we are looking for the intersection
* @return point of intersection beteewn path and line if the points doesn't
* exist then null is returned
*/
public Point2D getIntersectionWithPathIterator(final Line2D line, final PathIterator pi) {
if (pi == null) {
return null;
}
double[] coordinates = new double[PATH_ITERATOR_COORDINATES_STRUCT_SIZE];
Point2D first = null;
Point2D last = null;
Point2D actual = null;
while (!pi.isDone()) {
int type = pi.currentSegment(coordinates);
last = actual;
actual = new Point2D.Double(coordinates[0], coordinates[1]);
switch (type) {
case PathIterator.SEG_MOVETO:
break;
case PathIterator.SEG_LINETO:
break;
case PathIterator.SEG_QUADTO:
break;
case PathIterator.SEG_CUBICTO:
// in case when there is an arc we define only end points of the arc
// as a border
actual = new Point2D.Double(coordinates[SEG_CUBICTO_END_X_COORDINATE_INDEX], coordinates[SEG_CUBICTO_END_Y_COORDINATE_INDEX]);
break;
case PathIterator.SEG_CLOSE:
actual = first;
break;
default:
break;
}
if (first == null) {
first = actual;
// check if the two following points are not the same (this could cause
// NaN values)
} else if (last.distance(actual) > Configuration.EPSILON) {
double x1 = last.getX();
double y1 = last.getY();
double x2 = actual.getX();
double y2 = actual.getY();
double x3 = line.getX1();
double y3 = line.getY1();
double x4 = line.getX2();
double y4 = line.getY2();
if (Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) {
double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
double xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
double yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
return new Point2D.Double(xi, yi);
}
}
pi.next();
}
return null;
}
/**
* Returns a distance between line segment and a point.
*
* @param line
* line segment to which we are looking the shortest distance
* @param point
* point from which are looking the shortest distance
* @return distance between line and a point
*/
public double distBetweenPointAndLineSegment(final Line2D line, final Point2D point) {
return distBetweenPointAndLineSegment(line.getP1(), line.getP2(), point);
}
/**
* Returns a distance between line segment (defined by v and w points) and a
* point.
*
* @param v
* start point of the line
* @param w
* end point of the line
* @param point
* point from which we want to find a distance
* @return distance between point and line segment
*/
public double distBetweenPointAndLineSegment(final Point2D v, final Point2D w, final Point2D point) {
// Return minimum distance between line segment vw and point p
double l2 = v.distanceSq(w); // i.e. |w-v|^2 - avoid a sqrt
if (l2 == 0.0) {
return point.distance(v); // v == w case
}
// Consider the line extending the segment, parameterized as v + t (w - v).
// We find projection of point p onto the line.
// It falls where t = [(p-v) . (w-v)] / |w-v|^2
double t = ((point.getX() - v.getX()) * (w.getX() - v.getX()) + (point.getY() - v.getY()) * (w.getY() - v.getY())) / l2;
if (t < 0.0) {
return point.distance(v); // Beyond the 'v' end of the segment
} else if (t > 1.0) {
return point.distance(w); // Beyond the 'w' end of the segment
}
// Projection falls on the segment
return point.distance(v.getX() + t * (w.getX() - v.getX()), v.getY() + t * (w.getY() - v.getY()));
}
/**
* Returns a point that is on the line and is as close as possible to the
* point.
*
* @param line
* line on which the point should be found
* @param point
* point to which the result should be as close as possible
* @return point on the line that is as close as possible to the parameter
* point
*/
public Point2D closestPointOnSegmentLineToPoint(final Line2D line, final Point2D point) {
Point2D result = closestPointOnSegmentLineToPoint(line.getP1(), line.getP2(), point);
return result;
}
/**
* Returns a point that is on the line (v-w) and is as close as possible to
* the point.
*
* @param v
* start of the line segment
* @param w
* end of the line segment
* @param p
* point to which the result should be as close as possible
* @return point on the line (v-w) that is as close as possible to the
* parameter point
*/
public Point2D closestPointOnSegmentLineToPoint(final Point2D v, final Point2D w, final Point2D p) {
// Return minimum distance between line segment vw and point p
double l2 = v.distanceSq(w); // i.e. |w-v|^2 - avoid a sqrt
if (l2 == 0.0) {
return v; // v == w case
}
// Consider the line extending the segment, parameterized as v + t (w - v).
// We find projection of point p onto the line.
// It falls where t = [(p-v) . (w-v)] / |w-v|^2
double t = ((p.getX() - v.getX()) * (w.getX() - v.getX()) + (p.getY() - v.getY()) * (w.getY() - v.getY())) / l2;
if (t < 0.0) {
return v; // Beyond the 'v' end of the segment
} else if (t > 1.0) {
return w; // Beyond the 'w' end of the segment
}
// Projection falls on the segment
return new Point2D.Double(v.getX() + t * (w.getX() - v.getX()), v.getY() + t * (w.getY() - v.getY()));
}
}
package lcsb.mapviewer.common.geometry;
import java.awt.geom.Line2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
import lcsb.mapviewer.common.Configuration;
/**
* Class with basic operators on lines.
*
* @author Piotr Gawron
*
*/
public class LineTransformation {
/**
* Which value in the PathIterartor segment information array corrsepond to X
* coordinate in the cubicTo type.
*/
private static final int SEG_CUBICTO_END_Y_COORDINATE_INDEX = 5;
/**
* Which value in the PathIterartor segment information array corrsepond to Y
* coordinate in the cubicTo type.
*/
private static final int SEG_CUBICTO_END_X_COORDINATE_INDEX = 4;
/**
* Length of the PathIterartor segment information array.
*/
private static final int PATH_ITERATOR_COORDINATES_STRUCT_SIZE = 6;
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(LineTransformation.class.getName());
/**
* Returns a cross point between path and a line.
*
* @param line
* line for which we are looking for the intersection
* @param pi
* PathIterator for which we are looking for the intersection
* @return point of intersection between path and line if the points doesn't
* exist then null is returned
*/
public Point2D getIntersectionWithPathIterator(final Line2D line, final PathIterator pi) {
if (pi == null) {
return null;
}
double[] coordinates = new double[PATH_ITERATOR_COORDINATES_STRUCT_SIZE];
Point2D first = null;
Point2D last = null;
Point2D actual = null;
while (!pi.isDone()) {
int type = pi.currentSegment(coordinates);
last = actual;
actual = new Point2D.Double(coordinates[0], coordinates[1]);
switch (type) {
case PathIterator.SEG_MOVETO:
break;
case PathIterator.SEG_LINETO:
break;
case PathIterator.SEG_QUADTO:
break;
case PathIterator.SEG_CUBICTO:
// in case when there is an arc we define only end points of the arc
// as a border
actual = new Point2D.Double(coordinates[SEG_CUBICTO_END_X_COORDINATE_INDEX],
coordinates[SEG_CUBICTO_END_Y_COORDINATE_INDEX]);
break;
case PathIterator.SEG_CLOSE:
actual = first;
break;
default:
break;
}
if (first == null) {
first = actual;
// check if the two following points are not the same (this could cause
// NaN values)
} else if (last.distance(actual) > Configuration.EPSILON) {
double x1 = last.getX();
double y1 = last.getY();
double x2 = actual.getX();
double y2 = actual.getY();
double x3 = line.getX1();
double y3 = line.getY1();
double x4 = line.getX2();
double y4 = line.getY2();
if (Line2D.linesIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) {
double d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 -