From 4b63adc8035eac3e507a52dd08eee8f2ffe56ce5 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 25 Jan 2018 13:42:58 +0100 Subject: [PATCH] allow user to upload overlay and filter by model_name --- .../services/impl/LayoutService.java | 4 + .../services/utils/ColorSchemaReader.java | 17 + .../services/utils/ColorSchemaXlsxReader.java | 549 +++++++++--------- .../utils/data/ColorSchemaColumn.java | 268 ++++----- 4 files changed, 440 insertions(+), 398 deletions(-) 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 4104e98609..3e56dd04c2 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java @@ -792,6 +792,8 @@ public class LayoutService implements ILayoutService { sb.append("\t"); } else if (column.equals(ColorSchemaColumn.NAME)) { sb.append(schema.getName() + "\t"); + } else if (column.equals(ColorSchemaColumn.MODEL_NAME)) { + sb.append(schema.getModelName() + "\t"); } else if (column.equals(ColorSchemaColumn.VALUE)) { sb.append(schema.getValue() + "\t"); } else if (column.equals(ColorSchemaColumn.COMPARTMENT)) { @@ -847,6 +849,8 @@ public class LayoutService implements ILayoutService { sb.append("\t"); } else if (column.equals(ColorSchemaColumn.NAME)) { sb.append(schema.getName() + "\t"); + } else if (column.equals(ColorSchemaColumn.MODEL_NAME)) { + sb.append(schema.getModelName() + "\t"); } else if (column.equals(ColorSchemaColumn.VALUE)) { sb.append(schema.getValue() + "\t"); } else if (column.equals(ColorSchemaColumn.COMPARTMENT)) { 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 2f358661b2..0176a0da7e 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaReader.java @@ -157,6 +157,7 @@ public class ColorSchemaReader { Integer colorColumn = schemaColumns.get(ColorSchemaColumn.COLOR); Integer contigColumn = schemaColumns.get(ColorSchemaColumn.CONTIG); Integer nameColumn = schemaColumns.get(ColorSchemaColumn.NAME); + Integer modelNameColumn = schemaColumns.get(ColorSchemaColumn.MODEL_NAME); Integer identifierColumn = schemaColumns.get(ColorSchemaColumn.IDENTIFIER); Integer variantIdentifierColumn = schemaColumns.get(ColorSchemaColumn.VARIANT_IDENTIFIER); Integer allelFrequencyColumn = schemaColumns.get(ColorSchemaColumn.ALLEL_FREQUENCY); @@ -202,6 +203,9 @@ public class ColorSchemaReader { if (nameColumn != null) { processNameColumn(schema, values[nameColumn]); } + if (modelNameColumn != null) { + processModelNameColumn(schema, values[modelNameColumn]); + } if (compartmentColumn != null) { processCompartmentColumn(schema, values[compartmentColumn]); } @@ -328,6 +332,12 @@ public class ColorSchemaReader { schema.setName(content); } } + private void processModelNameColumn(ColorSchema schema, String content) { + if (!content.isEmpty()) { + schema.setModelName(content); + } + } + /** * Sets proper compartment names to {@link ColorSchema} from cell content. @@ -463,6 +473,7 @@ public class ColorSchemaReader { Integer valueColumn = schemaColumns.get(ColorSchemaColumn.VALUE); Integer colorColumn = schemaColumns.get(ColorSchemaColumn.COLOR); Integer nameColumn = schemaColumns.get(ColorSchemaColumn.NAME); + Integer modelNameColumn = schemaColumns.get(ColorSchemaColumn.MODEL_NAME); Integer identifierColumn = schemaColumns.get(ColorSchemaColumn.IDENTIFIER); Integer reactionIdentifierColumn = schemaColumns.get(ColorSchemaColumn.REACTION_IDENTIFIER); Integer compartmentColumn = schemaColumns.get(ColorSchemaColumn.COMPARTMENT); @@ -499,6 +510,9 @@ public class ColorSchemaReader { if (nameColumn != null) { processNameColumn(schema, values[nameColumn]); } + if (modelNameColumn != null) { + processModelNameColumn(schema, values[modelNameColumn]); + } if (valueColumn != null) { schema.setValue(parseValueColumn(values[valueColumn], errorPrefix)); } @@ -729,6 +743,9 @@ public class ColorSchemaReader { if (schema.getName() != null) { result.add(ColorSchemaColumn.NAME); } + if (schema.getModelName() != null) { + result.add(ColorSchemaColumn.MODEL_NAME); + } if (schema.getReactionIdentifier() != null) { result.add(ColorSchemaColumn.REACTION_IDENTIFIER); } 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 f852f697bc..be39f1a333 100644 --- a/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaXlsxReader.java +++ b/service/src/main/java/lcsb/mapviewer/services/utils/ColorSchemaXlsxReader.java @@ -41,285 +41,302 @@ import lcsb.mapviewer.services.utils.data.ColorSchemaColumn; * */ public class ColorSchemaXlsxReader { - /** - * Default class logger. - */ - @SuppressWarnings("unused") - private Logger logger = Logger.getLogger(ColorSchemaXlsxReader.class); + /** + * Default class logger. + */ + @SuppressWarnings("unused") + private Logger logger = Logger.getLogger(ColorSchemaXlsxReader.class); - /** - * @param fileName - * file name - * @param sheetName - * sheet name. - * @return list of ColorSchema. - * @throws IOException - * exception related to opening the input stream. - * @throws InvalidColorSchemaException - * invalid color schema exception. - */ - public Collection<ColorSchema> readColorSchema(String fileName, String sheetName) throws IOException, InvalidColorSchemaException { - ColorParser colorParser = new ColorParser(); - List<ColorSchema> result = new ArrayList<>(); - FileInputStream file = null; - Workbook workbook = null; + /** + * @param fileName + * file name + * @param sheetName + * sheet name. + * @return list of ColorSchema. + * @throws IOException + * exception related to opening the input stream. + * @throws InvalidColorSchemaException + * invalid color schema exception. + */ + public Collection<ColorSchema> readColorSchema(String fileName, String sheetName) + throws IOException, InvalidColorSchemaException { + ColorParser colorParser = new ColorParser(); + List<ColorSchema> result = new ArrayList<>(); + FileInputStream file = null; + Workbook workbook = null; - try { - file = new FileInputStream(fileName); - // Using XSSF for xlsx format, for xls use HSSF - // <-Interface, accepts both HSSF and XSSF. - if (FilenameUtils.getExtension(fileName).equalsIgnoreCase("xls")) { - workbook = new HSSFWorkbook(file); - } else if (FilenameUtils.getExtension(fileName).equalsIgnoreCase("xlsx")) { - workbook = new XSSFWorkbook(file); - } else { - throw new IllegalArgumentException("Received file does not have a standard excel extension."); - } - Sheet sheet = null; - if (sheetName == null) { - sheet = workbook.getSheetAt(0); - } else { - sheet = workbook.getSheet(sheetName); - } - DataFormat fmt = workbook.createDataFormat(); - CellStyle textStyle = workbook.createCellStyle(); - textStyle.setDataFormat(fmt.getFormat("@")); + try { + file = new FileInputStream(fileName); + // Using XSSF for xlsx format, for xls use HSSF + // <-Interface, accepts both HSSF and XSSF. + if (FilenameUtils.getExtension(fileName).equalsIgnoreCase("xls")) { + workbook = new HSSFWorkbook(file); + } else if (FilenameUtils.getExtension(fileName).equalsIgnoreCase("xlsx")) { + workbook = new XSSFWorkbook(file); + } else { + throw new IllegalArgumentException("Received file does not have a standard excel extension."); + } + Sheet sheet = null; + if (sheetName == null) { + sheet = workbook.getSheetAt(0); + } else { + sheet = workbook.getSheet(sheetName); + } + DataFormat fmt = workbook.createDataFormat(); + CellStyle textStyle = workbook.createCellStyle(); + textStyle.setDataFormat(fmt.getFormat("@")); - Iterator<Row> rowIterator = sheet.iterator(); - Integer valueColumn = null; - Integer colorColumn = null; - Integer nameColumn = null; - Integer identifierColumn = null; - Integer reactionIdentifierColumn = null; - Integer compartmentColumn = null; - Integer typeColumn = null; - Integer lineWidthColumn = null; - Integer reverseReactionColumn = null; - List<Pair<MiriamType, Integer>> foundCustomIdentifiers = new ArrayList<Pair<MiriamType, Integer>>(); - int lineIndex = 0; - Map<ColorSchemaColumn, Integer> foundSchemaColumns = new HashMap<ColorSchemaColumn, Integer>(); - while (rowIterator.hasNext()) { - Row row = rowIterator.next(); - Cell cell = row.getCell(0, Row.RETURN_BLANK_AS_NULL); - if (cell == null) { - continue; - } else { - cell.setCellType(Cell.CELL_TYPE_STRING); - if (cell.getStringCellValue().startsWith("#")) { - continue; - } - } - lineIndex++; - if (lineIndex == 1) { + Iterator<Row> rowIterator = sheet.iterator(); + Integer valueColumn = null; + Integer colorColumn = null; + Integer nameColumn = null; + Integer modelNameColumn = null; + Integer identifierColumn = null; + Integer reactionIdentifierColumn = null; + Integer compartmentColumn = null; + Integer typeColumn = null; + Integer lineWidthColumn = null; + Integer reverseReactionColumn = null; + List<Pair<MiriamType, Integer>> foundCustomIdentifiers = new ArrayList<Pair<MiriamType, Integer>>(); + int lineIndex = 0; + Map<ColorSchemaColumn, Integer> foundSchemaColumns = new HashMap<ColorSchemaColumn, Integer>(); + while (rowIterator.hasNext()) { + Row row = rowIterator.next(); + Cell cell = row.getCell(0, Row.RETURN_BLANK_AS_NULL); + if (cell == null) { + continue; + } else { + cell.setCellType(Cell.CELL_TYPE_STRING); + if (cell.getStringCellValue().startsWith("#")) { + continue; + } + } + lineIndex++; + if (lineIndex == 1) { - Map<String, MiriamType> acceptableIdentifiers = new HashMap<String, MiriamType>(); - for (MiriamType type : MiriamType.values()) { - acceptableIdentifiers.put(type.getCommonName().toLowerCase(), type); - } + Map<String, MiriamType> acceptableIdentifiers = new HashMap<String, MiriamType>(); + for (MiriamType type : MiriamType.values()) { + acceptableIdentifiers.put(type.getCommonName().toLowerCase(), type); + } - Iterator<Cell> cellIterator = row.cellIterator(); - int columnIndex = 0; - while (cellIterator.hasNext()) { - columnIndex++; - sheet.setDefaultColumnStyle(columnIndex, textStyle); - cell = cellIterator.next(); - cell.setCellType(Cell.CELL_TYPE_STRING); - String value = cell.getStringCellValue(); - boolean found = false; - for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { - if (value.trim().equalsIgnoreCase(schemaColumn.getTitle())) { - foundSchemaColumns.put(schemaColumn, columnIndex - 1); - found = true; - break; - } - } - if (!found) { - if (acceptableIdentifiers.keySet().contains(value.toLowerCase())) { - foundCustomIdentifiers.add(new Pair<MiriamType, Integer>(acceptableIdentifiers.get(value.toLowerCase()), columnIndex - 1)); - } else { - String columnNames = ""; - for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { - columnNames += schemaColumn.getTitle() + ", "; - } - for (String string : acceptableIdentifiers.keySet()) { - columnNames += ", " + string; - } - throw new InvalidColorSchemaException("Unknown column type: " + value + ". Acceptable column name: " + columnNames); - } - } - } - valueColumn = foundSchemaColumns.get(ColorSchemaColumn.VALUE); - colorColumn = foundSchemaColumns.get(ColorSchemaColumn.COLOR); - nameColumn = foundSchemaColumns.get(ColorSchemaColumn.NAME); - identifierColumn = foundSchemaColumns.get(ColorSchemaColumn.IDENTIFIER); - reactionIdentifierColumn = foundSchemaColumns.get(ColorSchemaColumn.REACTION_IDENTIFIER); - compartmentColumn = foundSchemaColumns.get(ColorSchemaColumn.COMPARTMENT); - typeColumn = foundSchemaColumns.get(ColorSchemaColumn.TYPE); - lineWidthColumn = foundSchemaColumns.get(ColorSchemaColumn.LINE_WIDTH); - reverseReactionColumn = foundSchemaColumns.get(ColorSchemaColumn.REVERSE_REACTION); + Iterator<Cell> cellIterator = row.cellIterator(); + int columnIndex = 0; + while (cellIterator.hasNext()) { + columnIndex++; + sheet.setDefaultColumnStyle(columnIndex, textStyle); + cell = cellIterator.next(); + cell.setCellType(Cell.CELL_TYPE_STRING); + String value = cell.getStringCellValue(); + boolean found = false; + for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { + if (value.trim().equalsIgnoreCase(schemaColumn.getTitle())) { + foundSchemaColumns.put(schemaColumn, columnIndex - 1); + found = true; + break; + } + } + if (!found) { + if (acceptableIdentifiers.keySet().contains(value.toLowerCase())) { + foundCustomIdentifiers.add( + new Pair<MiriamType, Integer>(acceptableIdentifiers.get(value.toLowerCase()), columnIndex - 1)); + } else { + String columnNames = ""; + for (ColorSchemaColumn schemaColumn : ColorSchemaColumn.values()) { + columnNames += schemaColumn.getTitle() + ", "; + } + for (String string : acceptableIdentifiers.keySet()) { + columnNames += ", " + string; + } + throw new InvalidColorSchemaException( + "Unknown column type: " + value + ". Acceptable column name: " + columnNames); + } + } + } + valueColumn = foundSchemaColumns.get(ColorSchemaColumn.VALUE); + colorColumn = foundSchemaColumns.get(ColorSchemaColumn.COLOR); + nameColumn = foundSchemaColumns.get(ColorSchemaColumn.NAME); + modelNameColumn = foundSchemaColumns.get(ColorSchemaColumn.MODEL_NAME); + identifierColumn = foundSchemaColumns.get(ColorSchemaColumn.IDENTIFIER); + reactionIdentifierColumn = foundSchemaColumns.get(ColorSchemaColumn.REACTION_IDENTIFIER); + compartmentColumn = foundSchemaColumns.get(ColorSchemaColumn.COMPARTMENT); + typeColumn = foundSchemaColumns.get(ColorSchemaColumn.TYPE); + lineWidthColumn = foundSchemaColumns.get(ColorSchemaColumn.LINE_WIDTH); + reverseReactionColumn = foundSchemaColumns.get(ColorSchemaColumn.REVERSE_REACTION); - if (valueColumn != null && colorColumn != null) { - throw new InvalidColorSchemaException("Schema can contain only one of these two columns: "); - } + if (valueColumn != null && colorColumn != null) { + throw new InvalidColorSchemaException("Schema can contain only one of these two columns: "); + } - if (nameColumn == null && identifierColumn == null && foundCustomIdentifiers.size() == 0 && reactionIdentifierColumn == null) { - throw new InvalidColorSchemaException("One of these columns is obligatory: name, identifier, reactionIdentifier"); - } + if (nameColumn == null && identifierColumn == null && foundCustomIdentifiers.size() == 0 + && reactionIdentifierColumn == null) { + throw new InvalidColorSchemaException( + "One of these columns is obligatory: name, identifier, reactionIdentifier"); + } - if (valueColumn == null && colorColumn == null) { - throw new InvalidColorSchemaException("Schema must contain one of these two columns: value, name"); - } + if (valueColumn == null && colorColumn == null) { + throw new InvalidColorSchemaException("Schema must contain one of these two columns: value, name"); + } - } else { - ColorSchema schema = new GenericColorSchema(); - if (nameColumn != null) { - schema.setName(row.getCell(nameColumn).getStringCellValue()); - } - if (valueColumn != null) { - try { - cell = row.getCell(valueColumn); - cell.setCellType(Cell.CELL_TYPE_STRING); - schema.setValue(Double.parseDouble(cell.getStringCellValue().replace(",", "."))); - } catch (Exception e) { - throw new InvalidColorSchemaException("[Line " + lineIndex + "] Problem with parsing value for value column. Cell value" + cell); - } - if (schema.getValue() > 1 + Configuration.EPSILON || schema.getValue() < -1 - Configuration.EPSILON) { - throw new InvalidColorSchemaException( - "[Line " + lineIndex + "] Value " + schema.getValue() + " out of range. Only values between -1 and 1 are allowed."); - } - } - if (compartmentColumn != null) { - String value = row.getCell(compartmentColumn).getStringCellValue(); - if (value != null) { - String[] compartments = value.split(","); - schema.addCompartments(compartments); - } - } - if (typeColumn != null) { - String value = row.getCell(typeColumn).getStringCellValue(); - if (value != null) { - String[] types = value.split(","); - for (String string : types) { - SpeciesMapping mapping = SpeciesMapping.getMappingByString(string); - if (mapping != null) { - schema.addType(mapping.getModelClazz()); - } else { - throw new InvalidColorSchemaException("Unknown class type: " + string + "."); - } - } - } - } - if (colorColumn != null) { - schema.setColor(colorParser.parse(row.getCell(colorColumn).getStringCellValue())); - } - if (reactionIdentifierColumn != null) { - schema.setReactionIdentifier(row.getCell(reactionIdentifierColumn).getStringCellValue()); - } - if (lineWidthColumn != null) { - cell = row.getCell(lineWidthColumn); - cell.setCellType(Cell.CELL_TYPE_STRING); - String value = cell.getStringCellValue(); - if (value != null && !value.trim().isEmpty()) { - try { - schema.setLineWidth(Double.parseDouble(value.replace(",", "."))); - } catch (NumberFormatException e) { - throw new InvalidColorSchemaException("[Line " + lineIndex + "] Problem with parsing value: \"" + value + "\""); - } - } - } - if (reverseReactionColumn != null) { - cell = row.getCell(reverseReactionColumn); - if (cell != null) { - cell.setCellType(Cell.CELL_TYPE_STRING); - schema.setReverseReaction("true".equalsIgnoreCase(cell.getStringCellValue())); - } - } - if (identifierColumn != null) { - cell = row.getCell(identifierColumn); - if (cell != null && !cell.getStringCellValue().trim().isEmpty()) { - MiriamConnector miriamConnector = new MiriamConnector(); - String value = cell.getStringCellValue().trim(); - if (miriamConnector.isValidIdentifier(value)) { - schema.setGeneralIdentifier(value); - } else { - throw new InvalidColorSchemaException("[Line " + lineIndex + "]" + " Invalid identifier: " + value); - } - } - } - for (Pair<MiriamType, Integer> pair : foundCustomIdentifiers) { - cell = row.getCell(pair.getRight()); - if (cell != null) { - schema.addIdentifierColumn(new Pair<MiriamType, String>(pair.getLeft(), cell.getStringCellValue())); - } - } + } else { + ColorSchema schema = new GenericColorSchema(); + if (nameColumn != null) { + schema.setName(row.getCell(nameColumn).getStringCellValue()); + } + if (modelNameColumn != null) { + schema.setModelName(row.getCell(modelNameColumn).getStringCellValue()); + } + if (valueColumn != null) { + try { + cell = row.getCell(valueColumn); + cell.setCellType(Cell.CELL_TYPE_STRING); + schema.setValue(Double.parseDouble(cell.getStringCellValue().replace(",", "."))); + } catch (Exception e) { + throw new InvalidColorSchemaException( + "[Line " + lineIndex + "] Problem with parsing value for value column. Cell value" + cell); + } + if (schema.getValue() > 1 + Configuration.EPSILON || schema.getValue() < -1 - Configuration.EPSILON) { + throw new InvalidColorSchemaException("[Line " + lineIndex + "] Value " + schema.getValue() + + " out of range. Only values between -1 and 1 are allowed."); + } + } + if (compartmentColumn != null) { + String value = row.getCell(compartmentColumn).getStringCellValue(); + if (value != null) { + String[] compartments = value.split(","); + schema.addCompartments(compartments); + } + } + if (typeColumn != null) { + String value = row.getCell(typeColumn).getStringCellValue(); + if (value != null) { + String[] types = value.split(","); + for (String string : types) { + SpeciesMapping mapping = SpeciesMapping.getMappingByString(string); + if (mapping != null) { + schema.addType(mapping.getModelClazz()); + } else { + throw new InvalidColorSchemaException("Unknown class type: " + string + "."); + } + } + } + } + if (colorColumn != null) { + schema.setColor(colorParser.parse(row.getCell(colorColumn).getStringCellValue())); + } + if (reactionIdentifierColumn != null) { + schema.setReactionIdentifier(row.getCell(reactionIdentifierColumn).getStringCellValue()); + } + if (lineWidthColumn != null) { + cell = row.getCell(lineWidthColumn); + cell.setCellType(Cell.CELL_TYPE_STRING); + String value = cell.getStringCellValue(); + if (value != null && !value.trim().isEmpty()) { + try { + schema.setLineWidth(Double.parseDouble(value.replace(",", "."))); + } catch (NumberFormatException e) { + throw new InvalidColorSchemaException( + "[Line " + lineIndex + "] Problem with parsing value: \"" + value + "\""); + } + } + } + if (reverseReactionColumn != null) { + cell = row.getCell(reverseReactionColumn); + if (cell != null) { + cell.setCellType(Cell.CELL_TYPE_STRING); + schema.setReverseReaction("true".equalsIgnoreCase(cell.getStringCellValue())); + } + } + if (identifierColumn != null) { + cell = row.getCell(identifierColumn); + if (cell != null && !cell.getStringCellValue().trim().isEmpty()) { + MiriamConnector miriamConnector = new MiriamConnector(); + String value = cell.getStringCellValue().trim(); + if (miriamConnector.isValidIdentifier(value)) { + schema.setGeneralIdentifier(value); + } else { + throw new InvalidColorSchemaException("[Line " + lineIndex + "]" + " Invalid identifier: " + value); + } + } + } + for (Pair<MiriamType, Integer> pair : foundCustomIdentifiers) { + cell = row.getCell(pair.getRight()); + if (cell != null) { + schema.addIdentifierColumn(new Pair<MiriamType, String>(pair.getLeft(), cell.getStringCellValue())); + } + } - if ((schema.getValue() != null && schema.getColor() != null) || (schema.getValue() == null && schema.getColor() == null)) { - throw new InvalidColorSchemaException("Value or Color is needed not both"); - } + if ((schema.getValue() != null && schema.getColor() != null) + || (schema.getValue() == null && schema.getColor() == null)) { + throw new InvalidColorSchemaException("Value or Color is needed not both"); + } - if (schema.getName() == null && schema.getGeneralIdentifier() == null && foundCustomIdentifiers.size() == 0 - && schema.getReactionIdentifier() == null) { - throw new InvalidColorSchemaException("One of these columns values is obligatory: name, identifier, reactionIdentifier"); - } - result.add(schema); - } - } - } finally { - try { - if (file != null) { - file.close(); - } - if (workbook != null) { - workbook.close(); - } - } catch (Exception e) { + if (schema.getName() == null && schema.getGeneralIdentifier() == null && foundCustomIdentifiers.size() == 0 + && schema.getReactionIdentifier() == null) { + throw new InvalidColorSchemaException( + "One of these columns values is obligatory: name, identifier, reactionIdentifier"); + } + result.add(schema); + } + } + } finally { + try { + if (file != null) { + file.close(); + } + if (workbook != null) { + workbook.close(); + } + } catch (Exception e) { - } - } - return result; + } + } + return result; - } + } - /** - * Returns list of columns that should be printed for given coloring schemas. - * - * @param schemas - * list of schemas - * @return list of columns that should be printed (were set in the coloring - * schemas) - */ - public Collection<ColorSchemaColumn> getSetColorSchemaColumns(Collection<ColorSchema> schemas) { - Set<ColorSchemaColumn> result = new HashSet<ColorSchemaColumn>(); - for (ColorSchema schema : schemas) { - if (schema.getColor() != null) { - result.add(ColorSchemaColumn.COLOR); - } - if (schema.getCompartments().size() > 0) { - result.add(ColorSchemaColumn.COMPARTMENT); - } - if (schema.getGeneralIdentifier() != null || schema.getIdentifierColumns().size() > 0) { - result.add(ColorSchemaColumn.IDENTIFIER); - } - if (schema.getLineWidth() != null) { - result.add(ColorSchemaColumn.LINE_WIDTH); - } - if (schema.getName() != null) { - result.add(ColorSchemaColumn.NAME); - } - if (schema.getReactionIdentifier() != null) { - result.add(ColorSchemaColumn.REACTION_IDENTIFIER); - } - if (schema.getReverseReaction() != null) { - result.add(ColorSchemaColumn.REVERSE_REACTION); - } - if (schema.getTypes().size() > 0) { - result.add(ColorSchemaColumn.TYPE); - } - if (schema.getValue() != null) { - result.add(ColorSchemaColumn.VALUE); - } - } - return result; - } + /** + * Returns list of columns that should be printed for given coloring schemas. + * + * @param schemas + * list of schemas + * @return list of columns that should be printed (were set in the coloring + * schemas) + */ + public Collection<ColorSchemaColumn> getSetColorSchemaColumns(Collection<ColorSchema> schemas) { + Set<ColorSchemaColumn> result = new HashSet<ColorSchemaColumn>(); + for (ColorSchema schema : schemas) { + if (schema.getColor() != null) { + result.add(ColorSchemaColumn.COLOR); + } + if (schema.getCompartments().size() > 0) { + result.add(ColorSchemaColumn.COMPARTMENT); + } + if (schema.getGeneralIdentifier() != null || schema.getIdentifierColumns().size() > 0) { + result.add(ColorSchemaColumn.IDENTIFIER); + } + if (schema.getLineWidth() != null) { + result.add(ColorSchemaColumn.LINE_WIDTH); + } + if (schema.getName() != null) { + result.add(ColorSchemaColumn.NAME); + } + if (schema.getModelName() != null) { + result.add(ColorSchemaColumn.MODEL_NAME); + } + if (schema.getReactionIdentifier() != null) { + result.add(ColorSchemaColumn.REACTION_IDENTIFIER); + } + if (schema.getReverseReaction() != null) { + result.add(ColorSchemaColumn.REVERSE_REACTION); + } + if (schema.getTypes().size() > 0) { + result.add(ColorSchemaColumn.TYPE); + } + if (schema.getValue() != null) { + result.add(ColorSchemaColumn.VALUE); + } + } + return result; + } } 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 6792e10ef5..a5a4025546 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 @@ -3,7 +3,6 @@ package lcsb.mapviewer.services.utils.data; import java.util.HashSet; import java.util.Set; - import lcsb.mapviewer.model.map.layout.ReferenceGenome; import lcsb.mapviewer.model.map.layout.ReferenceGenomeType; @@ -16,136 +15,141 @@ import lcsb.mapviewer.model.map.layout.ReferenceGenomeType; */ public enum ColorSchemaColumn { - /** - * Name of the element. - */ - NAME("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 }), // - - /** - * In which compartment the element should be located. - */ - COMPARTMENT("compartment", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Class type of the element. - */ - TYPE("type", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * New element/reaction color. - */ - COLOR("color", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Identifier of the element. - */ - IDENTIFIER("identifier", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Reaction identifier. - */ - REACTION_IDENTIFIER("reactionIdentifier", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // - - /** - * New line width of the reaction. - */ - LINE_WIDTH("lineWidth", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // - - /** - * Position where gene variants starts. - */ - POSITION("position", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Original DNA of the variant. - */ - ORIGINAL_DNA("original_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Alternative DNA of the variant. - */ - ALTERNATIVE_DNA("alternative_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Short description of the entry. - */ - DESCRIPTION("description", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), // - - /** - * Variant references. - */ - REFERENCES("references", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * What's the {@link ReferenceGenomeType}. - */ - REFERENCE_GENOME_TYPE("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 }), // - - /** - * Contig where variant was observed. - */ - CONTIG("contig", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - ALLEL_FREQUENCY("allel_frequency", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - VARIANT_IDENTIFIER("variant_identifier", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // - - /** - * Should the direction of reaction be reversed. - */ - REVERSE_REACTION("reverseReaction", new ColorSchemaType[] { ColorSchemaType.GENERIC }); // - - /** - * Default constructor that creates enum entry. - * - * @param title - * {@link #title} - * @param types - * list of {@link ColumnType types} where this column is allowed - */ - ColorSchemaColumn(String title, ColorSchemaType[] types) { - this.title = title; - for (ColorSchemaType colorSchemaType : types) { - this.types.add(colorSchemaType); - } - } - - /** - * Human readable title used in input file. - */ - private String title; - - /** - * Set of types where column is allowed. - */ - private Set<ColorSchemaType> types = new HashSet<>(); - - /** - * - * @return {@link #title} - */ - public String getTitle() { - return title; - } - - /** - * @return the types - * @see #types - */ - public Set<ColorSchemaType> getTypes() { - return types; - } + /** + * Name of the element. + */ + NAME("name", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Name of the element. + */ + MODEL_NAME("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 }), // + + /** + * In which compartment the element should be located. + */ + COMPARTMENT("compartment", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Class type of the element. + */ + TYPE("type", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * New element/reaction color. + */ + COLOR("color", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Identifier of the element. + */ + IDENTIFIER("identifier", new ColorSchemaType[] { ColorSchemaType.GENERIC, ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Reaction identifier. + */ + REACTION_IDENTIFIER("reactionIdentifier", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // + + /** + * New line width of the reaction. + */ + LINE_WIDTH("lineWidth", new ColorSchemaType[] { ColorSchemaType.GENERIC }), // + + /** + * Position where gene variants starts. + */ + POSITION("position", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Original DNA of the variant. + */ + ORIGINAL_DNA("original_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Alternative DNA of the variant. + */ + ALTERNATIVE_DNA("alternative_dna", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Short description of the entry. + */ + DESCRIPTION("description", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT, ColorSchemaType.GENERIC }), // + + /** + * Variant references. + */ + REFERENCES("references", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * What's the {@link ReferenceGenomeType}. + */ + REFERENCE_GENOME_TYPE("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 }), // + + /** + * Contig where variant was observed. + */ + CONTIG("contig", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + ALLEL_FREQUENCY("allel_frequency", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + VARIANT_IDENTIFIER("variant_identifier", new ColorSchemaType[] { ColorSchemaType.GENETIC_VARIANT }), // + + /** + * Should the direction of reaction be reversed. + */ + REVERSE_REACTION("reverseReaction", new ColorSchemaType[] { ColorSchemaType.GENERIC }); // + + /** + * Default constructor that creates enum entry. + * + * @param title + * {@link #title} + * @param types + * list of {@link ColumnType types} where this column is allowed + */ + ColorSchemaColumn(String title, ColorSchemaType[] types) { + this.title = title; + for (ColorSchemaType colorSchemaType : types) { + this.types.add(colorSchemaType); + } + } + + /** + * Human readable title used in input file. + */ + private String title; + + /** + * Set of types where column is allowed. + */ + private Set<ColorSchemaType> types = new HashSet<>(); + + /** + * + * @return {@link #title} + */ + public String getTitle() { + return title; + } + + /** + * @return the types + * @see #types + */ + public Set<ColorSchemaType> getTypes() { + return types; + } } -- GitLab