Search in sources :

Example 1 with VcfReader

use of org.molgenis.vcf.VcfReader in project molgenis by molgenis.

the class VcfRepositoryTest method testGetEntityType.

// Regression test for https://github.com/molgenis/molgenis/issues/6528
@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Failed to read VCF Metadata from file; nested exception is java.io.IOException: error processing source")
public void testGetEntityType() throws IOException {
    VcfReaderFactory vcfReaderFactory = mock(VcfReaderFactory.class);
    VcfReader vcfReader = mock(VcfReader.class);
    doThrow(new IOException("error processing source")).when(vcfReader).getVcfMeta();
    when(vcfReaderFactory.get()).thenReturn(vcfReader);
    String entityTypeId = "entityTypeId";
    VcfAttributes vcfAttributes = mock(VcfAttributes.class);
    EntityTypeFactory entityTypeFactory = mock(EntityTypeFactory.class);
    AttributeFactory attrMetaFactory = mock(AttributeFactory.class);
    VcfRepository vcfRepository = new VcfRepository(vcfReaderFactory, entityTypeId, vcfAttributes, entityTypeFactory, attrMetaFactory);
    vcfRepository.getEntityType();
}
Also used : EntityTypeFactory(org.molgenis.data.meta.model.EntityTypeFactory) VcfAttributes(org.molgenis.data.vcf.model.VcfAttributes) AttributeFactory(org.molgenis.data.meta.model.AttributeFactory) VcfReader(org.molgenis.vcf.VcfReader) IOException(java.io.IOException) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 2 with VcfReader

use of org.molgenis.vcf.VcfReader in project molgenis by molgenis.

the class VcfReaderFactoryImpl method get.

@Override
public VcfReader get() {
    try {
        InputStream inputStream = new FileInputStream(file);
        if (file.getName().endsWith(".gz")) {
            inputStream = new GZIPInputStream(inputStream);
        } else if (file.getName().endsWith(".zip")) {
            ZipFile zipFile = new ZipFile(file.getPath());
            Enumeration<? extends ZipEntry> e = zipFile.entries();
            // your only file
            ZipEntry entry = e.nextElement();
            inputStream = zipFile.getInputStream(entry);
        }
        VcfReader reader = new VcfReader(new InputStreamReader(inputStream, UTF_8));
        // bootstrap reader so close() can close all readers
        vcfReaderRegistry.add(reader);
        return reader;
    } catch (IOException e) {
        throw new MolgenisDataException("Failed to create VCF Reader for file" + file.getAbsolutePath(), e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) MolgenisDataException(org.molgenis.data.MolgenisDataException) Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) GZIPInputStream(java.util.zip.GZIPInputStream) ZipEntry(java.util.zip.ZipEntry) VcfReader(org.molgenis.vcf.VcfReader)

Aggregations

VcfReader (org.molgenis.vcf.VcfReader)2 IOException (java.io.IOException)1 Enumeration (java.util.Enumeration)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)1 MolgenisDataException (org.molgenis.data.MolgenisDataException)1 AttributeFactory (org.molgenis.data.meta.model.AttributeFactory)1 EntityTypeFactory (org.molgenis.data.meta.model.EntityTypeFactory)1 VcfAttributes (org.molgenis.data.vcf.model.VcfAttributes)1 Test (org.testng.annotations.Test)1