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

Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8e7177a
Fetch marker gene id with experiment accession from the DB
upendrakumbham Oct 21, 2024
9b74beb
Merge branch 'develop' into make-the-inferred-cell-type-options-dynam…
upendrakumbham Oct 21, 2024
4ab3665
Fix broken tests
upendrakumbham Oct 24, 2024
2e3cb5d
Update SQL query
upendrakumbham Oct 24, 2024
0ba7088
Add a method to filter conditional meta data for marker genes tab
upendrakumbham Nov 6, 2024
8ada971
Add a private method to filter data to generate markergene metadata i…
upendrakumbham Nov 13, 2024
2539249
Merge branch 'develop' into bugfix/make-the-inferred-cell-type-option…
upendrakumbham Nov 13, 2024
9f351b1
Add a DAO tests
upendrakumbham Nov 13, 2024
5c1fccc
Fix broken tests
upendrakumbham Nov 14, 2024
918127c
Add Service layer tests
upendrakumbham Nov 14, 2024
9f9fa67
Add service integration tests
upendrakumbham Nov 15, 2024
5ff7093
Improve getMarkerGeneMetadata method
upendrakumbham Nov 15, 2024
47be475
Add generalised unit tests as per review comment
upendrakumbham Nov 27, 2024
f3c04f2
Fix review comments - remove regx, remove unnecessary code and code i…
upendrakumbham Nov 28, 2024
11c992b
Update test method name
upendrakumbham Nov 29, 2024
061dd39
Improve code
upendrakumbham Nov 29, 2024
2bcfce7
Merge branch 'develop' into bugfix/make-the-inferred-cell-type-option…
upendrakumbham Nov 29, 2024
7bc29be
Improve code
upendrakumbham Nov 29, 2024
cffd5c9
Update test
upendrakumbham Nov 29, 2024
cade7ec
Code cleanup and improvements
upendrakumbham Dec 4, 2024
1ad1bcd
Remove unused methods
upendrakumbham Dec 4, 2024
a4575ab
Replace Sys err with logger
upendrakumbham Dec 4, 2024
6c3a201
Refactor variables names
upendrakumbham Dec 4, 2024
da7062e
Fix broken test
upendrakumbham Dec 5, 2024
d353670
Improve test method name
upendrakumbham Dec 5, 2024
d5bd597
Rename test method
upendrakumbham Dec 5, 2024
72f2036
Update code
upendrakumbham Dec 5, 2024
6adbc57
Update access modifier
upendrakumbham Dec 5, 2024
cd347f2
Update variable name
upendrakumbham Dec 5, 2024
5686849
Fix broken test
upendrakumbham Dec 5, 2024
d1d487f
Rename test methods
upendrakumbham Dec 6, 2024
6bd29a6
Merge branch 'develop' into bugfix/make-the-inferred-cell-type-option…
upendrakumbham Dec 9, 2024
98eefdb
Update tests
upendrakumbham Dec 9, 2024
19131a3
Update SQL queries indentation format like previous format
upendrakumbham Dec 13, 2024
a210be5
Merge branch 'develop' into bugfix/make-the-inferred-cell-type-option…
upendrakumbham Dec 13, 2024
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 " +
upendrakumbham marked this conversation as resolved.
Show resolved Hide resolved
"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);

}
}
Loading
Loading