Skip to content

Commit

Permalink
Merge pull request #18 from broadinstitute/add-drug-counts
Browse files Browse the repository at this point in the history
Add drug counts to data page data availability graph
  • Loading branch information
alimourey authored Aug 2, 2024
2 parents 82a1259 + 99581d4 commit b80254f
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 23 deletions.
1 change: 1 addition & 0 deletions frontend/packages/portal-frontend/src/dAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ export class DepmapApi {
// mapped to color category integers. The integer maps to Heatmap.tsx's
// color scale.
data_type_url_mapping: boolSummary.data_type_url_mapping,
drug_count_mapping: boolSummary.drug_count_mapping,
values: dataAvailVals,
data_types: boolSummary.data_types,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ const DataAvailabilityPlot = ({

return graphSectionUrlMapping;
};

const getDrugCountMapping = (categoryKey: string) => {
const graphSectionDrugCountMapping: {
[key: string]: number | undefined;
} = {};
dataValuesByDataTypeCategory[categoryKey].forEach((category: any) => {
const dataTypeString = getDataPageDataTypeString(category.dataType);

const count =
currentReleaseDataAvil.drug_count_mapping[category.dataType];

graphSectionDrugCountMapping[dataTypeString] = count;
});

return graphSectionDrugCountMapping;
};
return (
<div>
{dataValuesByDataTypeCategory && (
Expand All @@ -112,6 +128,7 @@ const DataAvailabilityPlot = ({
(category: any) => category.dataType
)}
dataTypeUrlMapping={getDataTypeUrlMapping(categoryKey)}
drugCountMapping={getDrugCountMapping(categoryKey)}
dataTypeGroupName={categoryKey}
isCurrentRelease={isCurrentRelease}
/>
Expand All @@ -131,7 +148,7 @@ const DataAvailabilityPlot = ({
BAR_THICKNESS *
dataValuesByDataTypeCategory[categoryKey].length
}
customWidth={400}
customWidth={350}
customColorScale={COLOR_SCALE}
margin={{
l: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const DataPage = ({
const [allDataAvail, setAllDataAvail] = useState<DataAvailability>({
all_depmap_ids: [],
data_type_url_mapping: {},
drug_count_mapping: {},
data_types: [],
values: [],
});
Expand All @@ -42,6 +43,7 @@ export const DataPage = ({
] = useState<DataAvailability>({
all_depmap_ids: [],
data_type_url_mapping: {},
drug_count_mapping: {},
data_types: [],
values: [],
});
Expand All @@ -65,18 +67,22 @@ export const DataPage = ({
const currentDataValues: number[][] = [];
const currentDataTypes: string[] = [];
const currentDataTypeUrlMapping: { [key: string]: string } = {};
const currentDataTypeDrugCountMapping: { [key: string]: number } = {};
dataAvail.data_types.forEach((data_type: string, index: number) => {
if (currentReleaseDatasets.includes(data_type)) {
currentDataTypes.push(data_type);
currentDataValues.push(dataAvail.values[index]);
currentDataTypeUrlMapping[data_type] =
dataAvail.data_type_url_mapping[data_type];
currentDataTypeDrugCountMapping[data_type] =
dataAvail.drug_count_mapping[data_type];
}
});

setCurrentReleaseDataAvail({
all_depmap_ids: dataAvail.all_depmap_ids,
data_type_url_mapping: currentDataTypeUrlMapping,
drug_count_mapping: currentDataTypeDrugCountMapping,
data_types: currentDataTypes,
values: currentDataValues,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,31 @@ interface Props {
datatypes: string[];
dataTypeGroupName: string;
dataTypeUrlMapping: { [key: string]: string | undefined };
drugCountMapping: { [data_type: string]: number | undefined };
isCurrentRelease: boolean;
}

const DataPageDatatypeSelector = ({
datatypes,
dataTypeGroupName,
dataTypeUrlMapping,
drugCountMapping,
isCurrentRelease,
}: Props) => {
const display: any = [];

const getDrugCountLabel = (dataType: string) => {
if (
Object.keys(drugCountMapping).includes(dataType) &&
drugCountMapping[dataType] !== null &&
drugCountMapping[dataType] !== undefined
) {
return `(${drugCountMapping[dataType]} drugs)`;
}

return "";
};

// If the data type is in the current release, add an asterisk.
const getDataTypeLabel = (
dataType: string,
Expand Down Expand Up @@ -47,10 +61,15 @@ const DataPageDatatypeSelector = ({
target="_blank"
rel="noreferrer"
>
{getDataTypeLabel(dataTypeDisplayName, inCurrentRelease)}
{`${getDataTypeLabel(dataTypeDisplayName, inCurrentRelease)}`}
<br />
{getDrugCountLabel(dataTypeDisplayName)}
</a>
) : (
<p>{getDataTypeLabel(dataTypeDisplayName, inCurrentRelease)}</p>
<p>
{getDataTypeLabel(dataTypeDisplayName, inCurrentRelease)} <br />
{getDrugCountLabel(dataTypeDisplayName)}
</p>
)}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const BAR_THICKNESS = 42;
export const BAR_THICKNESS = 43;

export const currentReleaseDatasets = [
"Sequencing_WES_Broad",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const COLOR_SCALE = [
export interface DataAvailSummary {
all_depmap_ids: [number, string][];
data_type_url_mapping: { [data_type: string]: string };
drug_count_mapping: { [data_type: string]: number };
data_types: string[];
values: boolean[][];
}
Expand All @@ -38,6 +39,7 @@ export interface DataSummary {
export interface DataAvailability {
all_depmap_ids: [number, string][];
data_type_url_mapping: { [data_type: string]: string };
drug_count_mapping: { [data_type: string]: number };
values: number[][];
data_types: string[];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
.dataAvailabilityPlotContainer {
width: 290px;
min-width: 290px;
width: 275px;
min-width: 275px;
margin-top: 2px;
border-bottom: 1px solid black;
padding-bottom: 0px;
margin-right: 8px;

@media (max-width: 910px) {
width: 200px;
min-width: 200px;
}
.datatypeSelector {
margin-left: 5px;
font-size: 16px;
min-width: 101px;

@media (max-width: 910px) {
font-size: 14px;
}
margin-left: 4px;
font-size: 14px;
min-width: 150px;

.groupContainer {
display: grid;
grid-template-columns: repeat(2, 1fr);
.groupLabel {
grid-column: 1;
margin-right: 20px;
margin-right: 10px;
align-self: normal;
font-family: roboto;
font-size: 16px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function Heatmap({
height,

margin,
width: 400,
width: customWidth,
}
: {
title: "",
Expand Down
32 changes: 32 additions & 0 deletions portal-backend/depmap/data_page/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from depmap.download.utils import get_download_url
from depmap.enums import BiomarkerEnum, DependencyEnum
from flask_restplus import Namespace, Resource
from depmap.data_access import interface as data_access
from flask import current_app
import pandas as pd

Expand Down Expand Up @@ -39,6 +40,33 @@
]


def _get_drug_count_mapping(data_types: List[str]):
def _get_drug_count(dataset_name: str):
dataset = DependencyDataset.get_dataset_by_name(dataset_name)

if not dataset:
return None

return len(data_access.get_dataset_feature_ids_by_label(dataset_name))

drug_counts_by_data_type = {
"Drug_CTD_Broad": _get_drug_count(DependencyEnum.CTRP_AUC.name),
"Drug_Repurposing_Broad": _get_drug_count(
DependencyEnum.Rep_all_single_pt.name
),
"Drug_GDSC_Sanger": _get_drug_count(DependencyEnum.GDSC2_AUC.name),
"Drug_OncRef_Broad": _get_drug_count(DependencyEnum.Prism_oncology_AUC.name),
}

current_env_mapping = {
data_type_name: drug_count
for data_type_name, drug_count in drug_counts_by_data_type.items()
if data_type_name in data_types
}

return current_env_mapping


def _get_data_type_url_mapping(data_types: List[str]):
def _get_dataset_url(dataset_name, isDependencyDataset=True) -> Union[str, None]:
data_page_endpoint = "data_page.view_data_page"
Expand Down Expand Up @@ -118,9 +146,12 @@ def _get_formatted_all_data_avail_df(overall_summary: pd.DataFrame) -> pd.DataFr
def _format_data_availability_summary_dict(summary_df: pd.DataFrame):
data_types_by_url = _get_data_type_url_mapping(summary_df.index.values.tolist())

drug_count_mapping = _get_drug_count_mapping(summary_df.index.values.tolist())

summary = {
"values": [row.values.tolist() for _, row in summary_df.iterrows()],
"data_type_url_mapping": data_types_by_url,
"drug_count_mapping": drug_count_mapping,
# For keeping track of data_type order
"data_types": summary_df.index.values.tolist(),
}
Expand All @@ -145,4 +176,5 @@ def get(self):
all_data_df = _get_all_data_avail_df()
formatted_df = _get_formatted_all_data_avail_df(all_data_df)
all_data_dict = _format_data_availability_summary_dict(formatted_df)

return all_data_dict
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ModelID,Drug_CTD_Broad,Drug_Repurposing_Broad,CRISPR_Achilles_Broad
ACH-000019,True,False,True
ACH-000019,False,False,True
ACH-000020,True,False,False
ACH-000021,True,False,False
ACH-000022,True,False,False
41 changes: 38 additions & 3 deletions portal-backend/tests/depmap/data_page/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
DependencyDatasetFactory,
DepmapModelFactory,
GeneFactory,
CompoundFactory,
CompoundExperimentFactory,
MatrixFactory,
)
import numpy as np
from tests.utilities import interactive_test_utils


def test_get_data_availability(populated_db):
Expand All @@ -19,6 +23,7 @@ def test_get_data_availability(populated_db):
assert list(data_availablity.keys()) == [
"values",
"data_type_url_mapping",
"drug_count_mapping",
"data_types",
"all_depmap_ids",
]
Expand Down Expand Up @@ -65,7 +70,23 @@ def test_get_data_availability_not_all_data_types_present(
)
dataset = DependencyDatasetFactory(matrix=matrix, name=dataset_name, priority=1,)

drug_dataset_name = DependencyDataset.DependencyEnum.CTRP_AUC
cell_lines = [
DepmapModelFactory(model_id="ACH-000020"),
DepmapModelFactory(model_id="ACH-000021"),
DepmapModelFactory(model_id="ACH-000022"),
]
compounds = [CompoundFactory() for _ in range(3)]
compound_experiments = [CompoundExperimentFactory(compound=c) for c in compounds]
matrix = MatrixFactory(
data=[[2, 3, 4], [0, 2, 1], [np.NaN, np.NaN, np.NaN]],
cell_lines=cell_lines,
entities=compound_experiments,
using_depmap_model_table=True,
)
DependencyDatasetFactory(matrix=matrix, name=drug_dataset_name, priority=1)
empty_db_mock_downloads.session.flush()
interactive_test_utils.reload_interactive_config()

def mock_get_all_data_avail_df():
with open(
Expand All @@ -77,22 +98,36 @@ def mock_get_all_data_avail_df():
monkeypatch.setattr(
data_page_api, "_get_all_data_avail_df", mock_get_all_data_avail_df
)

with empty_db_mock_downloads.app.test_client() as c:
r = c.get(
url_for("api.data_page_data_availability"), content_type="application/json",
)
data_availability = r.json
assert data_availability == {
"values": [[True], [True], [False]],
"values": [
[True, False, False, False],
[False, True, True, True],
[False, False, False, False],
],
"data_type_url_mapping": {
"CRISPR_Achilles_Broad": "/data_page/?release=test+name+version&file=test+file+name+2",
"Drug_CTD_Broad": None,
"Drug_CTD_Broad": "/data_page/?release=test+name+version&file=test+file+name+2",
"Drug_Repurposing_Broad": None,
},
"drug_count_mapping": {
"Drug_CTD_Broad": 3,
"Drug_Repurposing_Broad": None,
},
"data_types": [
"CRISPR_Achilles_Broad",
"Drug_CTD_Broad",
"Drug_Repurposing_Broad",
],
"all_depmap_ids": [[0, "ACH-000019"]],
"all_depmap_ids": [
[0, "ACH-000019"],
[1, "ACH-000020"],
[2, "ACH-000021"],
[3, "ACH-000022"],
],
}

0 comments on commit b80254f

Please sign in to comment.