private void checkAlignmentFormat(File file) throws CatalogException { if (!file.getFormat().equals(File.Format.BAM)) { throw new CatalogException("File " + file.getName() + " not supported. Expecting a BAM file."); } }
public static VariantFileMetadata readVariantFileMetadata(File file, URI fileUri) throws IOException { File.Format format = file.getFormat(); File.Format detectFormat = FileUtils.detectFormat(fileUri); if (format == File.Format.VCF || format == File.Format.GVCF || format == File.Format.BCF || detectFormat == File.Format.VCF || detectFormat == File.Format.GVCF || detectFormat == File.Format.BCF) { VariantFileMetadata metadata = new VariantFileMetadata(String.valueOf(file.getUid()), file.getName()); metadata.setId(String.valueOf(file.getUid())); return VariantMetadataUtils.readVariantFileMetadata(Paths.get(fileUri.getPath()), metadata); } else { return null; } }
public static AlignmentHeader readAlignmentHeader(Study study, File file, URI fileUri) { if (file.getFormat() == File.Format.SAM || file.getFormat() == File.Format.BAM || FileUtils.detectFormat(fileUri) == File.Format.SAM || FileUtils.detectFormat(fileUri) == File.Format.BAM) { AlignmentSamDataReader reader = new AlignmentSamDataReader(Paths.get(fileUri), study.getName()); try { reader.open(); reader.pre(); reader.post(); // reader.getSamHeader().get return reader.getHeader(); } finally { reader.close(); } } else { return null; } }
if (file.getStatus().getName().equals(File.FileStatus.READY) && file.getFormat().equals(File.Format.VCF)) { String indexStatus; if (file.getIndex() != null && file.getIndex().getStatus() != null && file.getIndex().getStatus().getName() != null) {
if (file.getFormat().equals(File.Format.VCF) || file.getFormat().equals(File.Format.GVCF)) { String status = file.getIndex() == null || file.getIndex().getStatus() == null ? FileIndex.IndexStatus.NONE : file.getIndex().getStatus().getName(); logger.warn("The input file is not a variant file. Format {}", file.getFormat());
@Test public void testComplexAdd() throws IOException, CatalogException, URISyntaxException { CatalogIOManager ioManager = catalogManager.getCatalogIOManagerFactory().getDefault(); URI fileUri = getClass().getResource("/biofiles/variant-test-file.vcf.gz").toURI(); ioManager.copyFile(fileUri, directory.resolve("file1.vcf.gz").toUri()); CatalogManagerTest.createDebugFile(directory.resolve("file1.vcf.variants.json").toString()); CatalogManagerTest.createDebugFile(directory.resolve("file1.vcf.variants.json.gz").toString()); CatalogManagerTest.createDebugFile(directory.resolve("file1.vcf.variants.json.snappy").toString()); CatalogManagerTest.createDebugFile(directory.resolve("file2.bam").toString()); CatalogManagerTest.createDebugFile(directory.resolve("file2.sam.gz").toString()); FileScanner fileScanner = new FileScanner(catalogManager); List<File> files = fileScanner.scan(folder, directory.toUri(), FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); Map<String, File> map = files.stream().collect(Collectors.toMap(File::getName, (f) -> f)); assertEquals(6, files.size()); files.forEach((file) -> assertEquals(File.FileStatus.READY, file.getStatus().getName())); assertEquals(File.Bioformat.VARIANT, map.get("file1.vcf.gz").getBioformat()); assertEquals(File.Bioformat.VARIANT, map.get("file1.vcf.variants.json").getBioformat()); assertEquals(File.Bioformat.VARIANT, map.get("file1.vcf.variants.json.gz").getBioformat()); assertEquals(File.Bioformat.VARIANT, map.get("file1.vcf.variants.json.snappy").getBioformat()); assertEquals(File.Bioformat.ALIGNMENT, map.get("file2.bam").getBioformat()); assertEquals(File.Bioformat.ALIGNMENT, map.get("file2.sam.gz").getBioformat()); assertEquals(File.Format.VCF, map.get("file1.vcf.gz").getFormat()); assertEquals(File.Format.JSON, map.get("file1.vcf.variants.json").getFormat()); assertEquals(File.Format.JSON, map.get("file1.vcf.variants.json.gz").getFormat()); assertEquals(File.Format.JSON, map.get("file1.vcf.variants.json.snappy").getFormat()); assertEquals(File.Format.BAM, map.get("file2.bam").getFormat()); assertEquals(File.Format.SAM, map.get("file2.sam.gz").getFormat()); }
@Test public void testIndex() throws Exception { URI uri = getClass().getResource("/biofiles/variant-test-file.vcf.gz").toURI(); File file = fileManager.link(studyFqn, uri, "", null, sessionIdUser).first(); assertEquals(4, file.getSamples().size()); assertEquals(File.Format.VCF, file.getFormat()); assertEquals(File.Bioformat.VARIANT, file.getBioformat()); Job job = fileManager.index(studyFqn, Collections.singletonList(file.getName()), "VCF", null, sessionIdUser).first(); assertEquals(file.getUid(), job.getInput().get(0).getUid()); }
public QueryResult<Sample> loadSampleAnnotations(File pedFile, String variableSetId, String sessionId) throws CatalogException { if (!pedFile.getFormat().equals(File.Format.PED)) { throw new CatalogException(pedFile.getUid() + " is not a pedigree file");
if (!File.Format.VCF.equals(file.getFormat()) && !File.Format.GVCF.equals(file.getFormat())) { throw new CatalogException("The file " + file.getName() + " is not a VCF file."); if (!File.Format.BAM.equals(file.getFormat()) && !File.Format.SAM.equals(file.getFormat())) { throw new CatalogException("The file " + file.getName() + " is not a SAM/BAM file.");
fileInfo.setName(file.getName()); fileInfo.setBioformat(file.getBioformat()); fileInfo.setFormat(file.getFormat());
@Test public void testGetMetadataFromVcf() throws CatalogException, FileNotFoundException { File file = catalogManager.getFileManager().upload(study.getFqn(), vcfFileUri, new File().setPath(folder.getPath() + VCF_FILE_NAME), false, false, sessionIdUser).first(); assertTrue(file.getSize() > 0); file = FileMetadataReader.get(catalogManager). setMetadataInformation(file, null, null, sessionIdUser, false); assertEquals(File.FileStatus.READY, file.getStatus().getName()); assertEquals(File.Format.VCF, file.getFormat()); assertEquals(File.Bioformat.VARIANT, file.getBioformat()); assertNotNull(file.getAttributes().get(VARIANT_FILE_METADATA)); assertEquals(4, file.getSamples().size()); assertEquals(expectedSampleNames, ((Map<String, Object>) file.getAttributes().get(VARIANT_FILE_METADATA)).get("sampleIds")); catalogManager.getSampleManager().get(study.getFqn(), new Query(SampleDBAdaptor.QueryParams.ID.key(), file.getSamples().stream().map(Sample::getId).collect(Collectors.toList())), new QueryOptions(), sessionIdUser).getResult(); assertTrue(expectedSampleNames.containsAll(file.getSamples().stream().map(Sample::getId).collect(Collectors.toSet()))); }
@Test public void testCreate() throws CatalogException { QueryResult<File> fileQueryResult = FileMetadataReader.get(catalogManager). create(study.getFqn(), vcfFileUri, folder.getPath() + VCF_FILE_NAME, "", false, null, sessionIdUser); File file = fileQueryResult.first(); assertEquals(File.FileStatus.STAGE, file.getStatus().getName()); assertEquals(File.Format.VCF, file.getFormat()); assertEquals(File.Bioformat.VARIANT, file.getBioformat()); assertNotNull(file.getAttributes().get(VARIANT_FILE_METADATA)); assertEquals(4, file.getSamples().size()); assertEquals(21499, file.getSize()); new FileUtils(catalogManager).upload(vcfFileUri, file, null, sessionIdUser, false, false, true, true, Integer.MAX_VALUE); file = catalogManager.getFileManager().get(study.getFqn(), file.getPath(), null, sessionIdUser).first(); assertEquals(File.FileStatus.READY, file.getStatus().getName()); assertEquals(File.Format.VCF, file.getFormat()); assertEquals(File.Bioformat.VARIANT, file.getBioformat()); assertNotNull(file.getAttributes().get(VARIANT_FILE_METADATA)); assertNotNull(((Map) file.getAttributes().get(VARIANT_FILE_METADATA)).get("sampleIds")); assertEquals(4, ((List) ((Map) file.getAttributes().get(VARIANT_FILE_METADATA)).get("sampleIds")).size()); assertNotNull(((Map) file.getAttributes().get(VARIANT_FILE_METADATA)).get("header")); assertEquals(4, file.getSamples().size()); assertEquals(21499, file.getSize()); }
assert (fileSolrModel.getName().equals(file.getName())); assert (fileSolrModel.getType().equals(file.getType().name())); assert (fileSolrModel.getFormat().equals(file.getFormat().name())); assert (fileSolrModel.getBioformat().equals(file.getBioformat().name())); assert (fileSolrModel.getRelease() == file.getRelease());
@Test public void testDoNotOverwriteSampleIds() throws CatalogException, FileNotFoundException { File file = catalogManager.getFileManager().upload(study.getFqn(), vcfFileUri, new File().setPath(folder.getPath() + VCF_FILE_NAME), false, false, sessionIdUser).first(); assertEquals(File.FileStatus.READY, file.getStatus().getName()); assertEquals(File.Format.VCF, file.getFormat()); assertEquals(File.Bioformat.VARIANT, file.getBioformat()); assertNotNull(file.getAttributes().get(VARIANT_FILE_METADATA)); assertEquals(4, file.getSamples().size()); //Add a sampleId String sampleId = catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId("Bad_Sample"), null, sessionIdUser) .first().getId(); catalogManager.getFileManager().update(study.getFqn(), file.getPath(), new ObjectMap(FileDBAdaptor.QueryParams.SAMPLES.key(), Collections.singletonList(sampleId)), new QueryOptions(), sessionIdUser); file = catalogManager.getFileManager().get(study.getFqn(), file.getPath(), null, sessionIdUser).first(); assertEquals(5, file.getSamples().size()); assertEquals(sampleId, file.getSamples().get(4).getId()); }
ParamUtils.checkPath(file.getPath(), "path"); file.setType(ParamUtils.defaultObject(file.getType(), File.Type.FILE)); file.setFormat(ParamUtils.defaultObject(file.getFormat(), File.Format.PLAIN)); file.setBioformat(ParamUtils.defaultObject(file.getBioformat(), File.Bioformat.NONE)); file.setDescription(ParamUtils.defaultString(file.getDescription(), ""));
if (format != File.Format.UNKNOWN && !format.equals(file.getFormat())) { modifyParams.put(FileDBAdaptor.QueryParams.FORMAT.key(), format); file.setFormat(format);