/** * Returns the check mapped to a particular identifier. * * @param checkIdentifier the name from the expression string * @return the {@link Check} mapped to the identifier or {@code null} if the given identifer is unmapped */ public Class<? extends Check> getCheck(String checkIdentifier) { Class<? extends Check> checkCls = checkNames.get(checkIdentifier); if (checkCls == null) { try { checkCls = (Class<? extends Check>) Class.forName(checkIdentifier); try { checkNames.putIfAbsent(checkIdentifier, checkCls); } catch (IllegalArgumentException e) { log.error("HELP! {} {} {}", checkIdentifier, checkCls, checkNames.inverse().get(checkCls)); throw e; } } catch (ClassNotFoundException | ClassCastException e) { throw new IllegalArgumentException( "Could not instantiate specified check '" + checkIdentifier + "'.", e); } } return checkCls; }
/** * Returns the check mapped to a particular identifier. * * @param checkIdentifier the name from the expression string * @return the {@link Check} mapped to the identifier or {@code null} if the given identifer is unmapped */ public Class<? extends Check> getCheck(String checkIdentifier) { Class<? extends Check> checkCls = checkNames.get(checkIdentifier); if (checkCls == null) { try { checkCls = (Class<? extends Check>) Class.forName(checkIdentifier); try { checkNames.putIfAbsent(checkIdentifier, checkCls); } catch (IllegalArgumentException e) { log.error("HELP! {} {} {}", checkIdentifier, checkCls, checkNames.inverse().get(checkCls)); throw e; } } catch (ClassNotFoundException | ClassCastException e) { throw new IllegalArgumentException( "Could not instantiate specified check '" + checkIdentifier + "'.", e); } } return checkCls; }
/** * Return all the indexed samples of an study plus the samples from a set of files. * Return a map between the sampleName and its position. * * @param studyConfiguration Selected study * @param fileIds Additional files to include * @return Map between sampleName and position */ public static BiMap<String, Integer> getIndexedSamplesPosition(StudyConfiguration studyConfiguration, int... fileIds) { Objects.requireNonNull(studyConfiguration, "StudyConfiguration is required"); BiMap<String, Integer> samplesPosition = HashBiMap.create(studyConfiguration.getSampleIds().size()); BiMap<Integer, String> idSamples = studyConfiguration.sampleIds.inverse(); for (Integer indexedFileId : studyConfiguration.getIndexedFiles()) { for (Integer sampleId : studyConfiguration.getSamplesInFiles().get(indexedFileId)) { samplesPosition.putIfAbsent(idSamples.get(sampleId), samplesPosition.size()); } } for (int fileId : fileIds) { for (Integer sampleId : studyConfiguration.getSamplesInFiles().get(fileId)) { samplesPosition.putIfAbsent(idSamples.get(sampleId), samplesPosition.size()); } } return samplesPosition; }
public MongoDBVariantWriteResult loadFile1(String chromosome, Integer fileId, List<String> chromosomes) throws StorageEngineException { studyConfiguration.getFileIds().putIfAbsent(getFileName(fileId), fileId); studyConfiguration.getSamplesInFiles().putIfAbsent(fileId, file1SampleIds); System.out.println("chromosome = " + chromosome); System.out.println("fileId = " + fileId); System.out.println("samples = " + file1SampleIds.stream().map(i -> studyConfiguration.getSampleIds().inverse().get(i)).collect(Collectors.toList()) + " : " + file1SampleIds); return loadFile(studyConfiguration, createFile1Variants(chromosome, fileId.toString(), Integer.toString(studyConfiguration.getStudyId())), fileId, chromosomes); }
public MongoDBVariantWriteResult loadFile3(String chromosome, Integer fileId, List<String> chromosomes) throws StorageEngineException { studyConfiguration2.getFileIds().putIfAbsent(getFileName(fileId), fileId); studyConfiguration2.getSamplesInFiles().putIfAbsent(fileId, file3SampleIds); System.out.println("chromosome = " + chromosome); System.out.println("fileId = " + fileId); System.out.println("samples = " + file3SampleIds.stream().map(i -> studyConfiguration2.getSampleIds().inverse().get(i)).collect(Collectors.toList()) + " : " + file3SampleIds); return loadFile(studyConfiguration2, createFile3Variants(chromosome, fileId.toString(), metadata3.getId()), fileId, chromosomes); }
public MongoDBVariantWriteResult loadFile2(String chromosome, Integer fileId, List<String> chromosomes) throws StorageEngineException { studyConfiguration2.getFileIds().putIfAbsent(getFileName(fileId), fileId); studyConfiguration2.getSamplesInFiles().putIfAbsent(fileId, file2SampleIds); System.out.println("chromosome = " + chromosome); System.out.println("fileId = " + fileId); System.out.println("samples = " + file2SampleIds.stream().map(i -> studyConfiguration2.getSampleIds().inverse().get(i)).collect(Collectors.toList()) + " : " + file2SampleIds); return loadFile(studyConfiguration2, createFile2Variants(chromosome, fileId.toString(), metadata2.getId()), fileId, chromosomes); }
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; }