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) {
......
......@@ -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;
}
/**
......@@ -327,7 +329,7 @@ public class HgncAnnotator extends ElementAnnotator implements IExternalService
}
return result;
} catch (WrongResponseCodeIOException e) {
logger.warn("No HGNC data found for id: "+miriamData);
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
......
......@@ -48,8 +48,8 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
private static final String SERVER = "hgdownload.cse.ucsc.edu";
/**
* Prefix string used for marking queries in cache database that identifies
* list of reference genome versions by organism id.
* Prefix string used for marking queries in cache database that identifies list
* of reference genome versions by organism id.
*/
static final String FILENAME_BY_ORGANISM_VERSION_PREFIX = "ORGANISM_VERSION_FILE:";
......@@ -61,7 +61,7 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
/**
* Regex pattern that helps to find out organism names in source file.
*/
private Pattern organismNamePattern = Pattern.compile("<!--([A-Za-z\\-\\.\\ ]+)Downloads [=]+ -->");
private Pattern organismNamePattern = Pattern.compile("<!--([A-Za-z\\-\\.\\ ]+)Downloads [=]*[\\ ]*-->");
/**
* Regex pattern that helps to find out reference genome versions.
......@@ -337,8 +337,8 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
}
@Override
public void downloadGenomeVersion(MiriamData organism, String version, IProgressUpdater updater, boolean async, String customUrl)
throws IOException, URISyntaxException, ReferenceGenomeConnectorException {
public void downloadGenomeVersion(MiriamData organism, String version, IProgressUpdater updater, boolean async,
String customUrl) throws IOException, URISyntaxException, ReferenceGenomeConnectorException {
Callable<Void> computations = new DownloadGenomeVersionTask(organism, version, customUrl, updater);
if (async) {
getAsyncExecutorService().submit(computations);
......@@ -349,8 +349,8 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
}
/**
* Returns local path on ftp server to folder with data about given organism
* and version.
* Returns local path on ftp server to folder with data about given organism and
* version.
*
* @param organism
* organism of reference genome
......@@ -364,7 +364,8 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
@Override
public String getGenomeVersionFile(MiriamData organism, String version) throws FileNotAvailableException {
String filename = super.getCacheValue(FILENAME_BY_ORGANISM_VERSION_PREFIX + organism.getResource() + "\n" + version);
String filename = super.getCacheValue(
FILENAME_BY_ORGANISM_VERSION_PREFIX + organism.getResource() + "\n" + version);
if (filename != null) {
return filename;
}
......@@ -376,7 +377,8 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw new FileNotAvailableException("Cannot find file with genome for: " + organism + "; " + version + ". FTP server refused connection.");
throw new FileNotAvailableException(
"Cannot find file with genome for: " + organism + "; " + version + ". FTP server refused connection.");
} else {
ftp.enterLocalPassiveMode();
ftp.login("anonymous", "");
......@@ -385,6 +387,7 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
String remotePath = getGenomePath(organism, version);
FTPFile[] files = ftp.listFiles(remotePath);
for (FTPFile ftpFile : files) {
logger.debug(ftpFile.getName());
if (ftpFile.getName().endsWith(".2bit")) {
if (filename != null) {
logger.warn("More than one 2bit file found in a folder: " + remotePath + ". Using first: " + filename);
......@@ -402,7 +405,8 @@ public class UcscReferenceGenomeConnector extends AbstractReferenceGenomeConnect
try {
ftp.disconnect();
} catch (IOException ioe) {
throw new FileNotAvailableException("Cannot find file with genome for: " + organism + "; " + version + ". Problem with ftp connection.", ioe);
throw new FileNotAvailableException(
"Cannot find file with genome for: " + organism + "; " + version + ". Problem with ftp connection.", ioe);
}
}
}
......
......@@ -200,6 +200,29 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testGetAnnotationsForBID() throws Exception {
try {
GenericProtein bidProtein = new GenericProtein("id");
bidProtein.setName("BID");
hgncAnnotator.annotateElement(bidProtein);
GenericProtein bidMutationProtein = new GenericProtein("id2");
bidMutationProtein.setName("BID (p15)");
hgncAnnotator.annotateElement(bidMutationProtein);
assertEquals(bidProtein.getSymbol(),bidMutationProtein.getSymbol());
assertEquals(bidProtein.getFormerSymbols(),bidMutationProtein.getFormerSymbols());
assertEquals(bidProtein.getFullName(),bidMutationProtein.getFullName());
assertEquals(bidProtein.getMiriamData(),bidMutationProtein.getMiriamData());
assertEquals(bidProtein.getSynonyms(),bidMutationProtein.getSynonyms());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetAnnotationsForInvalid() throws Exception {
try {
......@@ -300,8 +323,10 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
@Test
public void testHgncIdToName() throws Exception {
try {
assertEquals(new MiriamData(MiriamType.HGNC_SYMBOL, "FSD2", HgncAnnotator.class), hgncAnnotator.hgncIdToHgncName(new MiriamData(MiriamType.HGNC, "18024")));
assertEquals(new MiriamData(MiriamType.HGNC_SYMBOL, "LMOD1", HgncAnnotator.class), hgncAnnotator.hgncIdToHgncName(new MiriamData(MiriamType.HGNC, "6647")));
assertEquals(new MiriamData(MiriamType.HGNC_SYMBOL, "FSD2", HgncAnnotator.class),
hgncAnnotator.hgncIdToHgncName(new MiriamData(MiriamType.HGNC, "18024")));
assertEquals(new MiriamData(MiriamType.HGNC_SYMBOL, "LMOD1", HgncAnnotator.class),
hgncAnnotator.hgncIdToHgncName(new MiriamData(MiriamType.HGNC, "6647")));
} catch (Exception e) {
e.printStackTrace();
throw e;
......@@ -342,7 +367,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testHgncToEntrezWithInvalidArg() throws Exception {
try {
......@@ -375,7 +399,6 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
}
}
@Test
public void testHgncIdToNameWithInvalidArg() throws Exception {
try {
......@@ -531,7 +554,8 @@ public class HgncAnnotatorTest extends AnnotationTestFunctions {
WebPageDownloader downloader = hgncAnnotator.getWebPageDownloader();
try {
WebPageDownloader mockDownloader = Mockito.mock(WebPageDownloader.class);
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString())).thenReturn("<response><result/></response>");
when(mockDownloader.getFromNetwork(anyString(), anyString(), anyString()))
.thenReturn("<response><result/></response>");
hgncAnnotator.setWebPageDownloader(mockDownloader);
assertEquals(ExternalServiceStatusType.CHANGED, hgncAnnotator.getServiceStatus().getStatus());
} catch (Exception e) {
......
......@@ -80,6 +80,7 @@ public class UcscReferenceGenomeConnectorTest extends AnnotationTestFunctions {
MiriamData human = new MiriamData(MiriamType.TAXONOMY, "9606");
try {
List<String> list = connector.getAvailableGenomeVersion(human);
logger.debug(list);
assertTrue(list.size() >= 17);
} catch (Exception e) {
e.printStackTrace();
......@@ -126,6 +127,7 @@ public class UcscReferenceGenomeConnectorTest extends AnnotationTestFunctions {
MiriamData human = new MiriamData(MiriamType.TAXONOMY, "9606");
MiriamData chicken = new MiriamData(MiriamType.TAXONOMY, "9031");
List<MiriamData> list = connector.getAvailableOrganisms();
logger.debug(list);
assertTrue(list.size() > 40);
assertTrue(list.contains(human));
......@@ -194,7 +196,8 @@ public class UcscReferenceGenomeConnectorTest extends AnnotationTestFunctions {
}
}
assertNotNull(genome);
connector.downloadGeneMappingGenomeVersion(genome, "test", null, false, "http://www.biodalliance.org/datasets/flyThickets.bb");
connector.downloadGeneMappingGenomeVersion(genome, "test", null, false,
"http://www.biodalliance.org/datasets/flyThickets.bb");
dbUtils.createSessionForCurrentThread();
genomes = referenceGenomeDao.getByType(ReferenceGenomeType.UCSC);
......@@ -232,7 +235,7 @@ public class UcscReferenceGenomeConnectorTest extends AnnotationTestFunctions {
assertTrue(e.getMessage().contains("Only big bed format files are supported"));
}
// connector.removeGeneMapping(genome.getGeneMapping().get(0));
// connector.removeGeneMapping(genome.getGeneMapping().get(0));
int warningCount = getWarnings().size();
......@@ -665,7 +668,8 @@ public class UcscReferenceGenomeConnectorTest extends AnnotationTestFunctions {
MiriamData yeast = new MiriamData(MiriamType.TAXONOMY, "4932");
String version = "sacCer3";
String query = UcscReferenceGenomeConnector.FILENAME_BY_ORGANISM_VERSION_PREFIX + yeast.getResource() + "\n" + version;
String query = UcscReferenceGenomeConnector.FILENAME_BY_ORGANISM_VERSION_PREFIX + yeast.getResource() + "\n"
+ version;
Object res = connector.refreshCacheQuery(query);
assertNotNull(res);
} catch (Exception e) {
......@@ -680,7 +684,8 @@ public class UcscReferenceGenomeConnectorTest extends AnnotationTestFunctions {
MiriamData yeast = new MiriamData(MiriamType.TAXONOMY, "4932");
String version = "unkVer";
String query = UcscReferenceGenomeConnector.FILENAME_BY_ORGANISM_VERSION_PREFIX + yeast.getResource() + "\n" + version;
String query = UcscReferenceGenomeConnector.FILENAME_BY_ORGANISM_VERSION_PREFIX + yeast.getResource() + "\n"
+ version;
connector.refreshCacheQuery(query);
} catch (SourceNotAvailable e) {
} catch (Exception e) {
......
......@@ -4,10 +4,10 @@ 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;
import lcsb.mapviewer.common.Configuration;
/**
* Class with basic operators on lines.
*
......@@ -43,7 +43,7 @@ public class LineTransformation {
* 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
* @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) {
......@@ -69,7 +69,8 @@ public class LineTransformation {
// 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]);
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;
......@@ -138,7 +139,8 @@ public class LineTransformation {
// 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;
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) {
......@@ -149,15 +151,13 @@ public class LineTransformation {
}
/**
* Returns a point that is on the line and is as close as possible to the
* point.
* 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
* @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);
......@@ -165,8 +165,8 @@ public class LineTransformation {
}
/**
* Returns a point that is on the line (v-w) and is as close as possible to
* the point.
* 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
......@@ -174,8 +174,8 @@ public class LineTransformation {
* 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
* @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
......
......@@ -17,9 +17,8 @@ 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.AntisenseRnaRegion;
import lcsb.mapviewer.model.map.species.field.AbstractSiteModification;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
import lcsb.mapviewer.model.map.species.field.RnaRegion;
/**
* This structure contains information about {@link CellDesignerElement
......@@ -100,31 +99,29 @@ public class CellDesignerElementCollection {
}
String modifications = "";
List<ModificationResidue> regions = new ArrayList<>();
if (modelElement instanceof AntisenseRna) {
AntisenseRna asAntisenseRna = ((AntisenseRna) modelElement);
for (AntisenseRnaRegion region : asAntisenseRna.getRegions()) {
modifications += region.getState();
}
regions.addAll(asAntisenseRna.getRegions());
} else if (modelElement instanceof Gene) {
Gene asGene = ((Gene) modelElement);
for (ModificationResidue region : asGene.getModificationResidues()) {
modifications += region.getState();
}
regions.addAll(asGene.getModificationResidues());
} else if (modelElement instanceof Protein) {
Protein asProtein = ((Protein) modelElement);
modifications = asProtein.getStructuralState();
for (ModificationResidue region : asProtein.getModificationResidues()) {
modifications += region.getState();
}
regions.addAll(asProtein.getModificationResidues());
} else if (modelElement instanceof Rna) {
Rna asRna = ((Rna) modelElement);
for (RnaRegion region : asRna.getRegions()) {
modifications += region.getState();
}
regions.addAll(asRna.getRegions());
} else if (modelElement instanceof Complex) {
Complex asComplex = ((Complex) modelElement);
modifications = asComplex.getStructuralState();
}
for (ModificationResidue region : regions) {
if (region instanceof AbstractSiteModification) {
modifications += ((AbstractSiteModification) region).getState();
}
}
String complexId = "";
String homodimer = "";
......@@ -135,7 +132,8 @@ public class CellDesignerElementCollection {
if (!isCyclicNesting(((Species) modelElement).getComplex())) {
complexId = getElementId(((Species) modelElement).getComplex());
} else {
throw new InvalidArgumentException("Cycling nested structure found in element: " + modelElement.getElementId());
throw new InvalidArgumentException(
"Cycling nested structure found in element: " + modelElement.getElementId());
}
} else {
complexId = ((Species) modelElement).getComplex().getName();
......@@ -159,8 +157,8 @@ public class CellDesignerElementCollection {
// name, compartment, modifications, homodimer, state, complex where it's
// located,
// children of the complex
String sbmlId = compartmenName + "\n" + modelElement.getName() + "\n" + modelElement.getStringType() + "\n" + modifications + "\n" + complexId + "\n"
+ homodimer + "\n" + childrenId;
String sbmlId = compartmenName + "\n" + modelElement.getName() + "\n" + modelElement.getStringType() + "\n"
+ modifications + "\n" + complexId + "\n" + homodimer + "\n" + childrenId;
return sbmlId;
}
......@@ -170,8 +168,8 @@ public class CellDesignerElementCollection {
*
* @param complex
* complex for which data is checked
* @return true if parent of the complex is also a (grand)child of this
* complex, false otherwise
* @return true if parent of the complex is also a (grand)child of this complex,
* false otherwise
*/
private boolean isCyclicNesting(Complex complex) {
Set<Complex> foundComplexes = new HashSet<>();
......@@ -218,15 +216,15 @@ public class CellDesignerElementCollection {
*/
public void addElement(CellDesignerElement<?> element, String id) {
if (elementById.get(id) != null) {
throw new InvalidArgumentException(
"[" + element.getClass().getSimpleName() + " " + element.getElementId() + "]\t" + "Element with given id alread exists. ID: " + id);
throw new InvalidArgumentException("[" + element.getClass().getSimpleName() + " " + element.getElementId() + "]\t"
+ "Element with given id alread exists. ID: " + id);
}
elementById.put(id, element);
}
/**
* Adds CellDesigner structure in a way that it would be accessed via
* identifier for model structure. Method used only for unit test.
* Adds CellDesigner structure in a way that it would be accessed via identifier
* for model structure. Method used only for unit test.
*
* @param modelElement
* model element that will create identifier
......
......@@ -143,6 +143,9 @@ public class SpeciesAliasXmlParser extends AbstractAliasXmlParser<Species> {
complex.addSpecies(result);
}
}
species.updateModelElementAfterLayoutAdded(result);
return result;
}
......
package lcsb.mapviewer.converter.model.celldesigner.geometry;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
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;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerAnchor;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerEllipseTransformation;
......@@ -13,6 +18,8 @@ import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerP
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.CellDesignerRectangleTransformation;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.model.map.species.field.ModificationResidue;
/**
* This abstract class is an interface for setting up graphical data for alias
......@@ -24,6 +31,31 @@ import lcsb.mapviewer.model.map.species.Element;
*/
public abstract class AbstractCellDesignerAliasConverter<T extends Element> implements ICellDesignerAliasConverter<T> {
/**
* PI value.
*/
private static final double PI = Math.PI;
/**
* Constant determining angle of the top right corner.
*/
protected static final double RIGHT_TOP_RESIDUE_MAX_ANGLE = 0.25 * PI;
/**
* Constant determining angle of the top left corner.
*/
protected static final double TOP_RESIDUE_MAX_ANGLE = 0.75 * PI;
/**
* Constant determining angle of the bottom left corner.
*/
protected static final double LEFT_RESIDUE_MAX_ANGLE = 1.25 * PI;
/**
* Constant determining angle of the bottom right corner.
*/
protected static final double BOTTOM_RESIDUE_MAX_ANGLE = 1.75 * PI;
/**
* Default class logger.
*/
......@@ -35,7 +67,7 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
private CellDesignerPolygonTransformation polygonTransformation = new CellDesignerPolygonTransformation();
/**
* CellDesigner graphical helper with lin transformation functions.
* CellDesigner graphical helper with line transformation functions.
*/
private LineTransformation lineTransformation = new LineTransformation();
......@@ -55,15 +87,15 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
public static final int HOMODIMER_OFFSET = 6;
/**
* Should the converter use sbgn standard.
* Should the converter use SBGN standard.
*/
private boolean sbgn;
/**
* Default constructor that prevents from instatiation of the class.
* Default constructor that prevents from instantiation of the class.
*
* @param sbgn
* Should the converter use sbgn standard
* Should the converter use SBGN standard
*/
protected AbstractCellDesignerAliasConverter(boolean sbgn) {
this.sbgn = sbgn;
......@@ -105,8 +137,8 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
}
/**
* This method computes coordinates that should be associated with the angle
* on the border of the alias.
* This method computes coordinates that should be associated with the angle on
* the border of the alias.
*
* @param alias
* alias to be investigated
......@@ -232,4 +264,162 @@ public abstract class AbstractCellDesignerAliasConverter<T extends Element> impl
return sbgn;
}
/**
* Returns coordinates on the {@link Species} border for given angle for
* residues.
*
* @param species
* object on border which the point is looked for
* @param angle
* CellDEsigner specific angle defining coordinates (;/)
* @return coordinates on the alias border that correspond to the angle