Skip to content

Commit bb1449a

Browse files
committed
refactor: explicit type cast
Signed-off-by: Josh Loecker <joshloecker@icloud.com>
1 parent 95dc2db commit bb1449a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

main/como/rnaseq_gen.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async def _build_matrix_results(
219219
study_sample_names = metadata_df[metadata_df["study"] == study]["sample_name"].tolist()
220220
layouts = metadata_df[metadata_df["study"] == study]["layout"].tolist()
221221
metrics[study] = _StudyMetrics(
222-
count_matrix=counts_matrix[counts_matrix.columns.intersection(study_sample_names)],
222+
count_matrix=cast(pd.DataFrame, counts_matrix[counts_matrix.columns.intersection(study_sample_names)]),
223223
fragment_lengths=metadata_df[metadata_df["study"] == study]["fragment_length"].values.astype(float),
224224
sample_names=study_sample_names,
225225
layout=[LayoutMethod(layout) for layout in layouts],
@@ -393,6 +393,7 @@ def zfpkm_transform(
393393
zfpkm_series: list[pd.Series] = []
394394
results: dict[str, _ZFPKMResult] = {}
395395

396+
slim_fpkm_df: pd.DataFrame = cast(pd.DataFrame, fpkm_df[fpkm_df.index != "-"] if remove_na else fpkm_df)
396397
with ProcessPoolExecutor(max_workers=cores) as pool:
397398
futures: list[Future[_ZFPKMResult]] = [
398399
pool.submit(
@@ -523,7 +524,7 @@ def cpm_filter(
523524
for sample, metric in metrics.items():
524525
counts: pd.DataFrame = metric.count_matrix
525526
entrez_ids: list[str] = metric.entrez_gene_ids
526-
library_size: pd.DataFrame = counts.sum(axis=1)
527+
library_size: pd.DataFrame = cast(pd.DataFrame, counts.sum(axis=1))
527528

528529
# For library_sizes equal to 0, add 1 to prevent divide by 0
529530
# This will not impact the final counts per million calculation because the original counts are still 0
@@ -595,8 +596,8 @@ def tpm_quantile_filter(*, metrics: NamedMetrics, filtering_options: _FilteringO
595596
# Only keep `entrez_gene_ids` that pass `min_genes`
596597
metric.entrez_gene_ids = [gene for gene, keep in zip(entrez_ids, min_genes, strict=True) if keep]
597598
metric.gene_sizes = np.array(gene for gene, keep in zip(gene_size, min_genes, strict=True) if keep)
598-
metric.count_matrix = metric.count_matrix.iloc[min_genes, :]
599-
metric.normalization_matrix = metrics[sample].normalization_matrix.iloc[min_genes, :]
599+
metric.count_matrix = cast(pd.DataFrame, metric.count_matrix.iloc[min_genes, :])
600+
metric.normalization_matrix = cast(pd.DataFrame, metrics[sample].normalization_matrix.iloc[min_genes, :])
600601

601602
keep_top_genes = [gene for gene, keep in zip(entrez_ids, top_genes, strict=True) if keep]
602603
metric.high_confidence_entrez_gene_ids = [gene for gene, keep in zip(entrez_ids, keep_top_genes, strict=True) if keep]

0 commit comments

Comments
 (0)