diff --git a/src/main/java/org/kpmp/QueryController.java b/src/main/java/org/kpmp/QueryController.java index 9a0bd55..dfddaf0 100755 --- a/src/main/java/org/kpmp/QueryController.java +++ b/src/main/java/org/kpmp/QueryController.java @@ -123,6 +123,11 @@ public List getClusterHieararchies(@Argument String cellType) return clusterHierarchyService.findClustersByCellType(cellType); } + @QueryMapping + public List getClusterHieararchies2025(@Argument String cellType) throws IOException { + return clusterHierarchyService.findClustersByCellType2025(cellType); + } + @QueryMapping public PlotData getUmapPlotData(@Argument String dataType, @Argument String geneSymbol, @Argument String enrollmentCategory) throws Exception { try { @@ -184,6 +189,17 @@ public List dataTypesForConcept(@Argument String geneSymbol, @Argument S } + @QueryMapping + public List dataTypesForConcept2025(@Argument String geneSymbol, @Argument String clusterName) throws Exception { + if (geneSymbol != null && !geneSymbol.isEmpty()) { + return geneExpressionSummaryService.findDataTypesByGene(geneSymbol); + } else if (clusterName != null && !clusterName.isEmpty()) { + return clusterHierarchyService.findDataTypesByClusterName2025(clusterName); + } + throw new Exception("Must provide either a cluster or a gene symbol."); + + } + @QueryMapping public RTExpressionByEnrollmentCategory getRTGeneExpressionByEnrollment(@Argument String comparisonType, @Argument String geneSymbol) throws Exception { diff --git a/src/main/java/org/kpmp/cellTypeSummary/ClusterHiearchyRepository.java b/src/main/java/org/kpmp/cellTypeSummary/ClusterHiearchyRepository.java index 59b1da1..1a6701f 100755 --- a/src/main/java/org/kpmp/cellTypeSummary/ClusterHiearchyRepository.java +++ b/src/main/java/org/kpmp/cellTypeSummary/ClusterHiearchyRepository.java @@ -2,6 +2,7 @@ import java.util.List; +import org.kpmp.cluster.Cluster; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; @@ -13,11 +14,48 @@ interface ClusterHiearchyRepository extends CrudRepository findAll(); - @Cacheable("clusterHierarchyCt") + @Cacheable("clusterHierarchyRNA2025ByCellType") + @Query(value = "SELECT ch.*, 'N' AS is_rt, 'N' AS is_rp, 'Y' AS is_single_cell, 'Y' as is_single_nuc FROM cluster_hierarchy_2025_v ch WHERE ch.cell_type = :cell_type OR ch.structure_region = :cell_type OR ch.structure_subregion = :cell_type " + + "ORDER BY ch.cell_type_order ASC", nativeQuery = true) + List findRnaSeqByCellTypeOrRegion(@Param("cell_type") String cell_type); + + @Cacheable("clusterHierarchyRP2025ByCellType") + @Query(value = "SELECT * FROM (SELECT rt.*, 0 AS cluster_id, rt.cell_type AS cluster_name, 'Y' AS is_rt, 'Y' AS is_rp, 'N' AS is_single_cell, 'N' as is_single_nuc FROM rt_segment_hierarchy_2025_v rt " + + "WHERE rt.abbreviation <> 'Ti' AND rt.abbreviation <> 'INT' AND rt.structure_subregion IS NULL AND (rt.cell_type = :cell_type OR rt.structure_region = :cell_type OR rt.structure_subregion = :cell_type) " + + "UNION ALL " + + "SELECT rt.*, 0 AS cluster_id, NULL AS `cluster_name`, 'Y' AS is_rt, 'N' AS is_rp, 'N' AS is_single_cell, 'N' as is_single_nuc FROM rt_segment_hierarchy_2025_v rt " + + "WHERE rt.abbreviation <> 'Ti' AND (rt.cell_type = :cell_type OR rt.structure_region = :cell_type OR rt.structure_subregion = :cell_type)) x ORDER BY x.cell_type_order ASC", nativeQuery = true) + List findRTRPByCellTypeOrRegion(@Param("cell_type") String cell_type); + + // This query gets the regions or subregions that RT/RP data are in given a more specific cell type. + @Cacheable("clusterHierarchy2025ByCellTypeRegionsSubregions") + @Query(value = "SELECT * FROM (SELECT v1.*, 0 AS cluster_id, v1.cell_type AS cluster_name, 'Y' AS is_rt, 'Y' AS is_rp, 'N' AS is_single_cell, 'N' as is_single_nuc FROM rt_segment_hierarchy_2025_v v1 " + + "WHERE v1.cell_type IS NULL AND v1.structure_subregion IS NULL AND v1.structure_region IN (" + + "SELECT v2.structure_region FROM cell_type_2025 v2 " + + "WHERE v2.cell_type = :cell_type OR " + + "v2.structure_subregion = :cell_type) " + + "UNION ALL " + + "SELECT v1.*, 0 AS cluster_id, v1.cell_type AS cluster_name, 'Y' AS is_rt, 'Y' AS is_rp, 'N' AS is_single_cell, 'N' as is_single_nuc FROM knowledge_environment.rt_segment_hierarchy_2025_v v1 " + + "WHERE v1.cell_type IS NULL AND v1.structure_subregion IN ( " + + "SELECT v2.structure_subregion FROM cell_type_2025 v2 " + + "WHERE v2.cell_type = :cell_type OR " + + "v2.structure_subregion = :cell_type)) x GROUP BY x.cluster_name, x.structure_subregion, x.structure_region ORDER BY x.cell_type_order ASC", nativeQuery = true) + List findRTRPParentRegions(@Param("cell_type") String cell_type); + + @Query(value = "SELECT v1.*, null as cell_type_order FROM cluster_hierarchy_2025_v v1 " + + "WHERE v1.cluster_name = cluster " + + "UNION ALL " + + "SELECT v1.*, null as cell_type_order FROM rt_segment_hierarchy_2025_v v1 " + + "WHERE v1.cell_type IS NULL AND (v1.structure_subregion = cluster OR v1.structure_region = cluster) LIMIT 1", nativeQuery = true) + ClusterHierarchy findFirstByClusterOrRegion2025(@Param("cluster_name") String cell_type); + + + @Cacheable("clusterHierarchyCt") @Query(value = "CALL cluster_hierarchy_sp(:cell_type);", nativeQuery = true) List findByCellType(@Param("cell_type") String cellType); @Cacheable("clusterHierarchyCluster") @Query(value = "CALL cluster_hierarchy_by_cluster_sp(:cluster);", nativeQuery = true) ClusterHierarchy findFirstByClusterOrRegion(String cluster); + } diff --git a/src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchy2025.java b/src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchy2025.java new file mode 100644 index 0000000..ecd1e8d --- /dev/null +++ b/src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchy2025.java @@ -0,0 +1,130 @@ +package org.kpmp.cellTypeSummary; + +import jakarta.persistence.*; +import org.springframework.lang.Nullable; + +import java.io.Serializable; + +@Entity +@Table(name = "cluster_hierarchy_v") +@IdClass(ClusterHierarchyId.class) +public class ClusterHierarchy2025 implements Serializable { + + private static final long serialVersionUID = -7707637379989017634L; + @Id + @Column(name = "cell_type_id") + private int cellTypeId; + @Id + @Column(name = "cluster_id") + private int clusterId; + @Column(name = "structure_region") + private String structureRegion; + @Column(name = "structure_subregion") + private String structureSubregion; + @Column(name = "cluster_name") + private String clusterName; + @Column(name = "is_single_cell") + private String isSingleCellCluster; + @Column(name = "is_single_nuc") + private String isSingleNucCluster; + @Column(name = "is_rt") + private String isRegionalTranscriptomics; + @Column(name = "is_rp") + private String isRegionalProteomics; + @Column(name = "cell_type") + private String cellType; + @Column(name = "cell_type_order") + private Double cellTypeOrder; + + public int getCellTypeId() { + return cellTypeId; + } + + public void setCellTypeId(int cellTypeId) { + this.cellTypeId = cellTypeId; + } + + @Nullable + public int getClusterId() { + return clusterId; + } + + public void setClusterId(int clusterId) { + this.clusterId = clusterId; + } + + public String getStructureRegion() { + return structureRegion; + } + + public void setStructureRegion(String structureRegion) { + this.structureRegion = structureRegion; + } + + @Nullable + public String getStructureSubregion() { + return structureSubregion; + } + + public void setStructureSubregion(String structureSubregion) { + this.structureSubregion = structureSubregion; + } + + @Nullable + public String getClusterName() { + return clusterName; + } + + public void setClusterName(String clusterName) { + this.clusterName = clusterName; + } + + public String getIsSingleCellCluster() { + return isSingleCellCluster; + } + + public void setIsSingleCellCluster(String isSingleCellCluster) { + this.isSingleCellCluster = isSingleCellCluster; + } + + public String getIsSingleNucCluster() { + return isSingleNucCluster; + } + + public void setIsSingleNucCluster(String isSingleNucCluster) { + this.isSingleNucCluster = isSingleNucCluster; + } + + public String getIsRegionalTranscriptomics() { + return isRegionalTranscriptomics; + } + + public void setIsRegionalTranscriptomics(String isRegionalTranscriptomics) { + this.isRegionalTranscriptomics = isRegionalTranscriptomics; + } + + public String getIsRegionalProteomics() { + return isRegionalProteomics; + } + + public void setIsRegionalProteomics(String isRegionalProteomics) { + this.isRegionalProteomics = isRegionalProteomics; + } + @Nullable + public Double getCellTypeOrder() { + return cellTypeOrder; + } + + public void setCellTypeOrder(Double cellTypeOrder) { + this.cellTypeOrder = cellTypeOrder; + } + + @Nullable + public String getCellType() { + return cellType; + } + + public void setCellType(String cellType) { + this.cellType = cellType; + } +} diff --git a/src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchyService.java b/src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchyService.java index b1bf6f6..61af074 100755 --- a/src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchyService.java +++ b/src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchyService.java @@ -80,4 +80,69 @@ public List findDataTypesByClusterName(String clusterName) { } return dataTypesRepresented; } + + public List findClustersByCellType2025(String cellType) { + + ArrayList result = new ArrayList<>(); + Map clusterToHierarchy = new HashMap<>(); + List clusterHierarchiesRNASeq = clusterHierarchyRepo.findRnaSeqByCellTypeOrRegion(cellType); + List clusterHierarchiesRegional = clusterHierarchyRepo.findRTRPByCellTypeOrRegion(cellType); + List clusterHierarchiesParentRegions = clusterHierarchyRepo.findRTRPParentRegions(cellType); + clusterHierarchiesRNASeq.addAll(clusterHierarchiesRegional); + clusterHierarchiesRNASeq.addAll(clusterHierarchiesParentRegions); + + for (ClusterHierarchy clusterHierarchy : clusterHierarchiesRNASeq) { + String clusterName = clusterHierarchy.getClusterName(); + if (clusterToHierarchy.containsKey(clusterName)) { + if (clusterName == null) { + result.add(clusterHierarchy); + } else if (clusterName.equals(clusterHierarchy.getCellType())) { + clusterToHierarchy.put(clusterName, clusterHierarchy); + } + } else { + clusterToHierarchy.put(clusterName, clusterHierarchy); + } + } + if (cellType.equals("Tubules") || cellType.equals("Interstitium")) { + ClusterHierarchy tiCluster = new ClusterHierarchy(); + tiCluster.setStructureRegion("Tubulo-interstitium"); + tiCluster.setIsSingleCellCluster("N"); + tiCluster.setIsSingleNucCluster("N"); + tiCluster.setIsRegionalProteomics("Y"); + tiCluster.setIsRegionalTranscriptomics("Y"); + tiCluster.setCellTypeOrder(0.01); + result.add(tiCluster); + } + result.addAll(clusterToHierarchy.values()); + Collections.sort(result, new Comparator() { + @Override + public int compare(ClusterHierarchy a, ClusterHierarchy b) { + return a.getCellTypeOrder().compareTo(b.getCellTypeOrder()); + } + }); + return result; + } + + public List findDataTypesByClusterName2025(String clusterName) { + List dataTypesRepresented = new ArrayList<>(); + if (clusterName.equals("Tubulo-interstitium")) { + dataTypesRepresented.add(FullDataTypeEnum.REGIONAL_PROTEOMICS.getAbbreviation()); + dataTypesRepresented.add(FullDataTypeEnum.REGIONAL_TRANSCRIPTOMICS.getAbbreviation()); + } else { + ClusterHierarchy clustersInDataTypes = clusterHierarchyRepo.findFirstByClusterOrRegion2025(clusterName); + if (clustersInDataTypes.getIsSingleCellCluster().equalsIgnoreCase("Y")) { + dataTypesRepresented.add(FullDataTypeEnum.SINGLE_CELL.getAbbreviation()); + } + if (clustersInDataTypes.getIsSingleNucCluster().equalsIgnoreCase("Y")) { + dataTypesRepresented.add(FullDataTypeEnum.SINGLE_NUCLEUS.getAbbreviation()); + } + if (clustersInDataTypes.getIsRegionalTranscriptomics().equalsIgnoreCase("Y")) { + dataTypesRepresented.add(FullDataTypeEnum.REGIONAL_TRANSCRIPTOMICS.getAbbreviation()); + } + if (clustersInDataTypes.getIsRegionalProteomics().equalsIgnoreCase("Y")) { + dataTypesRepresented.add(FullDataTypeEnum.REGIONAL_PROTEOMICS.getAbbreviation()); + } + } + return dataTypesRepresented; + } } diff --git a/src/main/resources/graphql/knowledge_environment.graphqls b/src/main/resources/graphql/knowledge_environment.graphqls index f2f04c9..77465dc 100755 --- a/src/main/resources/graphql/knowledge_environment.graphqls +++ b/src/main/resources/graphql/knowledge_environment.graphqls @@ -4,9 +4,11 @@ type Query { geneExpressionSummary(dataType: String, geneSymbol: String, cellType: String, enrollmentCategory: String) : [GeneExpressionSummary] geneExpressionSummary2025(dataType: String, geneSymbol: String, cellType: String, enrollmentCategory: String) : [GeneExpressionSummary2025] getClusterHieararchies(cellType: String!): [ClusterHierarchy] - getUmapPlotData(dataType: String!, geneSymbol: String!, enrollmentCategory: String): PlotData + getClusterHieararchies2025(cellType: String!): [ClusterHierarchy] + getUmapPlotData(dataType: String!, geneSymbol: String!, enrollmentCategory: String): PlotData getUmapPlotData2025(dataType: String!, geneSymbol: String!, enrollmentCategory: String): PlotData2025 dataTypesForConcept(geneSymbol: String, clusterName: String): [String] + dataTypesForConcept2025(geneSymbol: String, clusterName: String): [String] getDataTypeSummaryInformation: [DataTypeSummaryInformation] getDataTypeSummaryInformation2025: [DataTypeSummaryInformation2025] getRTGeneExpressionByEnrollment(comparisonType: String, geneSymbol: String): RTGeneExpressionByEnrollment diff --git a/src/test/java/org/kpmp/cellTypeSummary/ClusterHierarchyServiceTest.java b/src/test/java/org/kpmp/cellTypeSummary/ClusterHierarchyServiceTest.java index 7deefc7..37d8c39 100755 --- a/src/test/java/org/kpmp/cellTypeSummary/ClusterHierarchyServiceTest.java +++ b/src/test/java/org/kpmp/cellTypeSummary/ClusterHierarchyServiceTest.java @@ -211,4 +211,235 @@ public void testFindDataTypesByClusterNameTi() throws Exception { assertFalse(dataTypes.contains(FullDataTypeEnum.SINGLE_CELL.getAbbreviation())); assertFalse(dataTypes.contains(FullDataTypeEnum.SINGLE_NUCLEUS.getAbbreviation())); } + + //////// 2025 Set + + @Test + public void testFindClustersByCellType2025() { + + ClusterHierarchy clusterHierarchy1 = new ClusterHierarchy(); + clusterHierarchy1.setCellType("celltype"); + clusterHierarchy1.setClusterName(null); + clusterHierarchy1.setCellTypeOrder(3.2); + ClusterHierarchy clusterHierarchy2 = new ClusterHierarchy(); + clusterHierarchy2.setCellType("celltype2"); + clusterHierarchy2.setClusterName(null); + clusterHierarchy2.setCellTypeOrder(2.0); + ClusterHierarchy clusterHierarchy3 = new ClusterHierarchy(); + clusterHierarchy3.setCellType("celltype1"); + clusterHierarchy3.setClusterName(null); + clusterHierarchy3.setCellTypeOrder(1.0); + + List hierarchiesRTRP = new ArrayList<>(Arrays.asList(clusterHierarchy1)); + List hierarchiesRNA = new ArrayList<>(Arrays.asList(clusterHierarchy2)); + List hierarchiesParent = new ArrayList<>(Arrays.asList(clusterHierarchy3)); + + when(clusterHierarchyRepo.findRTRPByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRTRP); + when(clusterHierarchyRepo.findRnaSeqByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRNA); + when(clusterHierarchyRepo.findRTRPParentRegions("cell type")).thenReturn(hierarchiesParent); + + assertEquals(3, service.findClustersByCellType2025("cell type").size()); + } + + @Test + public void testFindClustersByCellType_remvoesDups2025() { + ClusterHierarchy clusterHierarchy1 = new ClusterHierarchy(); + clusterHierarchy1.setCellType("celltype"); + clusterHierarchy1.setClusterName("cluster"); + clusterHierarchy1.setCellTypeOrder(3.2); + ClusterHierarchy clusterHierarchy2 = new ClusterHierarchy(); + clusterHierarchy2.setCellType("celltype"); + clusterHierarchy2.setClusterName("cluster"); + clusterHierarchy2.setCellTypeOrder(2.0); + ClusterHierarchy clusterHierarchy3 = new ClusterHierarchy(); + clusterHierarchy3.setCellType("cluster"); + clusterHierarchy3.setClusterName("cluster"); + clusterHierarchy3.setCellTypeOrder(1.0); + + List hierarchiesRTRP = new ArrayList<>(Arrays.asList(clusterHierarchy1)); + List hierarchiesRNA = new ArrayList<>(Arrays.asList(clusterHierarchy2)); + List hierarchiesParent = new ArrayList<>(Arrays.asList(clusterHierarchy3)); + + when(clusterHierarchyRepo.findRTRPByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRTRP); + when(clusterHierarchyRepo.findRnaSeqByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRNA); + when(clusterHierarchyRepo.findRTRPParentRegions("cell type")).thenReturn(hierarchiesParent); + + assertEquals(Arrays.asList(clusterHierarchy3), service.findClustersByCellType2025("cell type")); + } + + @Test + public void testFindClustersByCellType_remvoesDupsUnlessNull2025() { + ClusterHierarchy clusterHierarchy1 = new ClusterHierarchy(); + clusterHierarchy1.setCellType("celltype"); + clusterHierarchy1.setClusterName(null); + clusterHierarchy1.setCellTypeOrder(3.2); + ClusterHierarchy clusterHierarchy2 = new ClusterHierarchy(); + clusterHierarchy2.setCellType("celltype"); + clusterHierarchy2.setClusterName(null); + clusterHierarchy2.setCellTypeOrder(2.0); + ClusterHierarchy clusterHierarchy3 = new ClusterHierarchy(); + clusterHierarchy3.setCellType("cluster"); + clusterHierarchy3.setClusterName(null); + clusterHierarchy3.setCellTypeOrder(1.0); + + List hierarchiesRTRP = new ArrayList<>(Arrays.asList(clusterHierarchy1)); + List hierarchiesRNA = new ArrayList<>(Arrays.asList(clusterHierarchy2)); + List hierarchiesParent = new ArrayList<>(Arrays.asList(clusterHierarchy3)); + + when(clusterHierarchyRepo.findRTRPByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRTRP); + when(clusterHierarchyRepo.findRnaSeqByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRNA); + when(clusterHierarchyRepo.findRTRPParentRegions("cell type")).thenReturn(hierarchiesParent); + + + List expected = Arrays.asList(clusterHierarchy1, clusterHierarchy2, clusterHierarchy3); + + List result = service.findClustersByCellType2025("cell type"); + + assertEquals(expected.size(), result.size()); + assertEquals(true, result.containsAll(expected)); + } + + @Test + public void testFindClustersByCellType_sorts2025() { + ClusterHierarchy clusterHierarchy1 = new ClusterHierarchy(); + clusterHierarchy1.setCellType("celltype"); + clusterHierarchy1.setClusterName(null); + clusterHierarchy1.setCellTypeOrder(3.2); + ClusterHierarchy clusterHierarchy2 = new ClusterHierarchy(); + clusterHierarchy2.setCellType("celltype"); + clusterHierarchy2.setClusterName(null); + clusterHierarchy2.setCellTypeOrder(2.0); + ClusterHierarchy clusterHierarchy3 = new ClusterHierarchy(); + clusterHierarchy3.setCellType("cluster"); + clusterHierarchy3.setClusterName(null); + clusterHierarchy3.setCellTypeOrder(1.0); + + List hierarchiesRTRP = new ArrayList<>(Arrays.asList(clusterHierarchy1)); + List hierarchiesRNA = new ArrayList<>(Arrays.asList(clusterHierarchy2)); + List hierarchiesParent = new ArrayList<>(Arrays.asList(clusterHierarchy3)); + + when(clusterHierarchyRepo.findRTRPByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRTRP); + when(clusterHierarchyRepo.findRnaSeqByCellTypeOrRegion("cell type")).thenReturn(hierarchiesRNA); + when(clusterHierarchyRepo.findRTRPParentRegions("cell type")).thenReturn(hierarchiesParent); + + assertEquals(Arrays.asList(clusterHierarchy3, clusterHierarchy2, clusterHierarchy1), service.findClustersByCellType2025("cell type")); + } + + @Test + public void testFindDataTypesByClusterNameWhenBothY2025() throws Exception { + ClusterHierarchy clusterHierarchy = new ClusterHierarchy(); + clusterHierarchy.setIsSingleCellCluster("Y"); + clusterHierarchy.setIsSingleNucCluster("Y"); + clusterHierarchy.setIsRegionalTranscriptomics("N"); + clusterHierarchy.setIsRegionalProteomics("N"); + when(clusterHierarchyRepo.findFirstByClusterOrRegion2025("cluster")).thenReturn(clusterHierarchy); + + List dataTypes = service.findDataTypesByClusterName2025("cluster"); + + assertEquals(2, dataTypes.size()); + assertEquals(Arrays.asList(FullDataTypeEnum.SINGLE_CELL.getAbbreviation(), + FullDataTypeEnum.SINGLE_NUCLEUS.getAbbreviation()), dataTypes); + verify(clusterHierarchyRepo).findFirstByClusterOrRegion2025("cluster"); + } + + @Test + public void testFindDataTypesByClusterNameWhenSingleCellY2025() throws Exception { + ClusterHierarchy clusterHierarchy = new ClusterHierarchy(); + clusterHierarchy.setIsSingleCellCluster("Y"); + clusterHierarchy.setIsSingleNucCluster("N"); + clusterHierarchy.setIsRegionalTranscriptomics("N"); + clusterHierarchy.setIsRegionalProteomics("N"); + when(clusterHierarchyRepo.findFirstByClusterOrRegion2025("cluster")).thenReturn(clusterHierarchy); + + List dataTypes = service.findDataTypesByClusterName2025("cluster"); + + assertEquals(1, dataTypes.size()); + assertEquals(Arrays.asList(FullDataTypeEnum.SINGLE_CELL.getAbbreviation()), dataTypes); + verify(clusterHierarchyRepo).findFirstByClusterOrRegion2025("cluster"); + } + + @Test + public void testFindDataTypesByClusterNameWhenSingleNucY2025() throws Exception { + ClusterHierarchy clusterHierarchy = new ClusterHierarchy(); + clusterHierarchy.setIsSingleCellCluster("N"); + clusterHierarchy.setIsSingleNucCluster("y"); + clusterHierarchy.setIsRegionalTranscriptomics("N"); + clusterHierarchy.setIsRegionalProteomics("N"); + when(clusterHierarchyRepo.findFirstByClusterOrRegion2025("cluster")).thenReturn(clusterHierarchy); + + List dataTypes = service.findDataTypesByClusterName2025("cluster"); + + assertEquals(1, dataTypes.size()); + assertEquals(Arrays.asList(FullDataTypeEnum.SINGLE_NUCLEUS.getAbbreviation()), dataTypes); + verify(clusterHierarchyRepo).findFirstByClusterOrRegion2025("cluster"); + } + + @Test + public void testFindDataTypesByClusterNameWhenNeitherY2025() throws Exception { + ClusterHierarchy clusterHierarchy = new ClusterHierarchy(); + clusterHierarchy.setIsSingleCellCluster("N"); + clusterHierarchy.setIsSingleNucCluster("N"); + clusterHierarchy.setIsRegionalTranscriptomics("N"); + clusterHierarchy.setIsRegionalProteomics("N"); + when(clusterHierarchyRepo.findFirstByClusterOrRegion2025("cluster")).thenReturn(clusterHierarchy); + + List dataTypes = service.findDataTypesByClusterName2025("cluster"); + + assertEquals(0, dataTypes.size()); + verify(clusterHierarchyRepo).findFirstByClusterOrRegion2025("cluster"); + } + + @Test + public void testFindDataTypesByClusterNameWhenRTY2025() throws Exception { + ClusterHierarchy clusterHierarchy = new ClusterHierarchy(); + clusterHierarchy.setIsSingleCellCluster("N"); + clusterHierarchy.setIsSingleNucCluster("N"); + clusterHierarchy.setIsRegionalTranscriptomics("Y"); + clusterHierarchy.setIsRegionalProteomics("N"); + when(clusterHierarchyRepo.findFirstByClusterOrRegion2025("cluster")).thenReturn(clusterHierarchy); + + List dataTypes = service.findDataTypesByClusterName2025("cluster"); + + assertEquals(1, dataTypes.size()); + verify(clusterHierarchyRepo).findFirstByClusterOrRegion2025("cluster"); + } + + + @Test + public void testFindDataTypesByClusterNameWhenRPY2025() throws Exception { + ClusterHierarchy clusterHierarchy = new ClusterHierarchy(); + clusterHierarchy.setIsSingleCellCluster("N"); + clusterHierarchy.setIsSingleNucCluster("N"); + clusterHierarchy.setIsRegionalTranscriptomics("N"); + clusterHierarchy.setIsRegionalProteomics("Y"); + when(clusterHierarchyRepo.findFirstByClusterOrRegion2025("cluster")).thenReturn(clusterHierarchy); + + List dataTypes = service.findDataTypesByClusterName2025("cluster"); + + assertEquals(1, dataTypes.size()); + assertEquals(Arrays.asList("rp"), dataTypes); + verify(clusterHierarchyRepo).findFirstByClusterOrRegion2025("cluster"); + } + + @Test + public void testFindClustersByCellTypeTubulesOrInterstitium2025() throws Exception { + List clusterHierarchies = new ArrayList<>(); + when(clusterHierarchyRepo.findRTRPByCellTypeOrRegion("cell type")).thenReturn(clusterHierarchies); + when(clusterHierarchyRepo.findRnaSeqByCellTypeOrRegion("cell type")).thenReturn(clusterHierarchies); + when(clusterHierarchyRepo.findRTRPParentRegions("cell type")).thenReturn(clusterHierarchies); + List clusters = service.findClustersByCellType2025("Tubules"); + assertEquals("Tubulo-interstitium", clusters.get(0).getStructureRegion()); + List clusters2 = service.findClustersByCellType2025("Interstitium"); + assertEquals("Tubulo-interstitium", clusters2.get(0).getStructureRegion()); + } + + @Test + public void testFindDataTypesByClusterNameTi2025() throws Exception { + List dataTypes = service.findDataTypesByClusterName2025("Tubulo-interstitium"); + assertTrue(dataTypes.contains(FullDataTypeEnum.REGIONAL_PROTEOMICS.getAbbreviation())); + assertTrue(dataTypes.contains(FullDataTypeEnum.REGIONAL_TRANSCRIPTOMICS.getAbbreviation())); + assertFalse(dataTypes.contains(FullDataTypeEnum.SINGLE_CELL.getAbbreviation())); + assertFalse(dataTypes.contains(FullDataTypeEnum.SINGLE_NUCLEUS.getAbbreviation())); + } + }