private void markAsNonOverlapped(FileEntry fileEntry) { int fid = getFileId(fileEntry); if (fid < 0) { fileEntry.setFileId(String.valueOf(-fid)); } }
private void markAsOverlapped(FileEntry fileEntry) { int fid = getFileId(fileEntry); if (fid > 0) { fileEntry.setFileId(String.valueOf(-fid)); } }
@Override public List<Variant> apply(List<Variant> batch) throws Exception { batch.forEach(variant -> variant.getStudies() .forEach((StudyEntry studyEntry) -> { studyEntry.setStudyId(studyIdStr); studyEntry.getFiles().forEach((FileEntry fileEntry) -> fileEntry.setFileId(fileIdStr)); })); return batch; } }
public void setFileId(String fileId) { if (impl.getFiles().isEmpty()) { impl.getFiles().add(new FileEntry(fileId, "", new HashMap<>())); } else { impl.getFiles().get(0).setFileId(fileId); } }
@Override public List<Document> apply(List<Variant> batch) { progressLogger.increment(batch.size(), () -> "up to position " + batch.get(batch.size() - 1)); return batch.stream().map(variant -> { for (StudyEntry studyEntry : variant.getStudies()) { studyEntry.setStudyId(studiesIdRemap.getOrDefault(studyEntry.getStudyId(), studyEntry.getStudyId())); for (FileEntry file : studyEntry.getFiles()) { if (file.getFileId().isEmpty()) { file.setFileId("-1"); } else if (fileIdRemap.containsKey(file.getFileId())) { file.setFileId(fileIdRemap.get(file.getFileId())); } } if (studyEntry.getSamplesData() == null) { studyEntry.setSamplesData(Collections.emptyList()); } } return variant; }).map(variantConverter::convertToStorageType).collect(Collectors.toList()); } }
private void addVariant(Variant variant) { String chromosome = variant.getChromosome(); // Remap studyId and fileId StudyEntry studyEntry = variant.getStudies().get(0); studyEntry.setStudyId(studyId); studyEntry.getFiles().get(0).setFileId(fileId); long[] coveredSlicePositions = getCoveredSlicePositions(variant); for (long slicePos : coveredSlicePositions) { addVariant(variant, chromosome, slicePos); } }
protected void checkCorrectness(URI file) throws StorageEngineException, NonStandardCompliantSampleField { Map<String, Variant> expectedVariants = readVariants(file); VariantDBIterator variants = variantStorageEngine.getDBAdaptor() .iterator(new Query(VariantQueryParam.STUDY.key(), "s1") .append(VariantQueryParam.FILE.key(), Paths.get(file).getFileName().toString()) .append(VariantQueryParam.INCLUDE_GENOTYPE.key(), true), new QueryOptions(QueryOptions.SORT, true)); while (variants.hasNext()) { Variant actual = variants.next(); Variant expected = expectedVariants.get(actual.toString()); // Check variants are correct assertNotNull(actual.toString(), expected); assertEquals(expected.toString(), actual.toString()); assertEquals(expected.getSv(), actual.getSv()); StudyEntry actualStudyEntry = actual.getStudies().get(0); StudyEntry expectedStudyEntry = expected.getStudies().get(0); // Check GTs are correct assertEquals(expectedStudyEntry.getSamplesData().stream().map(l -> Collections.singletonList(l.get(0))).collect(Collectors.toList()), actualStudyEntry.getSamplesData()); // Check File Attributes are correct expectedStudyEntry.getFiles().get(0).setFileId(""); actualStudyEntry.getFiles().get(0).setFileId(""); assertEquals(expectedStudyEntry.getFiles().get(0), actualStudyEntry.getFiles().get(0)); if (actual.getAlternate().equals("<DEL:ME:ALU>") || actual.getType().equals(VariantType.BREAKEND)) { System.err.println("WARN: Variant " + actual + (actual.getAnnotation() == null ? " without annotation" : " with annotation")); } else { assertNotNull(actual.toString(), actual.getAnnotation()); } } }
public Variant convert(VcfSliceProtos.VcfRecord vcfRecord, String chromosome, int slicePosition) { int start = getStart(vcfRecord, slicePosition); int end = getEnd(vcfRecord, slicePosition); Variant variant = new Variant(chromosome, start, end, vcfRecord.getReference(), vcfRecord.getAlternate()); variant.setType(getVariantType(vcfRecord.getType())); variant.setIds(vcfRecord.getIdNonDefaultList()); variant.resetLength(); FileEntry fileEntry = new FileEntry(); fileEntry.setFileId(fileId); Map<String, String> attributes = getFileAttributes(vcfRecord); fileEntry.setAttributes(attributes); fileEntry.setCall(vcfRecord.getCall().isEmpty() ? null : vcfRecord.getCall()); if (vcfRecord.getType().equals(VariantProto.VariantType.NO_VARIATION)) { attributes.put("END", Integer.toString(end)); } StudyEntry studyEntry = new StudyEntry(studyId); studyEntry.setFiles(Collections.singletonList(fileEntry)); studyEntry.setFormat(getFormat(vcfRecord)); studyEntry.setSamplesData(getSamplesData(vcfRecord, studyEntry.getFormatPositions())); studyEntry.setSamplesPosition(retrieveSamplePosition()); studyEntry.getFormatPositions(); // Initialize the map List<VariantProto.AlternateCoordinate> alts = vcfRecord.getSecondaryAlternatesList(); studyEntry.setSecondaryAlternates(getAlternateCoordinates(alts)); variant.addStudyEntry(studyEntry); studyEntry.getFormatPositions(); // Initialize the map return variant; }
StudyEntry studyEntry = variant.getStudies().get(0); studyEntry.setStudyId(STUDY_NAME); studyEntry.getFiles().get(0).setFileId(fileId); variant.setStudies(Collections.singletonList(studyEntry));