Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/make the inferred cell type options dynamic shown or disabled in marker gene heatmap dropdown menu #482

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.ac.ebi.atlas.experimentpage.markergenes;

import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -64,6 +63,7 @@ public ImmutableList<MarkerGene> getCellTypeMarkerGeneHeatmapData(String experim
.filter(markerGene -> !markerGene.cellGroupValueWhereMarker().equalsIgnoreCase("Not available"))
.collect(toImmutableList());
}

/**
* @param experimentAccession - Id of the experiment
* @param k - no of clusters
Expand All @@ -73,4 +73,9 @@ public ImmutableList<MarkerGene> getCellTypeMarkerGeneHeatmapData(String experim
public ImmutableList<MarkerGene> getMarkerGenesPerCluster(String experimentAccession, String k) {
return ImmutableList.copyOf(markerGenesDao.getMarkerGenesWithAveragesPerCluster(experimentAccession, k));
}

public Integer isMarkerGenesAvailableForTheInferredCellTypes(String experimentAccession, String cellGroupType) {
return markerGenesDao.getMarkerGenesForTheInferredCellTypes(experimentAccession, cellGroupType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@

@Repository
public class MarkerGenesDao {
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
static final String CELL_TYPE_ONTOLOGY_LABELS = "inferred cell type - ontology labels";
static final String CELL_TYPE_AUTHOR_LABELS = "inferred cell type - authors labels";

public MarkerGenesDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
}

private static final String SELECT_MARKER_GENES_WITH_AVERAGES_PER_CLUSTER =
"SELECT " +
"g.experiment_accession, " +
Expand All @@ -28,13 +22,13 @@ public MarkerGenesDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
"s.mean_expression, " +
"s.median_expression, " +
"e.expression_unit " +
"FROM " +
"FROM " +
"scxa_cell_group_marker_gene_stats s, " +
"scxa_cell_group_marker_genes m, " +
"scxa_cell_group g, " +
"scxa_cell_group h, " +
"experiment e " +
"WHERE " +
"WHERE " +
"s.cell_group_id = g.id AND " +
"s.marker_id = m.id AND " +
"m.cell_group_id = h.id AND " +
Expand All @@ -43,44 +37,16 @@ public MarkerGenesDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
"g.variable = :k AND " +
"s.expression_type = 0 AND " +
"e.accession = g.experiment_accession " +
"ORDER BY " +
"ORDER BY " +
"m.marker_probability";

public List<MarkerGene> getMarkerGenesWithAveragesPerCluster(String experimentAccession, String k) {
var namedParameters =
ImmutableMap.of(
"experiment_accession", experimentAccession,
"k", k);

return namedParameterJdbcTemplate.query(
SELECT_MARKER_GENES_WITH_AVERAGES_PER_CLUSTER,
namedParameters,
(resultSet, rowNumber) -> MarkerGene.create(
resultSet.getString("gene_id"),
resultSet.getString("k_where_marker"),
resultSet.getString("cluster_id_where_marker"),
resultSet.getDouble("marker_p_value"),
resultSet.getString("cluster_id"),
resultSet.getDouble("median_expression"),
resultSet.getDouble("mean_expression"),
resultSet.getString("expression_unit")));
}

private static final String SELECT_DISTINCT_KS_WITH_MARKER_GENES =
"SELECT DISTINCT h.variable as k_where_marker " +
"FROM scxa_cell_group_marker_genes m, scxa_cell_group h " +
"WHERE m.cell_group_id = h.id AND " +
"h.experiment_accession = :experiment_accession AND m.marker_probability < 0.05 " +
"ORDER BY k_where_marker ASC";

public List<String> getKsWithMarkerGenes(String experimentAccession) {
var namedParameters = ImmutableMap.of("experiment_accession", experimentAccession);
return namedParameterJdbcTemplate.queryForList(
SELECT_DISTINCT_KS_WITH_MARKER_GENES,
namedParameters,
String.class);
}

private static final String SELECT_MARKER_GENES_WITH_AVERAGES_PER_CELL_GROUP =
"SELECT " +
"g.experiment_accession, " +
Expand All @@ -92,13 +58,13 @@ public List<String> getKsWithMarkerGenes(String experimentAccession) {
"s.mean_expression, " +
"s.median_expression, " +
"e.expression_unit " +
"FROM " +
"FROM " +
"scxa_cell_group_marker_gene_stats s, " +
"scxa_cell_group_marker_genes m, " +
"scxa_cell_group g, " +
"scxa_cell_group h, " +
"experiment e " +
"WHERE " +
"WHERE " +
"s.cell_group_id = g.id AND " +
"s.marker_id = m.id AND " +
"m.cell_group_id = h.id AND " +
Expand All @@ -108,9 +74,84 @@ public List<String> getKsWithMarkerGenes(String experimentAccession) {
"g.value IN (:values) AND " +
"s.expression_type = 0 AND " +
"e.accession = g.experiment_accession " +
"ORDER BY " +
"ORDER BY " +
"m.marker_probability ";

private static final String SELECT_MARKER_GENES_WITH_AVERAGES_PER_CELL_GROUP_ALL =
"SELECT " +
"g.experiment_accession, " +
"m.gene_id, " +
"g.variable AS cell_group_type, " +
"h.value AS cell_group_value_where_marker, " +
"g.value AS cell_group_value, " +
"m.marker_probability AS marker_p_value, " +
"s.mean_expression, " +
"s.median_expression, " +
"e.expression_unit " +
"FROM " +
"scxa_cell_group_marker_gene_stats s, " +
"scxa_cell_group_marker_genes m, " +
"scxa_cell_group g, " +
"scxa_cell_group h, " +
"experiment e " +
"WHERE " +
"s.cell_group_id = g.id AND " +
"s.marker_id = m.id AND " +
"m.cell_group_id = h.id AND " +
"g.experiment_accession = :experiment_accession AND " +
"m.marker_probability < 0.05 AND " +
"g.variable = :variable AND " +
"s.expression_type = 0 AND " +
"e.accession = g.experiment_accession " +
"ORDER BY " +
"m.marker_probability ";

private static final String SELECT_MARKER_GENES_FOR_INFERRED_CELL_TYPES =
"SELECT count(m.gene_id) as marker_genes " +
"FROM " +
"scxa_cell_group_marker_genes m, " +
"scxa_cell_group h " +
"WHERE " +
"m.cell_group_id = h.id AND " +
"h.experiment_accession = :experiment_accession AND " +
"m.marker_probability < 0.05 AND " +
"h.variable= :variable " +
"LIMIT 1";

private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;

public MarkerGenesDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
}

public List<MarkerGene> getMarkerGenesWithAveragesPerCluster(String experimentAccession, String k) {
var namedParameters =
ImmutableMap.of(
"experiment_accession", experimentAccession,
"k", k);

return namedParameterJdbcTemplate.query(
SELECT_MARKER_GENES_WITH_AVERAGES_PER_CLUSTER,
namedParameters,
(resultSet, rowNumber) -> MarkerGene.create(
resultSet.getString("gene_id"),
resultSet.getString("k_where_marker"),
resultSet.getString("cluster_id_where_marker"),
resultSet.getDouble("marker_p_value"),
resultSet.getString("cluster_id"),
resultSet.getDouble("median_expression"),
resultSet.getDouble("mean_expression"),
resultSet.getString("expression_unit")));
}

public List<String> getKsWithMarkerGenes(String experimentAccession) {
var namedParameters = ImmutableMap.of("experiment_accession", experimentAccession);
return namedParameterJdbcTemplate.queryForList(
SELECT_DISTINCT_KS_WITH_MARKER_GENES,
namedParameters,
String.class);
}

public List<MarkerGene> getCellTypeMarkerGenesOntologyLabels(String experimentAccession,
ImmutableCollection<String> cellGroupValues) {
return getCellTypeMarkerGenes(experimentAccession, CELL_TYPE_ONTOLOGY_LABELS, cellGroupValues);
Expand Down Expand Up @@ -148,34 +189,6 @@ public List<MarkerGene> getCellTypeMarkerGenes(String experiment_accession,
resultSet.getString("expression_unit")));
}

private static final String SELECT_MARKER_GENES_WITH_AVERAGES_PER_CELL_GROUP_ALL =
"SELECT " +
"g.experiment_accession, " +
"m.gene_id, " +
"g.variable AS cell_group_type, " +
"h.value AS cell_group_value_where_marker, " +
"g.value AS cell_group_value, " +
"m.marker_probability AS marker_p_value, " +
"s.mean_expression, " +
"s.median_expression, " +
"e.expression_unit " +
"FROM " +
"scxa_cell_group_marker_gene_stats s, " +
"scxa_cell_group_marker_genes m, " +
"scxa_cell_group g, " +
"scxa_cell_group h, " +
"experiment e " +
"WHERE " +
"s.cell_group_id = g.id AND " +
"s.marker_id = m.id AND " +
"m.cell_group_id = h.id AND " +
"g.experiment_accession = :experiment_accession AND " +
"m.marker_probability < 0.05 AND " +
"g.variable = :variable AND " +
"s.expression_type = 0 AND " +
"e.accession = g.experiment_accession " +
"ORDER BY " +
"m.marker_probability ";
public List<MarkerGene> getCellTypeMarkerGenes(String experiment_accession,
String cellTypeVariable) {
var namedParameters =
Expand All @@ -196,4 +209,17 @@ public List<MarkerGene> getCellTypeMarkerGenes(String experiment_accession,
resultSet.getDouble("mean_expression"),
resultSet.getString("expression_unit")));
}

public Integer getMarkerGenesForTheInferredCellTypes(String experimentAccession, String cellGroupType) {
var namedParameters =
ImmutableMap.of(
"experiment_accession", experimentAccession,
"variable", cellGroupType);

return namedParameterJdbcTemplate.queryForObject(
SELECT_MARKER_GENES_FOR_INFERRED_CELL_TYPES,
namedParameters,
Integer.class);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import uk.ac.ebi.atlas.download.ExperimentFileType;
import uk.ac.ebi.atlas.experimentpage.ExternallyAvailableContentService;
import uk.ac.ebi.atlas.experimentpage.cellplot.CellPlotService;
import uk.ac.ebi.atlas.experimentpage.markergenes.MarkerGeneService;
import uk.ac.ebi.atlas.experimentpage.metadata.CellMetadataService;
import uk.ac.ebi.atlas.experimentpage.tsneplot.TSnePlotSettingsService;
import uk.ac.ebi.atlas.model.download.ExternallyAvailableContent;
Expand All @@ -36,6 +37,7 @@ public class ExperimentPageContentService {
private final OntologyAccessionsSearchService ontologyAccessionsSearchService;
private final ExperimentTrader experimentTrader;
private final CellPlotService cellPlotService;
private final MarkerGeneService markerGeneService;

final static ImmutableSet<String> EXPERIMENTS_WITH_NO_ANATOMOGRAM = ImmutableSet.of(
"E-CURD-10", "E-CURD-11", "E-CURD-126", "E-CURD-135",
Expand All @@ -50,14 +52,15 @@ public ExperimentPageContentService(ExperimentFileLocationService experimentFile
CellMetadataService cellMetadataService,
OntologyAccessionsSearchService ontologyAccessionsSearchService,
ExperimentTrader experimentTrader,
CellPlotService cellPlotService) {
CellPlotService cellPlotService, MarkerGeneService markerGeneService) {
this.experimentFileLocationService = experimentFileLocationService;
this.dataFileHub = dataFileHub;
this.tsnePlotSettingsService = tsnePlotSettingsService;
this.cellMetadataService = cellMetadataService;
this.ontologyAccessionsSearchService = ontologyAccessionsSearchService;
this.experimentTrader = experimentTrader;
this.cellPlotService = cellPlotService;
this.markerGeneService = markerGeneService;
}

public JsonObject getTsnePlotData(String experimentAccession) {
Expand All @@ -81,6 +84,9 @@ public JsonObject getTsnePlotData(String experimentAccession) {
GSON.toJsonTree(fetchDefaultPlotMethodAndParameterisation(experimentAccession)));

result.add("metadata", getMetadata(experimentAccession));
result.add("markerGeneMetadata", GSON.toJsonTree
(markerGeneService.isMarkerGenesAvailableForTheInferredCellTypes(experimentAccession,
"inferred cell type - ontology labels")));

var units = new JsonArray();
units.add("CPM");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import uk.ac.ebi.atlas.configuration.TestConfig;
import uk.ac.ebi.atlas.download.ExperimentFileLocationService;
import uk.ac.ebi.atlas.experimentpage.cellplot.CellPlotService;
import uk.ac.ebi.atlas.experimentpage.markergenes.MarkerGeneService;
import uk.ac.ebi.atlas.experimentpage.tsneplot.TSnePlotSettingsService;
import uk.ac.ebi.atlas.experimentpage.metadata.CellMetadataService;
import uk.ac.ebi.atlas.resource.DataFileHub;
Expand Down Expand Up @@ -62,6 +63,9 @@ class ExperimentPageContentServiceIT {
@Inject
private CellPlotService cellPlotService;

@Inject
private MarkerGeneService markerGeneService;

private ExperimentPageContentService subject;

@BeforeAll
Expand Down Expand Up @@ -101,7 +105,8 @@ void setUp() {
cellMetadataService,
ontologyAccessionsSearchService,
experimentTrader,
cellPlotService);
cellPlotService,
markerGeneService);
}

@Test
Expand Down
Loading
Loading