Commit 97411e82 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

data overlays are processed properly in zip file

parent 32647bee
Pipeline #42997 failed with stage
in 25 minutes
minerva (16.0.0~beta.1) stable; urgency=medium
* Bug fix: there was issue with updating data overlay in admin panel "Unknown
parameter: defaultOverlay"
* Bug fix: data overlays uploaded in complex map were not processed properly
(#1485)
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 9 Jun 2021 15:00:00 +0200
......
package lcsb.mapviewer.services.utils.data;
package lcsb.mapviewer.converter;
import java.util.HashSet;
import java.util.Set;
......
package lcsb.mapviewer.services.utils;
package lcsb.mapviewer.converter;
import java.awt.Color;
import java.io.*;
import java.lang.reflect.Field;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.annotation.services.MiriamConnector;
import lcsb.mapviewer.common.*;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.converter.model.celldesigner.species.SpeciesMapping;
import lcsb.mapviewer.converter.zip.ZipEntryFileFactory;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.ReferenceGenomeType;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.overlay.*;
import lcsb.mapviewer.services.utils.data.ColorSchemaColumn;
/**
* Class that reads information about set of {@link DataOverlayEntry color
......@@ -46,6 +43,22 @@ public class ColorSchemaReader {
*/
private static final int MIN_GV_RED_VALUE = 128;
private static Map<String, Class<? extends BioEntity>> speciesMapping;
static {
speciesMapping = new HashMap<>();
speciesMapping.put("protein", Protein.class);
speciesMapping.put("gene", Gene.class);
speciesMapping.put("complex", Complex.class);
speciesMapping.put("simple_molecule", SimpleMolecule.class);
speciesMapping.put("ion", Ion.class);
speciesMapping.put("phenotype", Phenotype.class);
speciesMapping.put("drug", Drug.class);
speciesMapping.put("rna", Rna.class);
speciesMapping.put("antisense_rna", AntisenseRna.class);
speciesMapping.put("unknown", Unknown.class);
speciesMapping.put("degraded", Degraded.class);
}
/**
* Object that parses colors from string.
*/
......@@ -56,11 +69,6 @@ public class ColorSchemaReader {
*/
private Logger logger = LogManager.getLogger();
/**
* Objects that manipulates {@link MiriamData}.
*/
private MiriamConnector mc = new MiriamConnector();
/**
* Reads information about set of {@link DataOverlayEntry color schemas} from
* the input stream.
......@@ -196,9 +204,9 @@ public class ColorSchemaReader {
if (typeColumn != null) {
String[] types = values[typeColumn].split(",");
for (String string : types) {
SpeciesMapping mapping = SpeciesMapping.getMappingByString(string);
if (mapping != null) {
schema.addType(mapping.getModelClazz());
Class<? extends BioEntity> clazz = speciesMapping.get(string.toLowerCase());
if (clazz != null) {
schema.addType(clazz);
} else {
throw new InvalidDataOverlayException("[Line " + lineIndex + "] Unknown class type: " + string + ".");
}
......@@ -274,10 +282,10 @@ public class ColorSchemaReader {
private void processGeneralIdentifier(String string, DataOverlayEntry schema, String errorPrefix)
throws InvalidDataOverlayException {
if (mc.isValidIdentifier(string)) {
try {
schema.addMiriamData(MiriamType.getMiriamDataFromIdentifier(string));
} else {
throw new InvalidDataOverlayException(errorPrefix + " Invalid identifier: " + string);
} catch (InvalidArgumentException e) {
throw new InvalidDataOverlayException(errorPrefix + " Invalid identifier: " + string, e);
}
}
......@@ -564,16 +572,13 @@ public class ColorSchemaReader {
String[] types = typesString.split(",");
for (String string : types) {
if (!string.isEmpty()) {
SpeciesMapping mapping = SpeciesMapping.getMappingByString(string);
if (mapping != null) {
result.add(mapping.getModelClazz());
Class<? extends BioEntity> clazz = speciesMapping.get(string.toLowerCase());
if (clazz != null) {
result.add(clazz);
} else {
String validStrings = "";
for (SpeciesMapping speciesMapping : SpeciesMapping.values()) {
validStrings += speciesMapping.getCellDesignerString() + ", ";
}
throw new InvalidDataOverlayException(
errorPrefix + "Unknown class type: " + string + ". Valid values are: " + validStrings);
errorPrefix + "Unknown class type: " + string + ". Valid values are: "
+ StringUtils.join(speciesMapping.values(), ","));
}
}
}
......
......@@ -21,8 +21,7 @@ import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.*;
import lcsb.mapviewer.model.overlay.DataOverlayType;
import lcsb.mapviewer.model.overlay.DataOverlay;
import lcsb.mapviewer.model.overlay.*;
/**
* This class allows to create complex {@link Model} that contains submaps. It's
......@@ -304,9 +303,10 @@ public class ComplexZipConverter {
* @return {@link DataOverlay} for a given {@link LayoutZipEntryFile}
* @throws IOException
* thrown when there is a problem with accessing {@link ZipFile}
* @throws InvalidInputDataExecption
*/
public DataOverlay layoutZipEntryFileToLayout(ComplexZipConverterParams params, ZipFile zipFile, ZipEntry entry,
LayoutZipEntryFile layoutEntry, int order) throws IOException {
LayoutZipEntryFile layoutEntry, int order) throws IOException, InvalidInputDataExecption {
DataOverlay layout = new DataOverlay();
layout.setDescription(layoutEntry.getDescription());
UploadedFileEntry fileEntry = new UploadedFileEntry();
......@@ -329,6 +329,14 @@ public class ComplexZipConverter {
layout.setPublic(true);
layout.setName(layoutEntry.getName());
layout.setOrderIndex(order);
ColorSchemaReader reader = new ColorSchemaReader();
ByteArrayInputStream baos = new ByteArrayInputStream(fileEntry.getFileContent());
try {
layout.addEntries(reader.readColorSchema(baos, parameters));
} catch (InvalidDataOverlayException e) {
throw new InvalidInputDataExecption(e);
}
return layout;
}
......
......@@ -7,7 +7,9 @@ import org.junit.runners.Suite.SuiteClasses;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParserTest;
@RunWith(Suite.class)
@SuiteClasses({ ComplexZipConverterParamsTest.class,
@SuiteClasses({
ColorSchemaReaderTest.class,
ComplexZipConverterParamsTest.class,
ComplexZipConverterTest.class,
OverviewParserTest.class,
ProjectFactoryTest.class,
......
package lcsb.mapviewer.services.utils;
package lcsb.mapviewer.converter;
import static org.junit.Assert.*;
......@@ -12,16 +12,13 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.commands.ColorModelCommand;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.TextFileUtils;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.overlay.*;
import lcsb.mapviewer.services.ServiceTestFunctions;
public class ColorSchemaReaderTest extends ServiceTestFunctions {
public class ColorSchemaReaderTest extends ConverterTestFunctions {
Logger logger = LogManager.getLogger();
ColorSchemaReader reader;
......@@ -37,17 +34,17 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
@Test
public void testReadSchema() throws Exception {
Collection<DataOverlayEntry> schemas = reader.readColorSchema("testFiles/enricoData/ageing.txt");
Collection<DataOverlayEntry> schemas = reader.readColorSchema("testFiles/coloring/ageing.txt");
assertNotNull(schemas);
assertEquals(412, schemas.size());
schemas = reader.readColorSchema("testFiles/enricoData/ge001.txt");
schemas = reader.readColorSchema("testFiles/coloring/ge001.txt");
assertNotNull(schemas);
assertEquals(3057, schemas.size());
schemas = reader.readColorSchema("testFiles/enricoData/ge005.txt");
schemas = reader.readColorSchema("testFiles/coloring/ge005.txt");
assertNotNull(schemas);
assertEquals(4338, schemas.size());
......@@ -174,7 +171,7 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
assertEquals(1, collection.size());
DataOverlayEntry schema = collection.iterator().next();
assertEquals("re1", schema.getElementId());
assertEquals(3.0, schema.getLineWidth(), EPSILON);
assertEquals(3.0, schema.getLineWidth(), Configuration.EPSILON);
assertEquals(Color.RED, schema.getColor());
}
......@@ -186,19 +183,6 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions {
assertEquals(3, schemas.size());
}
@Test
public void testColoring3() throws Exception {
ColorExtractor colorExtractor = new ColorExtractor(Color.RED, Color.GREEN, Color.BLUE, Color.WHITE);
Model model = getModelForFile("testFiles/coloring/protein_to_color.xml", false);
Collection<DataOverlayEntry> schemas = reader.readColorSchema("testFiles/coloring/problematicSchema.txt");
ColorModelCommand factory = new ColorModelCommand(model, schemas, colorExtractor);
factory.execute();
assertFalse(model.getElementByElementId("sa1").getFillColor().equals(Color.WHITE));
}
@Test
public void testColoringWithValueOrColor() throws Exception {
Map<String, String> params = new HashMap<>();
......
......@@ -284,17 +284,18 @@ public class ComplexZipConverterTest extends ConverterTestFunctions {
public void testLayoutZipEntryFileToLayoutOrder() throws Exception {
ComplexZipConverter converter = new ComplexZipConverter(MockConverter.class);
ComplexZipConverterParams params = new ComplexZipConverterParams();
ZipFile file = Mockito.mock(ZipFile.class);
params.zipFile(file);
ZipFile file1 = Mockito.mock(ZipFile.class);
ZipFile file2 = Mockito.mock(ZipFile.class);
LayoutZipEntryFile entry1 = new LayoutZipEntryFile("overlay1.txt", "name", "desc1");
LayoutZipEntryFile entry2 = new LayoutZipEntryFile("overlay2.txt", "name", "desc1");
params.entry(entry1);
params.entry(entry2);
ZipEntry entry = Mockito.mock(ZipEntry.class);
Mockito.when(file.getInputStream(entry)).thenReturn(new ByteArrayInputStream("".getBytes()));
Mockito.when(file1.getInputStream(entry)).thenReturn(new ByteArrayInputStream("name\tvalue\n".getBytes()));
Mockito.when(file2.getInputStream(entry)).thenReturn(new ByteArrayInputStream("name\tvalue\n".getBytes()));
DataOverlay overlay1 = converter.layoutZipEntryFileToLayout(params, file, entry, entry1, 1);
DataOverlay overlay2 = converter.layoutZipEntryFileToLayout(params, file, entry, entry2, 2);
DataOverlay overlay1 = converter.layoutZipEntryFileToLayout(params, file1, entry, entry1, 1);
DataOverlay overlay2 = converter.layoutZipEntryFileToLayout(params, file2, entry, entry2, 2);
assertTrue(overlay1.getOrderIndex() > 0);
assertTrue(overlay2.getOrderIndex() > overlay1.getOrderIndex());
}
......
......@@ -18,8 +18,10 @@ import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.overlay.DataOverlay;
public class ProjectFactoryTest extends ConverterTestFunctions {
Logger logger = LogManager.getLogger();
......@@ -221,4 +223,28 @@ public class ProjectFactoryTest extends ConverterTestFunctions {
return result;
}
@Test
public void testWithOverlay() throws Exception {
ComplexZipConverter converter = new ComplexZipConverter(MockConverter.class);
ProjectFactory projectFactory = new ProjectFactory(converter);
ZipFile zipFile = new ZipFile("testFiles/complex_model_with_layouts.zip");
ComplexZipConverterParams params = new ComplexZipConverterParams();
params.zipFile(zipFile);
ZipEntryFileFactory factory = new ZipEntryFileFactory();
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
params.entry(factory.createZipEntryFile(entry, zipFile));
}
}
Project project = projectFactory.create(params);
assertNotNull(project);
assertEquals(1, project.getDataOverlays().size());
DataOverlay overlay = project.getDataOverlays().get(0);
assertTrue(overlay.getEntries().size() > 0);
}
}
#TYPE=GENETIC_VARIANT
#GENOME_TYPE=UCSC
#GENOME_VERSION=hg38
position original_dna alternative_dna gene_name description color contig
10146 AC A DDX11L1 upstream #ff0000 chr1
10439 AC A DDX11L1;WASH7P upstream;downstream #ff0001 chr1
10583 G A DDX11L1;WASH7P upstream;downstream #ff0002 chr1
10611 C G DDX11L1;WASH7P upstream;downstream #ff0003 chr1
10616 CCGCCGTTGCAAAGGCGCGCCG C DDX11L1;WASH7P upstream;downstream #ff0004 chr1
10904 G A DDX11L1;WASH7P upstream;downstream #ff0005 chr1
12783 G A DDX11L1 intronic #ff0006 chr1
13116 T G DDX11L1 intronic #ff0007 chr1
13118 A G DDX11L1 intronic #ff0008 chr1
13143 G C DDX11L1 intronic #ff0009 chr1
13273 G C DDX11L1 intronic #ff0010 chr1
13302 C T DDX11L1 intronic #ff0011 chr1
13417 C CGAGA DDX11L1 exonic #ff0012 chr1
13550 G A DDX11L1 exonic #ff0013 chr1
13656 CAG C DDX11L1 UTR3 #ff0014 chr1
13668 G A DDX11L1 UTR3 #ff0015 chr1
13813 T G DDX11L1 UTR3 #ff0016 chr1
13838 C T DDX11L1 UTR3 #ff0017 chr1
13868 A G DDX11L1 UTR3 #ff0018 chr1
13896 C A DDX11L1 UTR3 #ff0019 chr1
13957 TC T DDX11L1 UTR3 #ff0020 chr1
14354 C A DDX11L1 UTR3 #ff0021 chr1
14464 A T WASH7P ncRNA_exonic #ff0022 chr1
14653 C T WASH7P ncRNA_exonic #ff0023 chr1
14671 G C WASH7P ncRNA_exonic #ff0024 chr1
14673 G C WASH7P ncRNA_exonic #ff0025 chr1
14677 G A WASH7P ncRNA_exonic #ff0026 chr1
14699 C G WASH7P ncRNA_exonic #ff0027 chr1
14907 A G WASH7P ncRNA_exonic #ff0028 chr1
14930 A G WASH7P ncRNA_exonic #ff0029 chr1
14933 G A WASH7P ncRNA_exonic #ff0030 chr1
14976 G A WASH7P ncRNA_exonic #ff0031 chr1
15118 A G WASH7P ncRNA_exonic #ff0032 chr1
15190 G A WASH7P ncRNA_exonic #ff0033 chr1
15211 T G WASH7P ncRNA_exonic #ff0034 chr1
15274 A G,T WASH7P ncRNA_exonic #ff0035 chr1
15447 A G WASH7P ncRNA_exonic #ff0036 chr1
15688 C T WASH7P ncRNA_exonic #ff0037 chr1
15820 G T WASH7P ncRNA_exonic #ff0038 chr1
15903 G GC WASH7P ncRNA_exonic #ff0039 chr1
16014 C T WASH7P ncRNA_exonic #ff0040 chr1
16068 T C WASH7P ncRNA_exonic #ff0041 chr1
16103 T G WASH7P ncRNA_exonic #ff0042 chr1
16206 T A WASH7P ncRNA_exonic #ff0043 chr1
16226 AG A WASH7P ncRNA_exonic #ff0044 chr1
16257 G C WASH7P ncRNA_exonic #ff0045 chr1
16288 C G WASH7P ncRNA_exonic #ff0046 chr1
16298 C T WASH7P ncRNA_exonic #ff0047 chr1
16378 T C WASH7P ncRNA_exonic #ff0048 chr1
16487 T C WASH7P ncRNA_exonic #ff0049 chr1
16495 G C WASH7P ncRNA_exonic #ff0050 chr1
16497 A G WASH7P ncRNA_exonic #ff0051 chr1
16534 C T WASH7P ncRNA_exonic #ff0052 chr1
16571 G A WASH7P ncRNA_exonic #ff0053 chr1
16682 G A WASH7P ncRNA_exonic #ff0054 chr1
16688 G A WASH7P ncRNA_exonic #ff0055 chr1
16719 T A WASH7P ncRNA_exonic #ff0056 chr1
16737 G T WASH7P ncRNA_exonic #ff0057 chr1
16742 G C WASH7P ncRNA_exonic #ff0058 chr1
16809 C G WASH7P ncRNA_intronic #ff0059 chr1
16841 G T WASH7P ncRNA_intronic #ff0060 chr1
16949 A C WASH7P ncRNA_exonic #ff0061 chr1
16963 G A WASH7P ncRNA_exonic #ff0062 chr1
16977 G A WASH7P ncRNA_exonic #ff0063 chr1
17020 G A WASH7P ncRNA_exonic #ff0064 chr1
17222 A G WASH7P ncRNA_intronic #ff0065 chr1
17385 G A MIR6859-1,MIR6859-2,MIR6859-3,MIR6859-4 ncRNA_exonic #ff0066 chr1
17408 C G MIR6859-1,MIR6859-2,MIR6859-3,MIR6859-4 ncRNA_exonic #ff0067 chr1
17538 C A WASH7P ncRNA_exonic #ff0068 chr1
17594 C T WASH7P ncRNA_exonic #ff0069 chr1
17614 G A WASH7P ncRNA_exonic #ff0070 chr1
17697 G C WASH7P ncRNA_exonic #ff0071 chr1
17730 C A WASH7P ncRNA_exonic #ff0072 chr1
17746 A G WASH7P ncRNA_exonic;splicing #ff0073 chr1
17765 G A WASH7P ncRNA_exonic #ff0074 chr1
17961 TG T WASH7P ncRNA_exonic #ff0075 chr1
19004 A G WASH7P ncRNA_exonic #ff0076 chr1
19322 C T WASH7P ncRNA_exonic #ff0077 chr1
19583 A G WASH7P ncRNA_exonic #ff0078 chr1
19592 T C WASH7P ncRNA_exonic #ff0079 chr1
19600 A T WASH7P ncRNA_exonic #ff0080 chr1
19604 T C WASH7P ncRNA_exonic #ff0081 chr1
19776 A G WASH7P ncRNA_intronic #ff0082 chr1
19788 C T WASH7P ncRNA_intronic #ff0083 chr1
19858 C T WASH7P ncRNA_intronic #ff0084 chr1
19942 G C WASH7P ncRNA_intronic #ff0085 chr1
20094 TAA T WASH7P ncRNA_intronic #ff0086 chr1
20098 CAG C WASH7P ncRNA_intronic #ff0087 chr1
20129 C T WASH7P ncRNA_intronic #ff0088 chr1
20136 T C WASH7P ncRNA_intronic #ff0089 chr1
20144 G A WASH7P ncRNA_intronic #ff0090 chr1
20191 T G WASH7P ncRNA_intronic #ff0091 chr1
20206 C T WASH7P ncRNA_intronic #ff0092 chr1
20207 G A WASH7P ncRNA_intronic #ff0093 chr1
20212 A G WASH7P ncRNA_intronic #ff0094 chr1
20227 T A WASH7P ncRNA_intronic #ff0095 chr1
20235 G A WASH7P ncRNA_intronic #ff0096 chr1
20245 G A WASH7P ncRNA_intronic #ff0097 chr1
20250 T C WASH7P ncRNA_intronic #ff0098 chr1
#TYPE=GENETIC_VARIANT
#GENOME_TYPE=UCSC
#GENOME_VERSION=hg38
position original_dna alternative_dna gene_name description color contig allele_frequency variant_identifier amino_acid_change
10146 AC A DDX11L1 upstream #ff0000 chr1 0.8 identifier_1 LRRK2:NM_198578:exon1:c.T45C:p.T15T
10439 AC A DDX11L1;WASH7P upstream;downstream #ff0001 chr1 0.5 identifier_2 LRRK2:NM_198578:exon1:c.C67T:p.L23L
10441 AC A DDX11L1;WASH7P upstream;downstream #ff0001 chr1 0.2 identifier_3 frameshift_insertion
10443 AC A DDX11L1;WASH7P upstream;downstream #ff0001 chr1 0.9 identifier_4
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment