Skip to content

Commit

Permalink
Merge pull request #97 from KPMP/develop
Browse files Browse the repository at this point in the history
Release v2.1
  • Loading branch information
rlreamy authored Sep 30, 2023
2 parents 77bb7e4 + 8f07dcf commit a346c27
Show file tree
Hide file tree
Showing 18 changed files with 368 additions and 58 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ If you have already followed these steps and are still having trouble connecting
1. Start up your atlas/knowledge-environment server
2. Open a tool like GraphQLPlayground and connect to "http://localhost:3030/graphql"
3. Write and execute your query

# Buyer BEWARE
Notes to ourselves about the non-dynamic nature of some things in the app (this is not exhaustive)

1. The endpoint `getDataTypeInformationByParticipant` is only partially dynamic. If we add new data types to the Spatial Viewer, it will pick those up without an issue, BUT if/when we add new data types to the Explorer, we will need to update the code that gets counts for data types in Explorer to include the new one.
25 changes: 16 additions & 9 deletions src/main/java/org/kpmp/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
import org.kpmp.dataSummary.AtlasRepoSummaryResult;
import org.kpmp.dataSummary.DataSummaryService;
import org.kpmp.dataSummary.DataTypeSummary;
import org.kpmp.gene.GeneService;
import org.kpmp.gene.MyGeneInfoHit;
import org.kpmp.geneExpression.RTExpressionByTissueType;
import org.kpmp.geneExpression.RTExpressionData;
import org.kpmp.geneExpression.RTExpressionDataService;
import org.kpmp.geneExpressionSummary.GeneExpressionSummary;
import org.kpmp.geneExpressionSummary.GeneExpressionSummaryService;
import org.kpmp.participant.ParticipantDataTypeSummary;
import org.kpmp.participant.ParticipantRepoDataTypeInformation;
import org.kpmp.participant.ParticipantRepoDataTypeSummary;
import org.kpmp.participant.ParticipantService;
import org.kpmp.participant.ParticipantSummaryDataset;
import org.kpmp.participant.ParticipantTissueTypeSummary;
Expand All @@ -36,7 +36,6 @@
@Component
public class Query implements GraphQLQueryResolver {

private GeneService geneService;
private AutocompleteService autocompleteService;
private CellTypeService cellTypeService;
private GeneExpressionSummaryService geneExpressionSummaryService;
Expand All @@ -48,12 +47,11 @@ public class Query implements GraphQLQueryResolver {
private Logger logger = LoggerFactory.getLogger(Query.class);

@Autowired
public Query(GeneService geneService, AutocompleteService autocompleteService, CellTypeService cellTypeService,
public Query(AutocompleteService autocompleteService, CellTypeService cellTypeService,
UmapDataService umapService, GeneExpressionSummaryService geneExpressionSummaryService,
DataSummaryService dataSummaryService, ClusterHierarchyService clusterHierarchyService,
RTExpressionDataService rtExpressionDataService, ParticipantService participantService) {

this.geneService = geneService;
this.autocompleteService = autocompleteService;
this.cellTypeService = cellTypeService;
this.umapService = umapService;
Expand All @@ -64,10 +62,6 @@ public Query(GeneService geneService, AutocompleteService autocompleteService, C
this.participantService = participantService;
}

public List<MyGeneInfoHit> genes(String symbol) throws IOException, Exception {
return geneService.querySymbolAndAlias(symbol);
}

public List<AutocompleteResult> autocomplete(String searchTerm) throws IOException, Exception {
return autocompleteService.query(searchTerm);
}
Expand Down Expand Up @@ -152,6 +146,10 @@ public ParticipantDataTypeSummary getDataTypeInformationByParticipant(String red
return participantService.getExperimentCounts(redcapId);
}

public ParticipantRepoDataTypeSummary getRepoDataTypeInformationByParticipant(String redcapId) {
return participantService.getDataTypeCounts(redcapId);
}

public ParticipantSummaryDataset participantSummaryDataset(String redcap_id) throws Exception {
try {
return participantService.getParticipantSummaryDataset(redcap_id);
Expand All @@ -168,6 +166,15 @@ public ParticipantSummaryDataset participantClinicalDataset(String redcap_id) th
return this.participantSummaryDataset(redcap_id);
}

public ParticipantRepoDataTypeInformation getTotalParticipantFilesCount(String redcap_id) throws Exception {
try {
return this.participantService.getTotalFilesCount(redcap_id);
} catch (Exception e) {
logger.error(e.getMessage());
throw e;
}
}

public List<ParticipantTissueTypeSummary> getTissueTypeSummaryData() throws Exception {
try {
return participantService.getTissueData();
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/org/kpmp/cache/CacheController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.kpmp.cache;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;

@Controller
public class CacheController {

@Autowired
private CacheManager cacheManager;

@RequestMapping(value = "/v1/clearCache", method = RequestMethod.GET)
public @ResponseBody CacheResponse clearCache(){
Collection<String> cacheNames = cacheManager.getCacheNames();
CacheResponse clearCacheResponse = new CacheResponse();
clearCacheResponse.setMessage("Caches successfully cleared!");
for(String name:cacheNames){
if (cacheManager.getCache(name) != null) {
cacheManager.getCache(name).clear();
} else {
clearCacheResponse.setMessage("There was a problem getting the " + name + " cache.");
break;
}
}
clearCacheResponse.setCacheNames(cacheNames);
return clearCacheResponse;
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/kpmp/cache/CacheResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.kpmp.cache;

import java.util.Collection;

public class CacheResponse {

private String message;
private Collection<String> cacheNames;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public Collection<String> getCacheNames() {
return cacheNames;
}

public void setCacheNames(Collection<String> cacheNames) {
this.cacheNames = cacheNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ public int hashCode() {
public boolean equals(Object obj) {
if (obj instanceof AtlasRepoSummaryLinkInformation) {
final AtlasRepoSummaryLinkInformation other = (AtlasRepoSummaryLinkInformation) obj;
return new EqualsBuilder().append(linkType, other.getLinkType()).append(linkValue, other.getLinkValue())
.isEquals();
} else {
return new EqualsBuilder().append(linkType, other.getLinkType()).append(linkValue, other.getLinkValue()).isEquals();
}
else {
return false;
}

}

}
20 changes: 20 additions & 0 deletions src/main/java/org/kpmp/dataSummary/DataSummaryRepository.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.kpmp.dataSummary;

import java.util.List;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
Expand Down Expand Up @@ -35,4 +37,22 @@ public interface DataSummaryRepository extends CrudRepository<DataSummaryValue,
@Cacheable("dataParticipantSvLinkDataTypeCount")
@Query(value = "SELECT count(*) from sv_link_v WHERE data_type= :data_type AND redcap_id= :redcap_id", nativeQuery = true)
Integer getParticipantSvLinkDataTypeCount(@Param("redcap_id") String redcapId, @Param("data_type") String dataType);

@Cacheable("dataParticipantRepoFileDataTypeCount")
@Query(value = "SELECT count(*) from (SELECT distinct(dl_file_id) FROM repo_file_v WHERE data_type= :data_type AND redcap_id= :redcap_id) a", nativeQuery = true)
Integer getParticipantRepoFileDataTypeCount(@Param("redcap_id") String redcapId, @Param("data_type") String dataType);

@Cacheable("repoDataTypes")
@Query(value = "SELECT distinct(data_type) FROM repository_summary_v ORDER BY data_type ASC", nativeQuery = true)
List<String> getRepoDataTypes();

@Cacheable("participantIDFromRedcapID")
@Query(value = "SELECT participant_id FROM participant WHERE redcap_id= :redcap_id LIMIT 1", nativeQuery = true)
String getParticipantIDString(@Param("redcap_id") String redcapId);

@Cacheable("participantTotalFileCount")
@Query(value = "SELECT count(DISTINCT fp.file_id) FROM file_participant fp JOIN ar_file_info ar ON fp.file_id = ar.file_id "
+ "WHERE fp.participant_id= :participant_id AND ar.release_sunset_version IS NULL", nativeQuery = true)
Integer getParticipantTotalFileCount(@Param("participant_id") String participantId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class ParticipantDataTypeSummary {
private List<ParticipantDataTypeInformation> spatialViewerDataTypes;
private List<ParticipantDataTypeInformation> explorerDataTypes;

public List<ParticipantDataTypeInformation> getSpatialViewerDataTypes() {
return spatialViewerDataTypes;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.kpmp.participant;

import org.kpmp.dataSummary.AtlasRepoSummaryLinkInformation;

public class ParticipantRepoDataTypeInformation {

private String dataType;
private Integer count;
private AtlasRepoSummaryLinkInformation linkInformation;

public ParticipantRepoDataTypeInformation(String dataType, Integer count, AtlasRepoSummaryLinkInformation linkInformation) {
this.dataType = dataType;
this.count = count;
this.linkInformation = linkInformation;
}

public String getDataType() {
return dataType;
}

public void setDataType(String dataType) {
this.dataType = dataType;
}

public Integer getCount() {
return count;
}

public void setCount(Integer count) {
this.count = count;
}

public AtlasRepoSummaryLinkInformation getLinkInformation() {
return linkInformation;
}

public void setLinkInformation(AtlasRepoSummaryLinkInformation linkInformation) {
this.linkInformation = linkInformation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.kpmp.participant;

import java.util.List;

public class ParticipantRepoDataTypeSummary {
private List<ParticipantRepoDataTypeInformation> repositoryDataTypes;

public List<ParticipantRepoDataTypeInformation> getRepositoryDataTypes() {
return repositoryDataTypes;
}

public void setRepositoryDataTypes(List<ParticipantRepoDataTypeInformation> repositoryDataTypes) {
this.repositoryDataTypes = repositoryDataTypes;
}
}
41 changes: 35 additions & 6 deletions src/main/java/org/kpmp/participant/ParticipantService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import org.kpmp.FullDataTypeEnum;
import org.kpmp.TissueTypeEnum;
import org.kpmp.dataSummary.AtlasRepoSummaryLinkInformation;
import org.kpmp.dataSummary.DataSummaryRepository;
import org.kpmp.geneExpressionSummary.RTParticipantRepository;
import org.slf4j.Logger;
Expand Down Expand Up @@ -37,22 +38,28 @@ public ParticipantService(DataSummaryRepository dataSummaryRepo, SpatialViewerTy
this.rtParticipantRepo = rtParticipantRepo;
this.participantSummaryDatasetRepository = participantSummaryDatasetRepository;
}

public ParticipantSummaryDataset getParticipantSummaryDataset(String redcapId) {
return participantSummaryDatasetRepository.findByRedcapId(redcapId);
}

public List<ParticipantTissueTypeSummary> getTissueData(){
public List<ParticipantTissueTypeSummary> getTissueData() {
List<ParticipantTissueTypeSummary> tissueData = new ArrayList<>();

tissueData.add(new ParticipantTissueTypeSummary(
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType()),
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType()),
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType()),
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType())));
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.AKI.getParticipantTissueType()),
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.CKD.getParticipantTissueType()),
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.HEALTHY_REFERENCE.getParticipantTissueType()),
participantSummaryDatasetRepository.getDataSummaryCount(TissueTypeEnum.DMR.getParticipantTissueType())));
return tissueData;
}

public ParticipantRepoDataTypeSummary getDataTypeCounts(String redcapId) {
ParticipantRepoDataTypeSummary summaryData = new ParticipantRepoDataTypeSummary();
summaryData.setRepositoryDataTypes(getRepositoryCounts(redcapId));
return summaryData;
}

public ParticipantDataTypeSummary getExperimentCounts(String redcapId) {
ParticipantDataTypeSummary summaryData = new ParticipantDataTypeSummary();
summaryData.setSpatialViewerDataTypes(getSpatialViewerCounts(redcapId));
Expand All @@ -61,6 +68,15 @@ public ParticipantDataTypeSummary getExperimentCounts(String redcapId) {
return summaryData;
}

public ParticipantRepoDataTypeInformation getTotalFilesCount(String redcapId) {
String participant_id = dataSummaryRepo.getParticipantIDString(redcapId);
Integer totalCount = dataSummaryRepo.getParticipantTotalFileCount(participant_id);
AtlasRepoSummaryLinkInformation linkInfo = new AtlasRepoSummaryLinkInformation("redcap_id", redcapId);
ParticipantRepoDataTypeInformation res = new ParticipantRepoDataTypeInformation("", totalCount, linkInfo);

return res;
}

private List<ParticipantDataTypeInformation> getExplorerCounts(String redcapId) {
List<ParticipantDataTypeInformation> explorerExperiments = new ArrayList<>();
int scCount = 0;
Expand Down Expand Up @@ -114,4 +130,17 @@ private List<ParticipantDataTypeInformation> getSpatialViewerCounts(String redca
}
return spatialViewerExperiments;
}

private List<ParticipantRepoDataTypeInformation> getRepositoryCounts(String redcapId) {
List<ParticipantRepoDataTypeInformation> repoCounts = new ArrayList<>();

List<String> repoDataTypes = dataSummaryRepo.getRepoDataTypes();
for (String repoDataType : repoDataTypes) {
Integer count = dataSummaryRepo.getParticipantRepoFileDataTypeCount(redcapId, repoDataType);
AtlasRepoSummaryLinkInformation linkInformation = new AtlasRepoSummaryLinkInformation("data_type", repoDataType);
ParticipantRepoDataTypeInformation dataTypeInfo = new ParticipantRepoDataTypeInformation(repoDataType, count, linkInformation);
repoCounts.add(dataTypeInfo);
}
return repoCounts;
}
}
20 changes: 11 additions & 9 deletions src/main/resources/knowledge_environment.graphqls
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
type Query {
genes(symbol: String): [MyGeneInfoHit]
autocomplete(searchTerm: String): [AutoCompleteResult]
cellTypeHierarchy: CellTypeHierarchy
geneExpressionSummary(dataType: String, geneSymbol: String, cellType: String, tissueType: String) : [GeneExpressionSummary]
Expand All @@ -11,8 +10,10 @@ type Query {
getRTGeneExpressionByStructure(structure: String): [RTGeneExpression]
getSummaryData: [GeneDatasetInformation]
getDataTypeInformationByParticipant(redcapId: String!): ParticipantDataTypeSummary
getRepoDataTypeInformationByParticipant(redcapId: String!): ParticipantRepoDataTypeSummary
participantSummaryDataset(redcapId: String): ParticipantSummaryDataset
participantClinicalDataset(redcapId: String): ParticipantSummaryDataset
getTotalParticipantFilesCount(redcapId: String): ParticipantRepoDataTypeInformation
getTissueTypeSummaryData: [ParticipantTissueTypeSummary]
getAtlasSummaryRows: AtlasRepoSummaryResult
}
Expand Down Expand Up @@ -52,6 +53,15 @@ type ParticipantDataTypeInformation {
isAggregatedData: Boolean
}

type ParticipantRepoDataTypeSummary {
repositoryDataTypes: [ParticipantRepoDataTypeInformation]
}

type ParticipantRepoDataTypeInformation {
dataType: String
count: Long
linkInformation: AtlasRepoSummaryLinkInformation
}

type GeneDatasetInformation {
omicsType: String
Expand All @@ -64,14 +74,6 @@ type GeneDatasetInformation {
participantCount: Long
}

type MyGeneInfoHit {
id: ID
symbol: String
name: String
entrezgene: String
alias: [String]
}

type AutoCompleteResult {
value: String
name: String
Expand Down
Loading

0 comments on commit a346c27

Please sign in to comment.