@Test @Transactional(propagation = Propagation.REQUIRES_NEW) public void testIndexUpdateOnProjectOperations() throws Exception { Resource gffResource = context.getResource(CLASSPATH_TEMPLATES_GENES_SORTED); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setPath(gffResource.getFile().getAbsolutePath()); request.setName("testGeneFile"); GeneFile geneFile = gffManager.registerGeneFile(request); Assert.assertNotNull(geneFile); Assert.assertNotNull(geneFile.getId()); referenceGenomeManager.updateReferenceGeneFileId(testReference.getId(), geneFile.getId()); Resource vcfResource = context.getResource(CLASSPATH_TEMPLATES_FELIS_CATUS_VCF); request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setPath(vcfResource.getFile().getAbsolutePath()); request.setName("testVcf"); VcfFile vcfFile = vcfManager.registerVcfFile(request); Project project = new Project(); project.setName(TEST_PROJECT_NAME + 1); project.setItems(Arrays.asList(new ProjectItem(new BiologicalDataItem(vcfFile.getBioDataItemId())), new ProjectItem(new BiologicalDataItem(geneFile.getBioDataItemId())), new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); projectManager.create(project); VcfFilterForm vcfFilterForm = new VcfFilterForm(); vcfFilterForm.setVcfFileIdsByProject( singletonMap(project.getId(), singletonList(vcfFile.getId()))); vcfFilterForm.setChromosomeIds(singletonList(testChromosome.getId())); vcfFilterForm.setGenes(new VcfFilterForm.FilterSection<>(singletonList(TEST_GENE_PREFIX), false)); vcfFilterForm.setVariationTypes(new VcfFilterForm.FilterSection<>(Arrays.asList(VariationType.MNP, VariationType.SNV), false)); IndexSearchResult<VcfIndexEntry> entryList = featureIndexManager.filterVariations(vcfFilterForm, project.getId()); Assert.assertFalse(entryList.getEntries().isEmpty()); request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setPath(vcfResource.getFile().getAbsolutePath()); request.setName(vcfResource.getFilename() + "2"); VcfFile vcfFile2 = vcfManager.registerVcfFile(request); project = projectManager.addProjectItem(project.getId(), vcfFile2.getBioDataItemId()); entryList = featureIndexManager.filterVariations(vcfFilterForm, project.getId()); Assert.assertFalse(entryList.getEntries().isEmpty()); Assert.assertTrue(entryList.getEntries().stream().allMatch(e -> e.getFeatureFileId().equals(vcfFile.getId()))); VcfFilterForm vcfFilterForm2 = new VcfFilterForm(); vcfFilterForm2.setVcfFileIdsByProject( singletonMap(project.getId(), singletonList(vcfFile2.getId()))); vcfFilterForm.setChromosomeIds(singletonList(testChromosome.getId())); vcfFilterForm2.setGenes(new VcfFilterForm.FilterSection<>(singletonList(TEST_GENE_PREFIX), false)); vcfFilterForm2.setVariationTypes(new VcfFilterForm.FilterSection<>(Arrays.asList(VariationType.MNP, VariationType.SNV), false)); IndexSearchResult<VcfIndexEntry> entryList2 = featureIndexManager.filterVariations(vcfFilterForm2, project.getId()); Assert.assertFalse(entryList2.getEntries().isEmpty()); Assert.assertEquals(entryList.getEntries().size(), entryList2.getEntries().size()); Assert.assertTrue(entryList2.getEntries().stream().allMatch(e -> e.getFeatureFileId().equals( vcfFile2.getId()))); vcfFilterForm2.setVcfFileIdsByProject(null); entryList2 = featureIndexManager.filterVariations(vcfFilterForm2, project.getId()); Assert.assertFalse(entryList2.getEntries().isEmpty()); Assert.assertEquals(entryList2.getEntries().size(), entryList.getEntries().size() * 2); vcfFilterForm2.setVcfFileIdsByProject( singletonMap(project.getId(), Arrays.asList(vcfFile.getId(), vcfFile2.getId()))); entryList2 = featureIndexManager.filterVariations(vcfFilterForm2, project.getId()); Assert.assertFalse(entryList2.getEntries().isEmpty()); Assert.assertEquals(entryList2.getEntries().size(), entryList.getEntries().size() * 2); project.setItems(project.getItems().stream() .filter(i -> !(i.getBioDataItem() instanceof VcfFile) || !((VcfFile) i.getBioDataItem()).getId().equals( vcfFile2.getId())) .collect(Collectors.toList())); project = projectManager.create(project); vcfFilterForm2.setVcfFileIdsByProject(singletonMap(project.getId(), singletonList(vcfFile2.getId()))); entryList2 = featureIndexManager.filterVariations(vcfFilterForm2, project.getId()); Assert.assertTrue(entryList2.getEntries().isEmpty()); project.setItems(project.getItems().stream() .filter(i -> !(i.getBioDataItem() instanceof GeneFile)) .collect(Collectors.toList())); project = projectManager.create(project); vcfFilterForm.setGenes(null); entryList = featureIndexManager.filterVariations(vcfFilterForm, project.getId()); Assert.assertFalse(entryList.getEntries().isEmpty()); project.getItems().clear(); projectManager.create(project); Project loadedProject = projectManager.load(project.getId()); Assert.assertTrue(loadedProject.getItems().isEmpty()); entryList2 = featureIndexManager.filterVariations(new VcfFilterForm(), project.getId()); Assert.assertTrue(entryList2.getEntries().isEmpty()); project.setItems(Arrays.asList(new ProjectItem(new BiologicalDataItem(vcfFile.getBioDataItemId())), new ProjectItem(new BiologicalDataItem(vcfFile2.getBioDataItemId())), new ProjectItem(new BiologicalDataItem(testReference.getBioDataItemId())))); projectManager.create(project); entryList2 = featureIndexManager.filterVariations(new VcfFilterForm(), project.getId()); Assert.assertTrue(entryList2.getEntries().stream().anyMatch(e -> e.getFeatureFileId().equals(vcfFile.getId()))); Assert.assertTrue(entryList2.getEntries().stream().anyMatch(e -> e.getFeatureFileId().equals( vcfFile2.getId()))); }
public IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm, long projectId) throws IOException { Project project = projectManager.load(projectId); List<VcfFile> files = project.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF) .map(i -> (VcfFile) i.getBioDataItem()) .collect(Collectors.toList()); return getVcfSearchResult(filterForm, files); }
FeatureIndexManager { public IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm, long projectId) throws IOException { Project project = projectManager.load(projectId); List<VcfFile> files = project.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF) .map(i -> (VcfFile) i.getBioDataItem()) .collect(Collectors.toList()); return getVcfSearchResult(filterForm, files); } }
FeatureIndexManager { public IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm, long projectId) throws IOException { Project project = projectManager.load(projectId); List<VcfFile> files = project.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF) .map(i -> (VcfFile) i.getBioDataItem()) .collect(Collectors.toList()); return getVcfSearchResult(filterForm, files); }  }
FeatureIndexManager { public IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm, long projectId) throws IOException { Project project = projectManager.load(projectId); List<VcfFile> files = project.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF) .map(i -> (VcfFile) i.getBioDataItem()) .collect(Collectors.toList()); return getVcfSearchResult(filterForm, files); }  void deleteFromIndexByFileId(final long projectId, List<Pair<FeatureType, Long>> fileIds); Set<String> searchGenesInVcfFilesInProject(long projectId, String gene, List<Long> vcfFileIds); Set<String> searchGenesInVcfFiles(String gene, List<Long> vcfFileIds); List<Chromosome> filterChromosomes(VcfFilterForm filterForm, long projectId); List<Chromosome> filterChromosomes(VcfFilterForm filterForm); IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm, long projectId); int getTotalPagesCount(VcfFilterForm filterForm); int getTotalPagesCount(VcfFilterForm filterForm, long projectId); List<Group> groupVariations(VcfFilterForm filterForm, long projectId, String groupByField); List<Group> groupVariations(VcfFilterForm filterForm, String groupByField); IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm); IndexSearchResult searchFeaturesInProject(String featureId, long projectId); IndexSearchResult searchFeaturesByReference(String featureId, long referenceId); VcfFilterInfo loadVcfFilterInfoForProject(long projectId); void buildIndexForFile(FeatureFile featureFile); Set<String> fetchGeneIds(int start, int end, List<GeneFile> geneFiles, Chromosome chromosome); void writeLuceneIndexForFile(final FeatureFile featureFile,
            final List<? extends FeatureIndexEntry> entries,
            VcfFilterInfo vcfFilterInfo); void makeIndexForBedReader(BedFile bedFile, AbstractFeatureReader<NggbBedFeature, LineIterator> reader,
                                      Map<String, Chromosome> chromosomeMap); void makeIndexForVcfReader(VcfFile vcfFile, FeatureReader<VariantContext> reader, List<GeneFile> geneFiles,
                                       Map<String, Chromosome> chromosomeMap, VcfFilterInfo info); void processGeneFile(GeneFile geneFile, final Map<String, Chromosome> chromosomeMap,
            boolean full); void addGeneFeatureToIndex(List<FeatureIndexEntry> allEntries, GeneFeature feature,
                                     Map<String, Chromosome> chromosomeMap); }
