From c2cfcb27aa4f5be0733306784d3d56450fb3865a Mon Sep 17 00:00:00 2001 From: Lukas Forer Date: Mon, 4 Dec 2023 12:57:39 +0100 Subject: [PATCH] Add support of hm_inferOtherAllele column --- .../commands/CreateCollectionCommand.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main/java/genepi/riskscore/commands/CreateCollectionCommand.java b/src/main/java/genepi/riskscore/commands/CreateCollectionCommand.java index 6487e27..dfd6428 100644 --- a/src/main/java/genepi/riskscore/commands/CreateCollectionCommand.java +++ b/src/main/java/genepi/riskscore/commands/CreateCollectionCommand.java @@ -63,10 +63,17 @@ public Integer call() throws Exception { for (int i = 0; i < filenames.length; i++) { names[i] = RiskScoreFile.getName(filenames[i]); readers[i] = new CsvWithHeaderTableReader(filenames[i], format.getSeparator()); - try { - variants[i] = readVariant(readers[i], format); - } catch (Exception e) { - throw new RuntimeException("File " + filenames[i], e); + boolean read = true; + while(read) { + try { + variants[i] = readVariant(readers[i], format); + read = false; + }catch (VariantReadingException e){ + totalVariants[i]++; + ignoredVariants[i]++; + } catch (Exception e) { + throw new RuntimeException("File " + filenames[i], e); + } } } @@ -225,12 +232,19 @@ public Variant readVariant(ITableReader reader, RiskScoreFormatImpl format) thro throw new VariantReadingException("Row " + row + ": '" + reader.getString(format.getEffectWeight()) + "' is an invalid weight. Ignore variant."); } - - String rawOtherA = reader.getString(format.getOtherAllele()); + String rawOtherA = ""; + if (reader.hasColumn(format.getOtherAllele())) { + rawOtherA = reader.getString(format.getOtherAllele()); + } else { + rawOtherA = reader.getString("hm_inferOtherAllele"); + } if (rawOtherA.isEmpty()) { throw new VariantReadingException("Row " + row + ": Other allele is empty. Ignore variant."); } String otherAllele = rawOtherA.trim(); + if (otherAllele.contains("/")){ + throw new VariantReadingException("Row " + row + ": Other allele contains multiple alleles. Ignore variant."); + } String rawEffectAllele = reader.getString(format.getEffectAllele()); if (rawEffectAllele.isEmpty()) { @@ -395,14 +409,15 @@ private boolean checkFileFormat(String filename, RiskScoreFormatImpl format) thr return false; } if (!reader.hasColumn(format.getOtherAllele())) { - System.out.println("Column '" + format.getOtherAllele() + "' not found in '" + filename + "'. Ignore."); - return false; + if (!reader.hasColumn("hm_inferOtherAllele")) { + System.out.println("Column '" + format.getOtherAllele() + "' not found in '" + filename + "'. Ignore."); + return false; + } } if (!reader.hasColumn(format.getEffectAllele())) { System.out.println("Column '" + format.getEffectAllele() + "' not found in '" + filename + "'. Ignore."); return false; } - return true; }