-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmark scripts and ignore types where pandas DataFrames cause …
…mypy problems
- Loading branch information
1 parent
75d7d25
commit 4df75a1
Showing
14 changed files
with
166 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.9 | ||
3.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ dev = [ | |
"mypy", | ||
"myst-parser", | ||
"nbsphinx", | ||
"pandas-stubs", | ||
"pandoc", | ||
"pre-commit", | ||
"pybiomart", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.json | ||
*.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
options(repos = c(CRAN = "https://cloud.r-project.org")) | ||
|
||
if (!requireNamespace("tximport", quietly = TRUE)) { | ||
install.packages("BiocManager") | ||
BiocManager::install("tximport") | ||
} | ||
|
||
if (!requireNamespace("bench", quietly = TRUE)) { | ||
install.packages("bench") | ||
} | ||
|
||
if (!requireNamespace("readr", quietly = TRUE)) { | ||
install.packages("readr") | ||
} | ||
|
||
if (!requireNamespace("matrixStats", quietly = TRUE)) { | ||
install.packages("matrixStats") | ||
} | ||
|
||
# Load libraries | ||
library(tximport) | ||
library(bench) | ||
library(readr) | ||
library(matrixStats) | ||
|
||
# Define the file paths and transcript-gene mapping | ||
transcript_gene_mapping <- read_tsv("../data/fabry_disease/transcript_gene_mapping_human.tsv") | ||
|
||
files <- c( | ||
"../data/fabry_disease/SRR16504309_wt/quant.sf", | ||
"../data/fabry_disease/SRR16504310_wt/quant.sf", | ||
"../data/fabry_disease/SRR16504311_ko/quant.sf", | ||
"../data/fabry_disease/SRR16504312_ko/quant.sf" | ||
) | ||
|
||
# Create a function to benchmark | ||
tximport_benchmark <- function() { | ||
txi <- tximport( | ||
files, | ||
type = "salmon", | ||
tx2gene = transcript_gene_mapping, | ||
ignoreTxVersion = TRUE, | ||
ignoreAfterBar = TRUE, | ||
dropInfReps = FALSE, | ||
countsFromAbundance = "lengthScaledTPM", | ||
infRepStat = rowMedians | ||
) | ||
return(txi) | ||
} | ||
|
||
# Run the benchmark | ||
benchmark_results <- bench::mark( | ||
tximport_benchmark(), | ||
filter_gc = FALSE, | ||
iterations = 11 | ||
) | ||
|
||
benchmark_results_df <- as.data.frame( | ||
lapply(benchmark_results, as.character), | ||
stringsAsFactors = FALSE | ||
) | ||
|
||
benchmark_results_df <- benchmark_results_df[, !grepl( | ||
"result", | ||
names(benchmark_results_df) | ||
)] | ||
|
||
benchmark_results_df <- benchmark_results_df[, !grepl( | ||
"memory", | ||
names(benchmark_results_df) | ||
)] | ||
|
||
print(benchmark_results) | ||
|
||
write.csv(as.data.frame(benchmark_results_df), "tximport_time_memory.csv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Benchmark pytximport.""" | ||
|
||
from logging import INFO, getLogger | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import pyperf | ||
|
||
from pytximport import tximport | ||
|
||
# Load transcript-gene mapping (this can be done once outside the benchmark) | ||
transcript_gene_mapping_human = pd.read_table( | ||
"../data/fabry_disease/transcript_gene_mapping_human.tsv", | ||
header=0, | ||
sep="\t", | ||
) | ||
|
||
# Define the files list | ||
files = [ | ||
"../data/fabry_disease/SRR16504309_wt/quant.sf", | ||
"../data/fabry_disease/SRR16504310_wt/quant.sf", | ||
"../data/fabry_disease/SRR16504311_ko/quant.sf", | ||
"../data/fabry_disease/SRR16504312_ko/quant.sf", | ||
] | ||
|
||
|
||
# Function to benchmark | ||
def tximport_benchmark(): | ||
"""Benchmark pytximport. | ||
Returns: | ||
ad.AnnData: The AnnData object. | ||
""" | ||
txi = tximport( | ||
files, | ||
"salmon", | ||
transcript_gene_mapping_human, | ||
inferential_replicates=True, | ||
inferential_replicate_transformer=lambda x: np.median(x, axis=1), | ||
) | ||
return txi | ||
|
||
|
||
# Run the pyperf benchmark | ||
if __name__ == "__main__": | ||
# Set log level to 25 | ||
getLogger().setLevel(25) | ||
|
||
runner = pyperf.Runner() | ||
runner.bench_func("pytximport", tximport_benchmark) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rm *.json | ||
python3 bench.py -o ./pytximport_time.json -p 1 -n 11 -w 0 | ||
python3 -m pyperf stats ./pytximport_time.json | ||
python3 bench.py -o ./pytximport_memory.json -p 1 -n 11 -w 0 --track-memory | ||
python3 -m pyperf stats ./pytximport_memory.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
rm *.csv | ||
Rscript bench.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters