Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/org/kpmp/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public List<ClusterHierarchy> getClusterHieararchies(@Argument String cellType)
return clusterHierarchyService.findClustersByCellType(cellType);
}

@QueryMapping
public List<ClusterHierarchy> 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 {
Expand Down Expand Up @@ -184,6 +189,17 @@ public List<String> dataTypesForConcept(@Argument String geneSymbol, @Argument S

}

@QueryMapping
public List<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,11 +14,48 @@ interface ClusterHiearchyRepository extends CrudRepository<ClusterHierarchy, Clu
@Cacheable("clusterHierarchy")
List<ClusterHierarchy> 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<ClusterHierarchy> 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<ClusterHierarchy> 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<ClusterHierarchy> 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<ClusterHierarchy> findByCellType(@Param("cell_type") String cellType);

@Cacheable("clusterHierarchyCluster")
@Query(value = "CALL cluster_hierarchy_by_cluster_sp(:cluster);", nativeQuery = true)
ClusterHierarchy findFirstByClusterOrRegion(String cluster);

}
130 changes: 130 additions & 0 deletions src/main/java/org/kpmp/cellTypeSummary/ClusterHierarchy2025.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,69 @@ public List<String> findDataTypesByClusterName(String clusterName) {
}
return dataTypesRepresented;
}

public List<ClusterHierarchy> findClustersByCellType2025(String cellType) {

ArrayList<ClusterHierarchy> result = new ArrayList<>();
Map<String, ClusterHierarchy> clusterToHierarchy = new HashMap<>();
List<ClusterHierarchy> clusterHierarchiesRNASeq = clusterHierarchyRepo.findRnaSeqByCellTypeOrRegion(cellType);
List<ClusterHierarchy> clusterHierarchiesRegional = clusterHierarchyRepo.findRTRPByCellTypeOrRegion(cellType);
List<ClusterHierarchy> 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<ClusterHierarchy>() {
@Override
public int compare(ClusterHierarchy a, ClusterHierarchy b) {
return a.getCellTypeOrder().compareTo(b.getCellTypeOrder());
}
});
return result;
}

public List<String> findDataTypesByClusterName2025(String clusterName) {
List<String> 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;
}
}
4 changes: 3 additions & 1 deletion src/main/resources/graphql/knowledge_environment.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading