@Test @Transactional(propagation = Propagation.REQUIRED) public void sortingTest() throws IOException { VcfFilterForm vcfFilterForm = new VcfFilterForm(); vcfFilterForm.setPage(1); vcfFilterForm.setPageSize(10); for (IndexSortField sortField : IndexSortField.values()) { vcfFilterForm.setOrderBy(singletonList(new VcfFilterForm.OrderBy(sortField.name(), false))); IndexSearchResult<VcfIndexEntry> entryList = featureIndexManager.filterVariations(vcfFilterForm, testProject.getId()); Assert.assertFalse(entryList.getEntries().isEmpty()); Assert.assertEquals(vcfFilterForm.getPageSize().intValue(), entryList.getEntries().size()); } checkSorted(IndexSortField.START_INDEX.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> e.getStartIndex() > p.getStartIndex())), testProject.getId()); checkSorted(IndexSortField.END_INDEX.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> e.getEndIndex() > p.getEndIndex())), testProject.getId()); checkSorted(IndexSortField.CHROMOSOME_NAME.name(), false, (page, seenEntries) -> page.stream().anyMatch(p -> seenEntries.stream().anyMatch( e -> e.getChromosome().getName().compareTo(p.getChromosome().getName()) > 0)), testProject.getId()); checkSorted(IndexSortField.GENE_NAME.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> StringUtils.isNotBlank(e.getGeneName()) && StringUtils.isNotBlank(p.getGeneName()) && e.getGeneName().compareTo(p.getGeneName()) > 0)), testProject.getId()); checkSorted(IndexSortField.GENE_NAME.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> StringUtils.isNotBlank(e.getGeneNames()) && StringUtils.isNotBlank(p.getGeneNames()) && e.getGeneNames().compareTo(p.getGeneNames()) > 0)), testProject.getId()); checkSorted(IndexSortField.GENE_ID.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> StringUtils.isNotBlank(e.getGene()) && StringUtils.isNotBlank(p.getGene()) && e.getGene().compareTo(p.getGene()) > 0)), testProject.getId()); checkSorted(IndexSortField.GENE_ID.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> StringUtils.isNotBlank(e.getGeneIds()) && StringUtils.isNotBlank(p.getGeneIds()) && e.getGeneIds().compareTo(p.getGeneIds()) > 0)), testProject.getId()); checkSorted(IndexSortField.VARIATION_TYPE.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> e.getVariationType().name().compareTo( p.getVariationType().name()) > 0)), testProject.getId()); checkSorted(IndexSortField.FILTER.name(), false, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> (e.getFailedFilter() != null ? e.getFailedFilter() : "") .compareTo(p.getFailedFilter() != null ? p.getFailedFilter() : "") > 0)), testProject.getId()); VcfFilterInfo info = vcfManager.getFiltersInfo(singletonList(testVcf.getId())); for (InfoItem item : info.getInfoItems()) { switch (item.getType()) { case Integer: checkSorted(item.getName(), false, (page, seenEntries) -> page.stream().anyMatch(p -> seenEntries.stream().anyMatch( e -> e.getInfo().containsKey(item.getName()) && e.getInfo().get(item.getName()) != null && e.getInfo().containsKey(item.getName()) && p.getInfo().get(item.getName()) != null && (e.getInfo().get(item.getName()).toString()).compareTo( p.getInfo().get(item.getName()).toString()) > 0 )), testProject.getId(), singletonList(item.getName())); break; case Float: checkSorted(item.getName(), false, (page, seenEntries) -> page.stream().anyMatch(p -> seenEntries.stream().anyMatch( e -> e.getInfo().containsKey(item.getName()) && e.getInfo().get(item.getName()) != null && e.getInfo().containsKey(item.getName()) && p.getInfo().get(item.getName()) != null && (e.getInfo().get(item.getName()).toString()).compareTo( p.getInfo().get(item.getName()).toString()) > 0 )), testProject.getId(), singletonList(item.getName())); break; default: checkSorted(item.getName(), false, (page, seenEntries) -> page.stream().anyMatch(p -> seenEntries.stream().anyMatch( e -> e.getInfo().get(item.getName()) != null && p.getInfo().get(item.getName()) != null && e.getInfo().get(item.getName()).toString().compareTo( p.getInfo().get(item.getName()).toString()) > 0)), testProject.getId(), singletonList(item.getName())); } } checkSorted(IndexSortField.START_INDEX.name(), true, (page, seenEntries) -> page.stream().anyMatch( p -> seenEntries.stream().anyMatch(e -> e.getStartIndex() < p.getStartIndex())), testProject.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);  }