From 5d252147ecc48dd4d80dcd4630c3409ad8bc3bb5 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 6 Jun 2019 20:03:50 +0200 Subject: [PATCH] genetic variant overlay without name caused problems --- CHANGELOG | 1 + .../services/utils/ColorSchemaReader.java | 2 +- .../services/utils/ColorSchemaReaderTest.java | 97 ++++++++----------- .../testFiles/coloring/gene_variants_id.txt | 5 + 4 files changed, 48 insertions(+), 57 deletions(-) create mode 100644 service/testFiles/coloring/gene_variants_id.txt diff --git a/CHANGELOG b/CHANGELOG index 90f4e97461..71510373a8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ minerva (12.3.1~beta.1) unstable; urgency=low * Bug fix: invalid color in data overlay provides proper feedback to the user (#822) + * Bug fix: genetic variant overlay without name caused problems (#832) * Bug fix: tair locus identifiers were used improperly - instead of id the name was used * Bug fix: plugin tab header wasn't properly resized after adding plugins diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java index 87b27aa822..93f0517170 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java @@ -292,7 +292,7 @@ public class ColorSchemaReader { gv.setContig(values[contigColumn]); schema.addGeneVariation(gv); - if (schema.getName().contains(";")) { + if (schema.getName()!=null && schema.getName().contains(";")) { String[] names = schema.getName().split(";"); for (String string : names) { if (!string.trim().isEmpty()) { diff --git a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java index 20d037fa24..119fb25312 100644 --- a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java @@ -11,6 +11,8 @@ import java.awt.Color; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Collection; @@ -75,21 +77,27 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { public void testReadGeneVariantsSchema() throws Exception { try { File f = new File("testFiles/coloring/gene_variants.txt"); - InputStream in = new FileInputStream(f); + byte[] data = fileToByteArray(f); - byte[] buff = new byte[8000]; - - int bytesRead = 0; + ByteArrayInputStream bin = new ByteArrayInputStream(data); - ByteArrayOutputStream bao = new ByteArrayOutputStream(); + ColorSchemaReader reader = new ColorSchemaReader(); - while ((bytesRead = in.read(buff)) != -1) { - bao.write(buff, 0, bytesRead); - } - in.close(); - bao.close(); + Collection<ColorSchema> schemas = reader.readColorSchema(bin, + TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); + assertNotNull(schemas); + assertEquals(3, schemas.size()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } - byte[] data = bao.toByteArray(); + @Test + public void testReadGeneVariantByIdSchema() throws Exception { + try { + File f = new File("testFiles/coloring/gene_variants_id.txt"); + byte[] data = fileToByteArray(f); ByteArrayInputStream bin = new ByteArrayInputStream(data); @@ -98,32 +106,37 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { Collection<ColorSchema> schemas = reader.readColorSchema(bin, TextFileUtils.getHeaderParametersFromFile(new ByteArrayInputStream(data))); assertNotNull(schemas); - assertEquals(3, schemas.size()); + assertEquals(1, schemas.size()); } catch (Exception e) { e.printStackTrace(); throw e; } } - @Test - public void testReadGeneVariantsWithAminoAcidChange() throws Exception { - try { - File f = new File("testFiles/coloring/gene_variants_aa_change.txt"); - InputStream in = new FileInputStream(f); + private byte[] fileToByteArray(File f) throws FileNotFoundException, IOException { + InputStream in = new FileInputStream(f); - byte[] buff = new byte[8000]; + byte[] buff = new byte[8000]; - int bytesRead = 0; + int bytesRead = 0; - ByteArrayOutputStream bao = new ByteArrayOutputStream(); + ByteArrayOutputStream bao = new ByteArrayOutputStream(); - while ((bytesRead = in.read(buff)) != -1) { - bao.write(buff, 0, bytesRead); - } - in.close(); - bao.close(); + while ((bytesRead = in.read(buff)) != -1) { + bao.write(buff, 0, bytesRead); + } + in.close(); + bao.close(); - byte[] data = bao.toByteArray(); + byte[] data = bao.toByteArray(); + return data; + } + + @Test + public void testReadGeneVariantsWithAminoAcidChange() throws Exception { + try { + File f = new File("testFiles/coloring/gene_variants_aa_change.txt"); + byte[] data = fileToByteArray(f); ByteArrayInputStream bin = new ByteArrayInputStream(data); @@ -151,21 +164,7 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { public void testReadGeneVariantsWithNewNamingSchema() throws Exception { try { File f = new File("testFiles/coloring/gene_variants_new_naming.txt"); - InputStream in = new FileInputStream(f); - - byte[] buff = new byte[8000]; - - int bytesRead = 0; - - ByteArrayOutputStream bao = new ByteArrayOutputStream(); - - while ((bytesRead = in.read(buff)) != -1) { - bao.write(buff, 0, bytesRead); - } - in.close(); - bao.close(); - - byte[] data = bao.toByteArray(); + byte[] data = fileToByteArray(f); ByteArrayInputStream bin = new ByteArrayInputStream(data); @@ -185,21 +184,7 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { public void testReadGeneVariantsSchemaWithAF() throws Exception { try { File f = new File("testFiles/coloring/gene_variants_all_freq.txt"); - InputStream in = new FileInputStream(f); - - byte[] buff = new byte[8000]; - - int bytesRead = 0; - - ByteArrayOutputStream bao = new ByteArrayOutputStream(); - - while ((bytesRead = in.read(buff)) != -1) { - bao.write(buff, 0, bytesRead); - } - in.close(); - bao.close(); - - byte[] data = bao.toByteArray(); + byte[] data = fileToByteArray(f); ByteArrayInputStream bin = new ByteArrayInputStream(data); diff --git a/service/testFiles/coloring/gene_variants_id.txt b/service/testFiles/coloring/gene_variants_id.txt new file mode 100644 index 0000000000..d2ee602490 --- /dev/null +++ b/service/testFiles/coloring/gene_variants_id.txt @@ -0,0 +1,5 @@ +#TYPE=GENETIC_VARIANT +#GENOME_TYPE=UCSC +#GENOME_VERSION=hg38 +position original_dna alternative_dna Entrez gene description color contig +10146 AC A 123456 upstream #ff0000 chr1 -- GitLab