diff --git a/CHANGELOG b/CHANGELOG index 65feb96cf5847fa3eed9083aca002a0cca29b794..afc764e05f4afcace272e865ab2b977fe6f4db04 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -14,6 +14,8 @@ minerva (12.3.0~alpha.0) unstable; urgency=low uploaded (#683) * Small improvement: warning about capslock is visible on login page when necessary (#658) + * Small improvement: names of columns in data overlay are unified: no + whitespace, "_" used as separator (#596) * Bug fix: progress bar of gene genome mapping upload is refreshing properly (#728) diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java index 94223e27eb3e281ff83487916aa5a7d4bbb967a8..bdbd459409350dc2ecd9a60123d0489aa23fa4cf 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java @@ -584,7 +584,7 @@ public class LayoutService implements ILayoutService { for (ColorSchemaColumn column : ColorSchemaColumn.values()) { if (columns.contains(column)) { - sb.append(column.getTitle() + "\t"); + sb.append(column.getColumnName() + "\t"); } } sb.append("matches<br/>\n"); 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 4d54c42bc2dfffad14f17ae1198a8d3fde35a077..b2085821ea21ee251891e3e1cb978229ae6d7e22 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java @@ -152,8 +152,8 @@ public class ColorSchemaReader { String[] columns = line.split("\t"); Map<ColorSchemaColumn, Integer> schemaColumns = new HashMap<>(); - List<Pair<MiriamType, Integer>> customIdentifiers = new ArrayList<>(); - parseColumns(columns, schemaColumns, customIdentifiers, ColorSchemaType.GENETIC_VARIANT); + List<Pair<MiriamType, Integer>> customIdentifiers = parseColumns(columns, schemaColumns, + ColorSchemaType.GENETIC_VARIANT); Integer colorColumn = schemaColumns.get(ColorSchemaColumn.COLOR); Integer contigColumn = schemaColumns.get(ColorSchemaColumn.CONTIG); if (contigColumn == null) { @@ -181,21 +181,21 @@ public class ColorSchemaReader { throw new InvalidColorSchemaException("One of these columns is obligatory: name, identifier"); } if (contigColumn == null) { - throw new InvalidColorSchemaException(ColorSchemaColumn.CONTIG.getTitle() + " column is obligatory"); + throw new InvalidColorSchemaException(ColorSchemaColumn.CONTIG.getColumnName() + " column is obligatory"); } if (positionColumn == null) { - throw new InvalidColorSchemaException(ColorSchemaColumn.POSITION.getTitle() + " column is obligatory"); + throw new InvalidColorSchemaException(ColorSchemaColumn.POSITION.getColumnName() + " column is obligatory"); } if (originalDnaColumn == null) { - throw new InvalidColorSchemaException(ColorSchemaColumn.ORIGINAL_DNA.getTitle() + " column is obligatory"); + throw new InvalidColorSchemaException(ColorSchemaColumn.ORIGINAL_DNA.getColumnName() + " column is obligatory"); } if (referenceGenomeTypeColumn == null && genomeType == null) { throw new InvalidColorSchemaException( - ColorSchemaColumn.REFERENCE_GENOME_TYPE.getTitle() + " column is obligatory"); + ColorSchemaColumn.REFERENCE_GENOME_TYPE.getColumnName() + " column is obligatory"); } if (referenceGenomeVersionColumn == null && referenceGenomeVersionStr == null) { throw new InvalidColorSchemaException( - ColorSchemaColumn.REFERENCE_GENOME_VERSION.getTitle() + " column is obligatory"); + ColorSchemaColumn.REFERENCE_GENOME_VERSION.getColumnName() + " column is obligatory"); } lineIndex++; line = br.readLine(); @@ -481,8 +481,7 @@ public class ColorSchemaReader { String[] columns = line.split("\t"); Map<ColorSchemaColumn, Integer> schemaColumns = new HashMap<>(); - List<Pair<MiriamType, Integer>> customIdentifiers = new ArrayList<>(); - parseColumns(columns, schemaColumns, customIdentifiers, ColorSchemaType.GENERIC); + List<Pair<MiriamType, Integer>> customIdentifiers = parseColumns(columns, schemaColumns, ColorSchemaType.GENERIC); Integer valueColumn = schemaColumns.get(ColorSchemaColumn.VALUE); Integer colorColumn = schemaColumns.get(ColorSchemaColumn.COLOR); @@ -501,8 +500,10 @@ public class ColorSchemaReader { if (nameColumn == null && identifierColumn == null && customIdentifiers.size() == 0 && elementIdentifierColumn == null) { - throw new InvalidColorSchemaException("One of these columns is obligatory: " + ColorSchemaColumn.NAME.getTitle() - + "," + ColorSchemaColumn.IDENTIFIER.getTitle() + "," + ColorSchemaColumn.ELEMENT_IDENTIFIER.getTitle()); + throw new InvalidColorSchemaException( + "One of these columns is obligatory: " + ColorSchemaColumn.NAME.getColumnName() + + "," + ColorSchemaColumn.IDENTIFIER.getColumnName() + "," + + ColorSchemaColumn.ELEMENT_IDENTIFIER.getColumnName()); } if (valueColumn == null && colorColumn == null) { @@ -678,29 +679,36 @@ public class ColorSchemaReader { * @throws InvalidColorSchemaException * thrown when the list of column headers contain invalid value */ - public void parseColumns(String[] columns, Map<ColorSchemaColumn, Integer> schemaColumns, - List<Pair<MiriamType, Integer>> customIdentifiers, ColorSchemaType type) throws InvalidColorSchemaException { - Map<String, MiriamType> acceptableIdentifiers = new HashMap<String, MiriamType>(); + public List<Pair<MiriamType, Integer>> parseColumns(String[] columns, Map<ColorSchemaColumn, Integer> schemaColumns, + ColorSchemaType type) throws InvalidColorSchemaException { + List<Pair<MiriamType, Integer>> result = new ArrayList<>(); + Map<String, MiriamType> acceptableIdentifiers = new HashMap<>(); + Map<String, MiriamType> deprecatedIdentifiers = new HashMap<>(); for (MiriamType miriamType : MiriamType.values()) { - acceptableIdentifiers.put(miriamType.getCommonName().toLowerCase(), miriamType); + acceptableIdentifiers.put("identifier_" + miriamType.name().toLowerCase(), miriamType); + deprecatedIdentifiers.put(miriamType.getCommonName().toLowerCase(), miriamType); } for (int i = 0; i < columns.length; i++) { boolean found = false; for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { - if (columns[i].trim().equalsIgnoreCase(schemaColumn.getTitle()) && schemaColumn.getTypes().contains(type)) { + if ((columns[i].trim().equalsIgnoreCase(schemaColumn.getColumnName()) || + columns[i].trim().equalsIgnoreCase(schemaColumn.getDepractedColumnName())) + && schemaColumn.getTypes().contains(type)) { schemaColumns.put(schemaColumn, i); found = true; } } if (!found) { if (acceptableIdentifiers.keySet().contains(columns[i].toLowerCase())) { - customIdentifiers.add(new Pair<>(acceptableIdentifiers.get(columns[i].toLowerCase()), i)); + result.add(new Pair<>(acceptableIdentifiers.get(columns[i].toLowerCase()), i)); + } else if (deprecatedIdentifiers.keySet().contains(columns[i].toLowerCase())) { + result.add(new Pair<>(deprecatedIdentifiers.get(columns[i].toLowerCase()), i)); } else { String columnNames = ""; for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { if (schemaColumn.getTypes().contains(type)) { - columnNames += schemaColumn.getTitle() + ", "; + columnNames += schemaColumn.getColumnName() + ", "; } } for (String string : acceptableIdentifiers.keySet()) { @@ -711,6 +719,7 @@ public class ColorSchemaReader { } } } + return result; } /** diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaXlsxReader.java b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaXlsxReader.java index 4948d346f2a2a595d3efb3947048a4d9bc219c64..1437bd37958dfe69f61f9d6886aae3127730de7e 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaXlsxReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaXlsxReader.java @@ -130,7 +130,7 @@ public class ColorSchemaXlsxReader { String value = cell.getStringCellValue(); boolean found = false; for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { - if (value.trim().equalsIgnoreCase(schemaColumn.getTitle())) { + if (value.trim().equalsIgnoreCase(schemaColumn.getDepractedColumnName()) || value.trim().equalsIgnoreCase(schemaColumn.getColumnName())) { foundSchemaColumns.put(schemaColumn, columnIndex - 1); found = true; break; @@ -143,7 +143,7 @@ public class ColorSchemaXlsxReader { } else { String columnNames = ""; for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { - columnNames += schemaColumn.getTitle() + ", "; + columnNames += schemaColumn.getColumnName() + ", "; } for (String string : acceptableIdentifiers.keySet()) { columnNames += ", " + string; @@ -174,8 +174,8 @@ public class ColorSchemaXlsxReader { if (nameColumn == null && identifierColumn == null && foundCustomIdentifiers.size() == 0 && elementIdentifierColumn == null) { throw new InvalidColorSchemaException( - "One of these columns is obligatory: " + ColorSchemaColumn.NAME.getTitle() + "," - + ColorSchemaColumn.IDENTIFIER.getTitle() + "," + ColorSchemaColumn.ELEMENT_IDENTIFIER.getTitle()); + "One of these columns is obligatory: " + ColorSchemaColumn.NAME.getColumnName() + "," + + ColorSchemaColumn.IDENTIFIER.getColumnName() + "," + ColorSchemaColumn.ELEMENT_IDENTIFIER.getColumnName()); } if (valueColumn == null && colorColumn == null) { diff --git a/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java b/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java index 838eeda5fee327c79a855b7cc0138f1e5601c9d1..8fd9276dfe5579067dca98d62c7c731ece156f82 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/data/ColorSchemaColumn.java @@ -19,41 +19,41 @@ public enum ColorSchemaColumn { /** * Name of the element. */ - NAME("name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), + NAME(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), - GENE_NAME("gene_name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), + GENE_NAME(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), /** * Name of the element. */ - MODEL_NAME("model_name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), + MODEL_NAME(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), /** * Value that will be transformed into new color. * * @see ColorSchemaColumn#COLOR */ - VALUE("value", new ColorSchemaType[] { ColorSchemaType.GENERIC }), + VALUE(new ColorSchemaType[] { ColorSchemaType.GENERIC }), /** * In which compartment the element should be located. */ - COMPARTMENT("compartment", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), + COMPARTMENT(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), /** * Class type of the element. */ - TYPE("type", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), + TYPE(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), /** * New element/reaction color. */ - COLOR("color", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), + COLOR(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), /** * Identifier of the element. */ - IDENTIFIER("identifier", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), + IDENTIFIER(new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), /** * Element identifier. @@ -74,69 +74,85 @@ public enum ColorSchemaColumn { /** * Position where gene variants starts. */ - POSITION("position", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + POSITION(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), /** * Original DNA of the variant. */ - ORIGINAL_DNA("original_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + ORIGINAL_DNA(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), /** * Alternative DNA of the variant. */ - ALTERNATIVE_DNA("alternative_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + ALTERNATIVE_DNA(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), /** * Short description of the entry. */ - DESCRIPTION("description", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), + DESCRIPTION(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), /** * Variant references. */ - REFERENCES("references", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + REFERENCES(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), /** * What's the {@link ReferenceGenomeType}. */ - REFERENCE_GENOME_TYPE("reference_genome_type", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + REFERENCE_GENOME_TYPE(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), /** * {@link ReferenceGenome#version Version} of the reference genome. */ - REFERENCE_GENOME_VERSION("reference_genome_version", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + REFERENCE_GENOME_VERSION(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), /** * Contig where variant was observed. */ - CONTIG("contig", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + CONTIG(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), - CHROMOSOME("chromosome", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + CHROMOSOME(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), ALLEL_FREQUENCY("allele_frequency", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), - VARIANT_IDENTIFIER("variant_identifier", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), + VARIANT_IDENTIFIER(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), /** * Should the direction of reaction be reversed. */ REVERSE_REACTION("reverseReaction", new ColorSchemaType[] { ColorSchemaType.GENERIC }), - + /** - * Optional amino acid change in the variant. + * Optional amino acid change in the variant. */ - AMINO_ACID_CHANGE("amino_acid_change", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }); + AMINO_ACID_CHANGE(new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }); + + /** + * Constructor that creates enum entry with deprecated column name. + * + * @param deprecatedColumnName + * {@link #deprecatedColumnName} + * @param types + * list of {@link ColorSchemaType types} where this column is allowed + * @deprecated As of release 12.3, replaced by {@link #ColorSchemaColumn(ColorSchemaType[])} + */ + @Deprecated + ColorSchemaColumn(String deprecatedColumnName, ColorSchemaType[] types) { + this.deprecatedColumnName = deprecatedColumnName; + for (ColorSchemaType colorSchemaType : types) { + this.types.add(colorSchemaType); + } + } /** * Default constructor that creates enum entry. * - * @param title - * {@link #title} + * @param deprecatedColumnName + * {@link #deprecatedColumnName} * @param types * list of {@link ColorSchemaType types} where this column is allowed */ - ColorSchemaColumn(String title, ColorSchemaType[] types) { - this.title = title; + ColorSchemaColumn(ColorSchemaType[] types) { for (ColorSchemaType colorSchemaType : types) { this.types.add(colorSchemaType); } @@ -145,7 +161,7 @@ public enum ColorSchemaColumn { /** * Human readable title used in input file. */ - private String title; + private String deprecatedColumnName; /** * Set of types where column is allowed. @@ -154,10 +170,16 @@ public enum ColorSchemaColumn { /** * - * @return {@link #title} + * @return {@link #deprecatedColumnName} + * @deprecated As of release 12.3, replaced by {@link #getColumnName()} */ - public String getTitle() { - return title; + @Deprecated + public String getDepractedColumnName() { + return deprecatedColumnName; + } + + public String getColumnName() { + return this.name().toLowerCase(); } /** 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 3a7d0ace0e306e47159b352a695b7d3731a161f5..8f38ead287c120fe84ebf7d78c168c6328a9d200 100644 --- a/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java +++ b/service/src/test/java/lcsb/mapviewer/services/utils/ColorSchemaReaderTest.java @@ -412,6 +412,25 @@ public class ColorSchemaReaderTest extends ServiceTestFunctions { } } + @Test + public void testSchemasWithIdSnakeCase() throws Exception { + try { + ColorSchemaReader reader = new ColorSchemaReader(); + + Collection<ColorSchema> schemas = reader.readColorSchema("testFiles/coloring/schema_with_identifiers_in_snake_case.txt"); + for (ColorSchema colorSchema : schemas) { + for (MiriamData md : colorSchema.getMiriamData()) { + assertNotNull(md.getResource()); + assertFalse(md.getResource().isEmpty()); + } + } + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + @Test public void testSchemasWithEmptyNameAndId() throws Exception { try { diff --git a/service/testFiles/coloring/schema_with_identifiers_in_snake_case.txt b/service/testFiles/coloring/schema_with_identifiers_in_snake_case.txt new file mode 100644 index 0000000000000000000000000000000000000000..dc57ab28b2411e1b78a435c753acbc9f2de7f25e --- /dev/null +++ b/service/testFiles/coloring/schema_with_identifiers_in_snake_case.txt @@ -0,0 +1,4 @@ +name identifier_Entrez identifier_Chebi identifier_go value + 120892 1 + CHEBI:26523 1 + GO:0036489 1