Skip to content

Commit 500fc70

Browse files
authored
Fix FPKM calcualtion (#242)
* fix(fpkm): update imports for zFPKM calculation improvements Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix(fpkm): use Salmon quantification instead of STAR quantification Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: ruff formatting Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: fill with integers for faster processing Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: remove unnecessary async function usage Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix: remove non existant genes from conversion Signed-off-by: Josh Loecker <joshloecker@icloud.com> * refactor: use more explicit (albeit longer) code to create gene_info dataframe object Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: import required modules Signed-off-by: Josh Loecker <joshloecker@icloud.com> * refactor: optional argument for fragment data Signed-off-by: Josh Loecker <joshloecker@icloud.com> * refactor: improve handling for single cell data Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: generalize data type input Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: ruff formatting Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: simplify FPKM/RPKM calculations; properly compute per-gene FPKM scores Signed-off-by: Josh Loecker <joshloecker@icloud.com> * refactor: move zfpkm calculation to external package Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: use np.bool for boolean array Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: ruff formatting Signed-off-by: Josh Loecker <joshloecker@icloud.com> * feat: allow setting negative zFPKM results to 0 Signed-off-by: Josh Loecker <joshloecker@icloud.com> * feat: simplification to use external zfpkm package Signed-off-by: Josh Loecker <joshloecker@icloud.com> * feat: allow providing the fragment size filepath (from rnaseq preprocessing) Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore(ruff): reduce max line length Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore(ruff): mark unsorted imports as fixable Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore(uv): lock pyproject file Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix: rename count to quant in testing files Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix: test new quant information Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: use quant files instead of strand files Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: updated COMO_input files for naiveB to use updated FastqToGeneCounts information Signed-off-by: Josh Loecker <joshloecker@icloud.com> * feat: added Salmon quantification data for naive B Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore: use `_read_file` function to read data Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix(tests): remove 1 from expected gene names to fix header Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix(tests): use `endswith` instead of `is in` Signed-off-by: Josh Loecker <joshloecker@icloud.com> * fix(tests): Use missing file appropriately Signed-off-by: Josh Loecker <joshloecker@icloud.com> * chore(uv): Use dependency groups Signed-off-by: Josh Loecker <joshloecker@icloud.com> * revert: use synchronous programming for more deterministic usage Signed-off-by: Josh Loecker <joshloecker@icloud.com> --------- Signed-off-by: Josh Loecker <joshloecker@icloud.com>
1 parent ef5f7b3 commit 500fc70

74 files changed

Lines changed: 2504832 additions & 3415412 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

main/como/rnaseq_gen.py

Lines changed: 269 additions & 348 deletions
Large diffs are not rendered by default.

main/como/rnaseq_preprocess.py

Lines changed: 313 additions & 252 deletions
Large diffs are not rendered by default.

main/como/utils.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,35 +188,39 @@ async def get_missing_gene_data(values: list[str] | pd.DataFrame, taxon_id: int
188188

189189

190190
@overload
191-
async def _read_file(path: None, h5ad_as_df: Literal[True] | Literal[False], **kwargs) -> None: ...
191+
def _read_file(path: None, h5ad_as_df: bool = True, **kwargs: Any) -> None: ...
192192

193193

194194
@overload
195-
async def _read_file(path: pd.DataFrame, h5ad_as_df: Literal[True] | Literal[False], **kwargs) -> pd.DataFrame: ...
195+
def _read_file(path: pd.DataFrame, h5ad_as_df: bool = True, **kwargs: Any) -> pd.DataFrame: ...
196196

197197

198198
@overload
199-
async def _read_file(path: sc.AnnData, h5ad_as_df: Literal[False] = False, **kwargs) -> sc.AnnData: ...
199+
def _read_file(path: io.StringIO, h5ad_as_df: bool = True, **kwargs: Any) -> pd.DataFrame: ...
200200

201201

202202
@overload
203-
async def _read_file(path: sc.AnnData, h5ad_as_df: Literal[True] = True, **kwargs) -> pd.DataFrame: ...
203+
def _read_file(path: sc.AnnData, h5ad_as_df: Literal[False], **kwargs: Any) -> sc.AnnData: ...
204204

205205

206206
@overload
207-
async def _read_file(path: Path, h5ad_as_df: Literal[False] = False, **kwargs) -> pd.DataFrame | sc.AnnData: ...
207+
def _read_file(path: sc.AnnData, h5ad_as_df: Literal[True] = True, **kwargs: Any) -> pd.DataFrame: ...
208208

209209

210210
@overload
211-
async def _read_file(path: Path, h5ad_as_df: Literal[True] = True, **kwargs) -> pd.DataFrame: ...
211+
def _read_file(path: Path, h5ad_as_df: Literal[False], **kwargs: Any) -> pd.DataFrame | sc.AnnData: ...
212212

213213

214-
async def _read_file(
214+
@overload
215+
def _read_file(path: Path, h5ad_as_df: Literal[True] = True, **kwargs: Any) -> pd.DataFrame: ...
216+
217+
218+
def _read_file(
215219
path: Path | io.StringIO | pd.DataFrame | sc.AnnData | None,
216220
h5ad_as_df: bool = True,
217-
**kwargs,
221+
**kwargs: Any,
218222
) -> pd.DataFrame | sc.AnnData | None:
219-
"""Asynchronously read a filepath and return a pandas DataFrame.
223+
"""Read a filepath and return pandas.DataFrame or scanpy.AnnData.
220224
221225
If the provided path is None, None will also be returned.
222226
None may be provided to this function so that `asyncio.gather` can safely be used on all sources
@@ -244,18 +248,17 @@ async def _read_file(
244248
_log_and_raise_error(f"File {path} does not exist", error=FileNotFoundError, level=LogLevel.CRITICAL)
245249

246250
match path.suffix:
247-
case ".csv" | ".tsv" | ".txt" | ".tab":
251+
case ".csv" | ".tsv" | ".txt" | ".tab" | ".sf":
248252
kwargs.setdefault("sep", "," if path.suffix == ".csv" else "\t") # set sep if not defined
249-
async with aiofiles.open(path) as i_stream:
250-
content = await i_stream.read()
251-
return pd.read_csv(io.StringIO(content), **kwargs)
253+
return pd.read_csv(path, **kwargs)
252254
case ".xlsx" | ".xls":
253255
return pd.read_excel(path, **kwargs)
254256
case ".h5ad":
255257
adata: sc.AnnData = sc.read_h5ad(path, **kwargs)
256258
if h5ad_as_df:
257259
df = adata.to_df().T
258-
df.index.name = "gene_symbol"
260+
if not df.index.name:
261+
df.index.name = "gene_symbol"
259262
df.reset_index(inplace=True)
260263
return df
261264
return adata

main/data/COMO_input/naiveB/fragmentSizes/S1/naiveB_S1R1_fragment_size.txt

Lines changed: 78362 additions & 258145 deletions
Large diffs are not rendered by default.

main/data/COMO_input/naiveB/fragmentSizes/S1/naiveB_S1R2_fragment_size.txt

Lines changed: 78362 additions & 258145 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)