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