protected boolean isCustomAnnotation(String fileName) { return !VariantReaderUtils.isAvro(fileName) && !VariantReaderUtils.isJson(fileName); }
protected static VariantJsonReader getVariantJsonReader(Path input, VariantStudyMetadata metadata) throws StorageEngineException { VariantJsonReader variantJsonReader; if (isJson(input.toString())) { Path sourceFile = getMetaFromTransformedFile(input.toAbsolutePath()); variantJsonReader = new VariantJsonReader(metadata, input.toAbsolutePath().toString(), sourceFile.toAbsolutePath().toString()); } else { throw variantInputNotSupported(input); } return variantJsonReader; }
protected DataReader<VariantAnnotation> newVariantAnnotationDataReader(URI uri) { DataReader<VariantAnnotation> reader; if (VariantReaderUtils.isAvro(uri.toString())) { reader = new AvroDataReader<>(Paths.get(uri).toFile(), VariantAnnotation.class); } else if (VariantReaderUtils.isJson(uri.toString())) { reader = new VariantAnnotationJsonDataReader(Paths.get(uri).toFile()); // } else if (VariantReaderUtils.isVcf(uri.toString())) { // //TODO: Read from VEP file // reader = new VepFormatReader(Paths.get(uri).toString()); } else { throw new IllegalArgumentException("Unable to load annotations from file " + uri); } return reader; }
@Test public void formatTest() { assertTrue(VariantReaderUtils.isProto("s1.genome.vcf.variants.proto.gz")); assertTrue(VariantReaderUtils.isJson("fileName.json")); assertTrue(VariantReaderUtils.isJson("fileName.json.gz")); assertFalse(VariantReaderUtils.isJson("fileName.vcf.gz")); assertFalse(VariantReaderUtils.isJson("fileName.json.vcf.gz")); assertFalse(VariantReaderUtils.isJson("json")); assertFalse(VariantReaderUtils.isJson("json.gz")); }
/** * Get a variant data reader depending on the type of the input file. * * @param input Stream Input variant file (avro, json, vcf) * @param metadata Optional VariantSource * @param stdin Indicate if the file should be read from the Standard Input * @return VariantReader * @throws StorageEngineException if the format is not valid or there is an error reading */ public static VariantReader getVariantReader(Path input, VariantStudyMetadata metadata, boolean stdin) throws StorageEngineException { String fileName = input.getFileName().toString(); if (metadata == null) { VariantFileMetadata variantFileMetadata = createEmptyVariantFileMetadata(input); metadata = variantFileMetadata.toVariantStudyMetadata(""); } if (isJson(fileName)) { return getVariantJsonReader(input, metadata); } else if (isAvro(fileName)) { return getVariantAvroReader(input, metadata, stdin); } else if (isVcf(fileName)) { return getVariantVcfReader(input, metadata, stdin); } else { throw variantInputNotSupported(input); } }