private List<FileEntry> normalizeFilesInfo(List<FileEntry> files, VariantAlternateRearranger rearranger) { if (rearranger == null) { return files; } for (FileEntry file : files) { for (Map.Entry<String, String> entry : file.getAttributes().entrySet()) { String data = rearranger.rearrange(entry.getKey(), entry.getValue()); entry.setValue(data); } } return files; }
private boolean filterFileAttribute(Variant variant, String attributeKey, Predicate<String> valueValidator) { FileEntry fileEntry = getFileEntry(variant, datasetId, fileId); String value = fileEntry == null ? null : fileEntry.getAttributes().get(attributeKey); return valueValidator.test(value); }
public void addAttribute(String fileId, String key, String value) { getFile(fileId).getAttributes().put(key, value); }
public void addAttributes(String fileId, Map<String, String> attributes) { getFile(fileId).getAttributes().putAll(attributes); }
public Map<String, String> getAllAttributes() { Map<String, String> attributes = new HashMap<>(); impl.getFiles().stream().forEach(fileEntry -> attributes.putAll(fileEntry.getAttributes().entrySet().stream() .collect(Collectors.toMap(entry -> fileEntry.getFileId() + "_" + entry.getKey(), Map.Entry::getValue)) ) ); return Collections.unmodifiableMap(attributes); }
protected Map<String, String> parseInfoAttributes(Variant variant, int customFileNumber) { Map<String, String> infoMap = variant.getStudies().get(0).getFiles().get(0).getAttributes(); Map<String, String> parsedInfo = new HashMap<>(); for (String attribute : infoMap.keySet()) { if (customFileFields.get(customFileNumber).contains(attribute)) { parsedInfo.put(attribute, infoMap.get(attribute)); // parsedInfo.put(attribute, getValueFromString(infoMap.get(attribute))); } } return parsedInfo; }
public static String extractFileAttribute(Variant a, String key) { List<StudyEntry> studies = a.getStudies(); if (studies.isEmpty()) { return null; } StudyEntry studyEntry = studies.get(0); List<FileEntry> files = studyEntry.getFiles(); if (files == null || files.isEmpty()) { return null; } return files.get(0).getAttributes().get(key); }
@Deprecated public Map<String, String> getAttributes() { return !impl.getFiles().isEmpty() ? impl.getFiles().get(0).getAttributes() : null; }
private void updateVariantSetStats(List<FileEntry> files) { int numPass = 0; for (FileEntry file : files) { Map<String, String> attributes = file.getAttributes(); if (attributes.containsKey(StudyEntry.QUAL) && !(".").equals(attributes.get(StudyEntry.QUAL))) { float qual = Float.valueOf(attributes.get(StudyEntry.QUAL)); qualCount++; qualSum += qual; qualSumSq += qual * qual; } if ("PASS".equalsIgnoreCase(attributes.get(StudyEntry.FILTER))) { numPass++; } } // Count +1 PASS variant if ANY of the files is PASS if (numPass > 0) { stats.addNumPass(1); } }
@Override protected String featureValueOf(FileEntry actual) { return actual.getAttributes().get(attribute); } };
protected Map<String, List<String>> parseInfo(List<FileEntry> files) { Map<String, List<String>> parsedInfo = new HashMap<>(); List<String> fileIds = new ArrayList<>(files.size()); List<String> ori = new ArrayList<>(files.size()); parsedInfo.put("FID", fileIds); parsedInfo.put("ORI", ori); int fileIdx = 0; for (FileEntry file : files) { fileIds.add(file.getFileId() == null ? "" : file.getFileId()); ori.add(file.getCall() == null ? "" : file.getCall()); Map<String, String> attributes = file.getAttributes(); for (Map.Entry<String, String> field : attributes.entrySet()) { List<String> value; if (parsedInfo.containsKey(field.getKey())) { value = parsedInfo.get(field.getKey()); } else { value = Arrays.asList(new String[files.size()]); parsedInfo.put(field.getKey(), value); } value.set(fileIdx, field.getValue()); } fileIdx++; } return parsedInfo; }
@Deprecated private static String[] getSvInsSeq(Variant variant) { String leftSvInsSeq = null; String rightSvInsSeq = null; if (variant.getStudies()!= null && !variant.getStudies().isEmpty() && !variant.getStudies().get(0).getFiles().isEmpty()) { if (variant.getStudies().get(0).getFiles().get(0).getAttributes().containsKey(LEFT_SVINSSEQ_INFO)) { leftSvInsSeq = variant.getStudies().get(0).getFiles().get(0).getAttributes().get(LEFT_SVINSSEQ_INFO); } if (variant.getStudies().get(0).getFiles().get(0).getAttributes().containsKey(RIGHT_SVINSSEQ_INFO)) { rightSvInsSeq = variant.getStudies().get(0).getFiles().get(0).getAttributes().get(RIGHT_SVINSSEQ_INFO); } } return new String[]{leftSvInsSeq, rightSvInsSeq}; }
@Deprecated public static int[] getImpreciseEnd(Variant variant) { if (variant.getStudies()!= null && !variant.getStudies().isEmpty() && !variant.getStudies().get(0).getFiles().isEmpty() && variant.getStudies().get(0).getFiles().get(0).getAttributes().containsKey(CIEND_INFO)) { String[] parts = variant.getStudies().get(0).getFiles().get(0).getAttributes().get(CIEND_INFO).split(",", 2); return new int[]{variant.getEnd() + Integer.parseInt(parts[0]), variant.getEnd() + Integer.parseInt(parts[1])}; } else { return new int[]{variant.getEnd(), variant.getEnd()}; } }
@Deprecated public static int[] getImpreciseStart(Variant variant) { if (variant.getStudies()!= null && !variant.getStudies().isEmpty() && !variant.getStudies().get(0).getFiles().isEmpty() && variant.getStudies().get(0).getFiles().get(0).getAttributes().containsKey(CIPOS_INFO)) { String[] parts = variant.getStudies().get(0).getFiles().get(0).getAttributes().get(CIPOS_INFO).split(",", 2); return new int[]{variant.getStart() + Integer.parseInt(parts[0]), variant.getStart() + Integer.parseInt(parts[1])}; } else { return new int[]{variant.getStart(), variant.getStart()}; } }
private List<String> remapFileData(Variant variant, StudyEntry studyEntry, FileEntry fileEntry, VariantOverlappingStatus overlappingStatus) { int capacity = fileAttributes.size() + HBaseToStudyEntryConverter.FILE_INFO_START_IDX; List<String> fileColumn = Arrays.asList(new String[capacity]); Map<String, String> attributes = fileEntry.getAttributes(); fileColumn.set(HBaseToStudyEntryConverter.FILE_CALL_IDX, fileEntry.getCall()); if (addSecondaryAlternates && studyEntry.getSecondaryAlternates() != null && !studyEntry.getSecondaryAlternates().isEmpty()) { fileColumn.set(HBaseToStudyEntryConverter.FILE_SEC_ALTS_IDX, getSecondaryAlternates(variant, studyEntry)); } fileColumn.set(HBaseToStudyEntryConverter.FILE_VARIANT_OVERLAPPING_STATUS_IDX, overlappingStatus.toString()); fileColumn.set(HBaseToStudyEntryConverter.FILE_QUAL_IDX, attributes.get(StudyEntry.QUAL)); fileColumn.set(HBaseToStudyEntryConverter.FILE_FILTER_IDX, attributes.get(StudyEntry.FILTER)); int attributeIdx = HBaseToStudyEntryConverter.FILE_INFO_START_IDX; for (String fileAttribute : fileAttributes) { fileColumn.set(attributeIdx, attributes.get(fileAttribute)); attributeIdx++; } // Trim all leading null values fileColumn = trimLeadingNullValues(fileColumn, HBaseToStudyEntryConverter.FILE_INFO_START_IDX); return fileColumn; }
/** * @param variant remains unchanged if the VariantSourceEntry is not inside * @param study stats are written here */ public void calculate(Variant variant, StudyEntry study) { // Map<String, String> infoMap = VariantAggregatedVcfFactory.getInfoMap(info); if (study.getFiles().isEmpty()) { return; } FileEntry fileEntry = study.getFiles().get(0); Map<String, String> infoMap = fileEntry.getAttributes(); int numAllele = 0; String reference = variant.getReference(); String[] alternateAlleles; if (study.getSecondaryAlternates().isEmpty()) { alternateAlleles = new String[]{variant.getAlternate()}; } else { List<String> secondaryAlternates = study.getSecondaryAlternates().stream().map(AlternateCoordinate::getAlternate).collect(Collectors.toList()); secondaryAlternates.add(0, variant.getAlternate()); alternateAlleles = secondaryAlternates.toArray(new String[secondaryAlternates.size()]); } if (tagMap != null) { parseMappedStats(variant, study, numAllele, reference, alternateAlleles, infoMap); } else { parseStats(variant, study, numAllele, reference, alternateAlleles, infoMap); } }
public static Variant addAttribute(Variant var, String key, String value) { var.getStudy("1").getFile("1").getAttributes().put(key, value); return var; }
private void checkFileEntry(FileEntry expectedFileEntry, FileEntry actualFileEntry) { if (!expectedFileEntry.getFileId().equals(actualFileEntry.getFileId())) { fail("File entry ID mismatch: " + expectedFileEntry.getFileId() + ", " + actualFileEntry.getFileId()); } if (expectedFileEntry.getCall() != null || actualFileEntry.getCall() != null) { if (expectedFileEntry.getCall() == null || !expectedFileEntry.getCall().equals(actualFileEntry.getCall())) { fail("File entry call mismatch: " + expectedFileEntry.getCall() + ", " + actualFileEntry.getCall()); } } if (expectedFileEntry.getAttributes() != null || actualFileEntry.getAttributes() != null) { if (expectedFileEntry.getAttributes().size() != actualFileEntry.getAttributes().size()) { fail("File entry attribute size mismatch: " + expectedFileEntry.getAttributes().size() + ", " + actualFileEntry.getAttributes().size()); } for (String key : actualFileEntry.getAttributes().keySet()) { if (!expectedFileEntry.getAttributes().containsKey(key)) { fail("File entry attribute '" + key + "' not found"); } if (!expectedFileEntry.getAttributes().get(key).equals(actualFileEntry.getAttributes().get(key))) { fail("File entry attribute '" + key + "' mismatch: " + expectedFileEntry.getAttributes().get(key) + ", " + actualFileEntry.getAttributes().get(key)); } } } } }
private Variant parseBreakendPair(VariantContext variantContext, VariantContext variantContext1) { // Get Variant object for the first BND Variant variant = converter.convert(variantContext); // Set mate position variant.getSv().getBreakend().getMate().setChromosome(variantContext1.getContig()); variant.getSv().getBreakend().getMate().setPosition(variantContext1.getStart()); // Check the second BND does have CIPOS List ciposValue = variantContext1.getAttributeAsList(CIPOS); if (!ciposValue.isEmpty()) { // Get CIPOS from second BND String ciposString = StringUtils.join(ciposValue, VCFConstants.INFO_FIELD_ARRAY_SEPARATOR); // Set CIPOS string of the sencond BND as part of the file INFO field in the first BND Map<String, String> attributesMap = variant.getStudies().get(0).getFiles().get(0).getAttributes(); attributesMap.put(MATE_CIPOS, ciposString); // CIPOS of the second breakend List ciposParts = variantContext1.getAttributeAsList(CIPOS); variant.getSv() .getBreakend() .getMate() .setCiPositionLeft(variantContext1.getStart() + Integer.valueOf((String) ciposParts.get(0))); variant.getSv() .getBreakend() .getMate() .setCiPositionRight(variantContext1.getStart() + Integer.valueOf((String) ciposParts.get(1))); // If not, it's a precise call, just position is stored (above) } return variant; }
@Test public void testGetByFilterMultiStudy() { query = new Query() .append(VariantQueryParam.FILTER.key(), "LowGQX;LowMQ") .append(VariantQueryParam.FILE.key(), file12877 + VariantQueryUtils.OR + file12882); queryResult = query(query, options); VariantQueryResult<Variant> allVariants = dbAdaptor.get(new Query() .append(VariantQueryParam.INCLUDE_SAMPLE.key(), "NA12877,NA12882") .append(VariantQueryParam.INCLUDE_FILE.key(), asList(file12877, file12882)), options); assertThat(queryResult, everyResult(allVariants, anyOf( withStudy("S_1", withFileId(file12877, with(FILTER, fileEntry -> fileEntry.getAttributes().get(FILTER), allOf(containsString("LowGQX"), containsString("LowMQ"))))), withStudy("S_2", withFileId(file12882, with(FILTER, fileEntry -> fileEntry.getAttributes().get(FILTER), allOf(containsString("LowGQX"), containsString("LowMQ"))))) ))); }