FeatureIndexManager { public IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm, long projectId) throws IOException { Project project = projectManager.load(projectId); List<VcfFile> files = project.getItems().stream() .filter(i -> i.getBioDataItem().getFormat() == BiologicalDataItemFormat.VCF) .map(i -> (VcfFile) i.getBioDataItem()) .collect(Collectors.toList()); return getVcfSearchResult(filterForm, files); }  void deleteFromIndexByFileId(final long projectId, List<Pair<FeatureType, Long>> fileIds); Set<String> searchGenesInVcfFilesInProject(long projectId, String gene, List<Long> vcfFileIds); Set<String> searchGenesInVcfFiles(String gene, List<Long> vcfFileIds); List<Chromosome> filterChromosomes(VcfFilterForm filterForm, long projectId); List<Chromosome> filterChromosomes(VcfFilterForm filterForm); IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm, long projectId); int getTotalPagesCount(VcfFilterForm filterForm); int getTotalPagesCount(VcfFilterForm filterForm, long projectId); List<Group> groupVariations(VcfFilterForm filterForm, long projectId, String groupByField); List<Group> groupVariations(VcfFilterForm filterForm, String groupByField); IndexSearchResult<VcfIndexEntry> filterVariations(VcfFilterForm filterForm); IndexSearchResult searchFeaturesInProject(String featureId, long projectId); IndexSearchResult searchFeaturesByReference(String featureId, long referenceId); VcfFilterInfo loadVcfFilterInfoForProject(long projectId); void buildIndexForFile(FeatureFile featureFile); Set<String> fetchGeneIds(int start, int end, List<GeneFile> geneFiles, Chromosome chromosome); void writeLuceneIndexForFile(final FeatureFile featureFile,
            final List<? extends FeatureIndexEntry> entries,
            VcfFilterInfo vcfFilterInfo); void makeIndexForBedReader(BedFile bedFile, AbstractFeatureReader<NggbBedFeature, LineIterator> reader,
                                      Map<String, Chromosome> chromosomeMap); void makeIndexForVcfReader(VcfFile vcfFile, FeatureReader<VariantContext> reader, List<GeneFile> geneFiles,
                                       Map<String, Chromosome> chromosomeMap, VcfFilterInfo info); void processGeneFile(GeneFile geneFile, final Map<String, Chromosome> chromosomeMap,
            boolean full); void addGeneFeatureToIndex(List<FeatureIndexEntry> allEntries, GeneFeature feature,
                                     Map<String, Chromosome> chromosomeMap);  }