Skip to content

Commit 41a8cc1

Browse files
Merge pull request #928 from AlexsLemonade/avrohom/922-update-demux-cell-count-estimate-for-metadata-output
922 - Update demux_cell_count_estimate for metadata output
2 parents 59dad9f + 7582e49 commit 41a8cc1

File tree

13 files changed

+81
-65
lines changed

13 files changed

+81
-65
lines changed

api/scpca_portal/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"demux_samples",
5858
"total_reads",
5959
"mapped_reads",
60-
"sample_cell_estimate", # ONLY FOR MULTIPLEXED
60+
"demux_cell_count_estimate", # ONLY FOR MULTIPLEXED
6161
"unfiltered_cells",
6262
"filtered_cell_count",
6363
"processed_cells",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.25 on 2024-10-10 17:43
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("scpca_portal", "0052_auto_20240929_1357"),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name="sample",
15+
old_name="demux_cell_count_estimate",
16+
new_name="demux_cell_count_estimate_sum",
17+
),
18+
]

api/scpca_portal/models/library.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -172,39 +172,30 @@ def get_sample_libraries_from_download_config(
172172
def get_local_path_from_data_file_path(data_file_path: Path) -> Path:
173173
return settings.INPUT_DATA_PATH / data_file_path
174174

175-
def get_metadata(self) -> Dict:
176-
library_metadata = {
177-
"scpca_library_id": self.scpca_id,
178-
}
179-
175+
def get_metadata(self, demux_cell_count_estimate_id) -> Dict:
180176
excluded_metadata_attributes = {
181177
"scpca_sample_id",
182178
"has_citeseq",
183-
# for multiplexed samples, this is handled at the sample level
184179
"sample_cell_estimates",
185180
}
186-
library_metadata.update(
187-
{
188-
key: value
189-
for key, value in self.metadata.items()
190-
if key not in excluded_metadata_attributes
191-
}
192-
)
181+
library_metadata = {
182+
key: value
183+
for key, value in self.metadata.items()
184+
if key not in excluded_metadata_attributes
185+
}
186+
187+
if self.is_multiplexed:
188+
library_metadata["demux_cell_count_estimate"] = self.metadata["sample_cell_estimates"][
189+
demux_cell_count_estimate_id
190+
]
193191

194192
return library_metadata
195193

196194
def get_combined_library_metadata(self) -> List[Dict]:
197-
combined_metadatas = []
198-
for sample in self.samples.all():
199-
metadata = self.project.get_metadata() | sample.get_metadata() | self.get_metadata()
200-
201-
# Only single cell multiplexed sample libraries should pass through sample_cell_estimate
202-
if not self.is_multiplexed:
203-
del metadata["sample_cell_estimate"]
204-
205-
combined_metadatas.append(metadata)
206-
207-
return combined_metadatas
195+
return [
196+
self.project.get_metadata() | sample.get_metadata() | self.get_metadata(sample.scpca_id)
197+
for sample in self.samples.all()
198+
]
208199

209200
def get_download_config_file_paths(self, download_config: Dict) -> List[Path]:
210201
"""

api/scpca_portal/models/project.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,8 @@ def update_sample_aggregate_properties(self):
392392
"scpca_id", flat=True
393393
)
394394
)
395-
# Sum demux_cell_count_estimate from all related library's
396-
# sample_cell_estimates for that sample.
397-
sample.demux_cell_count_estimate = sum(
395+
# Sum of all related libraries' sample_cell_estimates for that sample.
396+
sample.demux_cell_count_estimate_sum = sum(
398397
library.metadata["sample_cell_estimates"].get(sample.scpca_id, 0)
399398
for library in multiplexed_libraries
400399
)

api/scpca_portal/models/sample.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Modalities:
3535

3636
age = models.TextField()
3737
age_timing = models.TextField()
38-
demux_cell_count_estimate = models.IntegerField(null=True)
38+
demux_cell_count_estimate_sum = models.IntegerField(null=True)
3939
diagnosis = models.TextField(blank=True, null=True)
4040
disease_timing = models.TextField(blank=True, null=True)
4141
has_multiplexed_data = models.BooleanField(default=False)
@@ -107,28 +107,17 @@ def additional_metadata(self):
107107
}
108108

109109
def get_metadata(self) -> Dict:
110-
sample_metadata = {
111-
"scpca_sample_id": self.scpca_id,
112-
}
113-
114110
excluded_metadata_attributes = {
115111
"scpca_project_id",
116112
"submitter", # included in project metadata under the name pi_name
117113
}
118-
sample_metadata.update(
119-
{
120-
key: value
121-
for key, value in self.metadata.items()
122-
if key not in excluded_metadata_attributes
123-
}
124-
)
125114

126-
derived_attributes = {
127-
"demux_cell_count_estimate",
128-
"includes_anndata",
115+
sample_metadata = {
116+
key: value
117+
for key, value in self.metadata.items()
118+
if key not in excluded_metadata_attributes
129119
}
130-
sample_metadata.update({key: getattr(self, key) for key in derived_attributes})
131-
sample_metadata["sample_cell_estimate"] = sample_metadata.pop("demux_cell_count_estimate")
120+
sample_metadata["includes_anndata"] = self.includes_anndata
132121

133122
return sample_metadata
134123

api/scpca_portal/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Meta:
155155
"age_timing",
156156
"computed_files",
157157
"created_at",
158-
"demux_cell_count_estimate",
158+
"demux_cell_count_estimate_sum",
159159
"diagnosis",
160160
"disease_timing",
161161
"has_bulk_rna_seq",

api/scpca_portal/test/expected_values/computed_file_project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SINGLE_CELL_SCE_MULTIPLEXED:
7070
"metadata_only": False,
7171
"s3_bucket": settings.AWS_S3_OUTPUT_BUCKET_NAME,
7272
"s3_key": "SCPCP999991_SINGLE-CELL_SINGLE-CELL-EXPERIMENT_MULTIPLEXED.zip",
73-
"size_in_bytes": 9473,
73+
"size_in_bytes": 9478,
7474
"workflow_version": "development",
7575
"includes_celltype_report": True,
7676
}

api/scpca_portal/test/expected_values/computed_file_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class MULTIPLEXED_SINGLE_CELL_SCE:
129129
"metadata_only": False,
130130
"s3_bucket": settings.AWS_S3_OUTPUT_BUCKET_NAME,
131131
"s3_key": "SCPCS999992-SCPCS999993_SINGLE-CELL_SINGLE-CELL-EXPERIMENT_MULTIPLEXED.zip",
132-
"size_in_bytes": 7145,
132+
"size_in_bytes": 7150,
133133
"workflow_version": "development",
134134
"includes_celltype_report": True,
135135
}

api/scpca_portal/test/expected_values/project_SCPCP999990.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Sample_SCPCS999990:
5555
VALUES = {
5656
"age": "2",
5757
"age_timing": "diagnosis",
58-
"demux_cell_count_estimate": None,
58+
"demux_cell_count_estimate_sum": None,
5959
"diagnosis": "diagnosis1",
6060
"disease_timing": "Initial diagnosis",
6161
"has_bulk_rna_seq": False,
@@ -82,7 +82,7 @@ class Sample_SCPCS999991:
8282
VALUES = {
8383
"age": "2",
8484
"age_timing": "collection",
85-
"demux_cell_count_estimate": None,
85+
"demux_cell_count_estimate_sum": None,
8686
"diagnosis": "diagnosis2",
8787
"disease_timing": "Initial diagnosis",
8888
"has_bulk_rna_seq": False,
@@ -109,7 +109,7 @@ class Sample_SCPCS999994:
109109
VALUES = {
110110
"age": "2",
111111
"age_timing": "collection",
112-
"demux_cell_count_estimate": None,
112+
"demux_cell_count_estimate_sum": None,
113113
"diagnosis": "diagnosis5",
114114
"disease_timing": "Initial diagnosis",
115115
"has_bulk_rna_seq": True,
@@ -136,7 +136,7 @@ class Sample_SCPCS999997:
136136
VALUES = {
137137
"age": "2",
138138
"age_timing": "collection",
139-
"demux_cell_count_estimate": None,
139+
"demux_cell_count_estimate_sum": None,
140140
"diagnosis": "diagnosis5",
141141
"disease_timing": "Initial diagnosis",
142142
"has_bulk_rna_seq": False,

api/scpca_portal/test/expected_values/project_SCPCP999991.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Sample_SCPCS999992:
4848
VALUES = {
4949
"age": "2",
5050
"age_timing": "unknown",
51-
"demux_cell_count_estimate": 0,
51+
"demux_cell_count_estimate_sum": 0,
5252
"diagnosis": "diagnosis4",
5353
"disease_timing": "Initial diagnosis",
5454
"has_bulk_rna_seq": False,
@@ -75,7 +75,7 @@ class Sample_SCPCS999993:
7575
VALUES = {
7676
"age": "2",
7777
"age_timing": "diagnosis",
78-
"demux_cell_count_estimate": 0,
78+
"demux_cell_count_estimate_sum": 0,
7979
"diagnosis": "diagnosis3",
8080
"disease_timing": "Initial diagnosis",
8181
"has_bulk_rna_seq": False,
@@ -102,7 +102,7 @@ class Sample_SCPCS999995:
102102
VALUES = {
103103
"age": "2",
104104
"age_timing": "unknown",
105-
"demux_cell_count_estimate": None,
105+
"demux_cell_count_estimate_sum": None,
106106
"diagnosis": "diagnosis6",
107107
"disease_timing": "Initial diagnosis",
108108
"has_bulk_rna_seq": False,

0 commit comments

Comments
 (0)