protected List<Variant> addSamplesPosition(List<Variant> variants) { if (samplesPositions != null) { for (Variant variant : variants) { for (StudyEntry studyEntry : variant.getStudies()) { LinkedHashMap<String, Integer> samplesPosition = samplesPositions.get(studyEntry.getStudyId()); if (samplesPosition != null) { studyEntry.setSortedSamplesPosition(samplesPosition); } } } } else { for (Variant variant : variants) { if (variant.getStudies().size() == 1) { variant.getStudies().get(0).setSortedSamplesPosition(samplesPosition); } } } return variants; }
protected StudyEntry newStudyEntry(StudyConfiguration studyConfiguration, List<String> fixedFormat) { StudyEntry studyEntry; if (studyNameAsStudyId) { studyEntry = new StudyEntry(studyConfiguration.getStudyName()); } else { studyEntry = new StudyEntry(String.valueOf(studyConfiguration.getStudyId())); } if (expectedFormat == null) { studyEntry.setFormat(new ArrayList<>(fixedFormat)); } else { studyEntry.setFormat(new ArrayList<>(expectedFormat)); } LinkedHashMap<String, Integer> returnedSamplesPosition; if (mutableSamplesPosition) { returnedSamplesPosition = new LinkedHashMap<>(getReturnedSamplesPosition(studyConfiguration)); } else { returnedSamplesPosition = getReturnedSamplesPosition(studyConfiguration); } studyEntry.setSamplesData(new ArrayList<>(returnedSamplesPosition.size())); studyEntry.setSortedSamplesPosition(returnedSamplesPosition); return studyEntry; }
currentStudy.setSortedSamplesPosition(newSamplesPosition); currentStudy.setFormat(newFormat);
StudyEntry studyEntry = new StudyEntry(); studyEntry.setFormat(archiveVariant.getStudies().get(0).getFormat()); studyEntry.setSortedSamplesPosition(new LinkedHashMap<>()); studyEntry.setSamplesData(new ArrayList<>());
studyEntry.setSortedSamplesPosition(samplesPosition); studyEntry.setSamplesData(samplesData); variant.addStudyEntry(studyEntry);
studyEntry.setSortedSamplesPosition(new LinkedHashMap<>()); studyEntry.setSamplesData(new ArrayList<>()); mergedVariant.addStudyEntry(studyEntry);
protected List<Variant> readVariants(StudyConfiguration sc, String fileName, Integer fileId, String sampleSufix) { FullVcfCodec codec = new FullVcfCodec(); LineIterator lineIterator = codec.makeSourceFromStream(getClass().getResourceAsStream(fileName)); VCFHeader header = (VCFHeader) codec.readActualHeader(lineIterator); VariantNormalizer normalizer = new VariantNormalizer().configure(header); VariantFileMetadata file = new VariantFileMetadata(fileId.toString(), "file"); VariantStudyMetadata studyMetadata = file.toVariantStudyMetadata(String.valueOf(sc.getStudyId())); VariantVcfHtsjdkReader reader = new VariantVcfHtsjdkReader(getClass().getResourceAsStream(fileName), studyMetadata, normalizer); reader.open(); reader.pre(); List<Variant> variants = reader.read(1000000); reader.post(); reader.close(); sc.getAttributes().append(DEFAULT_GENOTYPE.key(), defaultGenotype); LinkedHashSet<Integer> sampleIds = new LinkedHashSet<>(); LinkedHashMap<String, Integer> samplesPosition = new LinkedHashMap<>(); for (String sample : file.getSampleIds()) { sample = sample + sampleSufix; sc.getSampleIds().putIfAbsent(sample, sc.getSampleIds().size() + 1); sampleIds.add(sc.getSampleIds().get(sample)); samplesPosition.put(sample, samplesPosition.size()); } sc.getFileIds().put(getFileName(fileId), fileId); sc.getSamplesInFiles().put(fileId, sampleIds); for (Variant variant : variants) { variant.getStudies().get(0).setSortedSamplesPosition(samplesPosition); } return variants; }