Skip to content

Commit

Permalink
Cuppa: Fix uninformative error messages in SomaticVariantsLoader
Browse files Browse the repository at this point in the history
(cherry picked from commit c63829e)
  • Loading branch information
luan-n-nguyen committed Dec 12, 2024
1 parent bb089ad commit 5ba5aa7
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hartwig.hmftools.cup.somatics;

import static com.hartwig.hmftools.common.utils.config.CommonConfig.PURPLE_DIR_CFG;
import static com.hartwig.hmftools.common.utils.file.FileDelimiters.CSV_DELIM;
import static com.hartwig.hmftools.cup.common.CupConstants.CUP_LOGGER;
import static com.hartwig.hmftools.cup.somatics.SomaticVariant.FLD_ALT;
Expand Down Expand Up @@ -33,8 +32,6 @@

public class SomaticVariantsLoader
{
public static final String SOMATIC_VARIANTS_DIR = "somatic_variants_dir";

public static List<SomaticVariant> loadFromConfig(
final PrepConfig config, final String sampleId, @Nullable final List<VariantType> variantTypes) throws NoSuchFileException
{
Expand All @@ -45,22 +42,19 @@ public static List<SomaticVariant> loadFromConfig(
if(genericVariantsFile.isFile())
{
if(vcfFile.isFile())
{
CUP_LOGGER.error("VCF and generic variants files both exist for sample({})", sampleId);
}
CUP_LOGGER.warn("Both VCF and generic variants files exist for sample({}). Using generic variants file: {}", sampleId, genericVariantsFile);

variants = loadFromGenericFile(genericVariantsFile.getAbsolutePath(), variantTypes);
return variants;
}
else if(vcfFile.isFile())

if(vcfFile.isFile())
{
variants = loadFromVcf(vcfFile.getAbsolutePath(), variantTypes);
}
else
{
throw new NoSuchFileException(String.format("%s or %s not provided", PURPLE_DIR_CFG, SOMATIC_VARIANTS_DIR));
return variants;
}

return variants;
throw new NoSuchFileException(String.format("Invalid VCF file ('%s') or generic variants file ('%s')", vcfFile, genericVariantsFile));
}

private static List<SomaticVariant> loadFromVcf(final String vcfFile, @Nullable final List<VariantType> variantTypes)
Expand Down Expand Up @@ -96,9 +90,6 @@ private static List<SomaticVariant> loadFromGenericFile(final String filename, @
{
List<SomaticVariant> variants = new ArrayList<>();

if(filename == null || filename.isEmpty())
System.exit(1);

try
{
final List<String> lines = Files.readAllLines(new File(filename).toPath());
Expand Down Expand Up @@ -131,7 +122,8 @@ private static List<SomaticVariant> loadFromGenericFile(final String filename, @
}
catch (IOException e)
{
CUP_LOGGER.error("failed to read somatic variant flat file({}): {}", filename, e.toString());
CUP_LOGGER.error("failed to load generic variants file({}): {}", filename, e.toString());
e.printStackTrace();
System.exit(1);
}

Expand Down

0 comments on commit 5ba5aa7

Please sign in to comment.