Skip to content

Commit

Permalink
replace callBasilisk with basilisk::basiliskRun
Browse files Browse the repository at this point in the history
  • Loading branch information
ChangqingW committed Oct 4, 2023
1 parent dfa2ba7 commit fc64827
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 65 deletions.
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ importFrom(bambu,prepareAnnotations)
importFrom(bambu,writeToGTF)
importFrom(basilisk,BasiliskEnvironment)
importFrom(basilisk,basiliskRun)
importFrom(basilisk,basiliskStart)
importFrom(basilisk,basiliskStop)
importFrom(circlize,colorRamp2)
importFrom(cowplot,get_legend)
importFrom(cowplot,plot_grid)
Expand Down
3 changes: 2 additions & 1 deletion R/BLAZE_demultiplexing.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#' blaze(expect_cells=10, fastq1, overwrite=TRUE)
#'
#' @importFrom reticulate import_from_path dict
#' @importFrom basilisk basiliskRun
#' @export
blaze <- function(expect_cells, fq_in, ...) {
# prepare command-line-style arguments for blaze
Expand Down Expand Up @@ -57,7 +58,7 @@ blaze <- function(expect_cells, fq_in, ...) {

# run blaze
ret <-
callBasilisk(flames_env, function(blaze_argv) {
basiliskRun(env = flames_env, fun = function(blaze_argv) {
# blaze_path <- system.file("blaze", package = "FLAMES")
cat("Running BLAZE...\n")
cat("Argument: ", blaze_argv, "\n")
Expand Down
15 changes: 0 additions & 15 deletions R/call_basilisk.R

This file was deleted.

9 changes: 4 additions & 5 deletions R/cutadapt.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
#' \dontrun{
#' cutadapt("-h")
#' }
#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
#' @export
cutadapt <- function(args) {
callBasilisk(flames_env, function(x) {
# python_path <- system.file("python", package = "FLAMES")
# mod <- reticulate::import_from_path("cutadapt_wrapper", python_path)
# return(mod$wrapper(as.list(x)))
basiliskRun(env = flames_env, fun = function(x) {
subprocess <- reticulate::import("subprocess")
builtin <- reticulate::import_builtins()
output <- subprocess$check_output(paste("cutadapt", as.list(x), sep=" "), shell=TRUE)
Expand All @@ -22,4 +21,4 @@ cutadapt <- function(args) {
}, x = args)
}

#cutadapt -a 'CCCATGTACTCTGCGTTGATACCACTGCTT' -o cutadapt.fq --untrimmed-output untrimmed.fq ../main/1k.out.fq
# cutadapt usage: cutadapt -a 'CCCATGTACTCTGCGTTGATACCACTGCTT' -o cutadapt.fq --untrimmed-output untrimmed.fq ../main/1k.out.fq
3 changes: 2 additions & 1 deletion R/demultiplex_sockey.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#' @return returns NULL
#' @export
#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
demultiplex_sockeye <- function(fastq_dir, sockeye_tsv, out_fq) {
callBasilisk(flames_env, function(fastq_dir_, sockeye_tsv_, out_fq_) {
basiliskRun(env = flames_env, fun = function(fastq_dir_, sockeye_tsv_, out_fq_) {
python_path <- system.file("python", package = "FLAMES")
demult <- reticulate::import_from_path("demultiplex_sockeye", python_path)
ret <- demult$demultiplex_sockeye(fastq_dir_, sockeye_tsv_, out_fq_)
Expand Down
10 changes: 6 additions & 4 deletions R/filter_gff.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
annotate_filter_gff <-
function(isoform_gff,
ref_gff,
isoform_out,
anno_out,
tr_cnt,
min_sup_reads) {
callBasilisk(flames_env, function(isoform_gff,
basiliskRun(env = flames_env, fun = function(isoform_gff,
ref_gff,
isoform_out,
anno_out,
Expand Down Expand Up @@ -34,10 +35,11 @@ annotate_filter_gff <-
}



#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
annotate_full_splice_match_all_sample <-
function(anno_out, isoform_gff, ref_gff) {
callBasilisk(flames_env, function(anno_out, isoform_gff, ref_gff) {
basiliskRun(env = flames_env, fun = function(anno_out, isoform_gff, ref_gff) {
python_path <- system.file("python", package = "FLAMES")

filter <-
Expand All @@ -49,4 +51,4 @@ annotate_full_splice_match_all_sample <-
)

invisible()
}
}
5 changes: 3 additions & 2 deletions R/find_isoform.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ find_isoform_bambu <- function(annotation, genome_fa, genome_bam, outdir, config

#' @importFrom reticulate import_from_path
#' @importFrom Rsamtools indexFa
#' @importFrom basilisk basiliskRun
find_isoform_flames <- function(annotation, genome_fa, genome_bam, outdir, config) {
if (length(genome_bam) == 1) {
ret <- callBasilisk(flames_env, function(gff3, genome, iso, tss, fa, tran, ds, conf, raw) {
ret <- basiliskRun(env = flames_env, fun = function(gff3, genome, iso, tss, fa, tran, ds, conf, raw) {
python_path <- system.file("python", package = "FLAMES")
find <- reticulate::import_from_path("find_isoform", python_path)
ret <- find$find_isoform(gff3, genome, iso, tss, fa, tran, ds, conf, raw)
Expand All @@ -95,7 +96,7 @@ find_isoform_flames <- function(annotation, genome_fa, genome_bam, outdir, confi
gff3 = annotation, genome = genome_bam, iso = file.path(outdir, "isoform_annotated.gff3"), tss = file.path(outdir, "tss_tes.bedgraph"), fa = genome_fa, tran = file.path(outdir, "transcript_assembly.fa"), ds = config$isoform_parameters$downsample_ratio, conf = config, raw = ifelse(config$isoform_parameters$generate_raw_isoform, file.path(outdir, "splice_raw.gff3"), FALSE)
)
} else {
ret <- callBasilisk(flames_env, function(gff3, genome, iso, tss, fa, tran, ds, conf, raw) {
ret <- basiliskRun(env = flames_env, fun = function(gff3, genome, iso, tss, fa, tran, ds, conf, raw) {
python_path <- system.file("python", package = "FLAMES")
find <- reticulate::import_from_path("find_isoform", python_path)
ret <- find$find_isoform_multisample(gff3, genome, iso, tss, fa, tran, ds, conf, raw)
Expand Down
3 changes: 2 additions & 1 deletion R/parse_gene_anno.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' "chr_to_gene", "transcript_dict", "gene_to_transcript", "transcript_to_exon", containing
#' the data parsed from the gff3 file.
#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
#'
#' @examples
#' temp_path <- tempfile()
Expand All @@ -20,7 +21,7 @@
#' \dontrun{parsed_gff <- parse_gff_tree(gff)}
#' @export
parse_gff_tree <- function(gff_file) {
ret <- callBasilisk(flames_env, function(args) {
ret <- basiliskRun(env = flames_env, fun = function(args) {
python_path <- system.file("python", package = "FLAMES")
parse <-
reticulate::import_from_path("parse_gene_anno", python_path)
Expand Down
12 changes: 8 additions & 4 deletions R/quantification.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#' @importFrom reticulate import_from_path dict
#' @importFrom basilisk basiliskRun
parse_realigned_bam <-
function(bam_in,
fa_idx_f,
Expand All @@ -7,7 +8,7 @@ parse_realigned_bam <-
min_read_coverage,
bc_file) {
ret <-
callBasilisk(flames_env, function(bam_in,
basiliskRun(env = flames_env, fun = function(bam_in,
fa_idx_f,
min_sup_reads,
min_tr_coverage,
Expand Down Expand Up @@ -43,6 +44,7 @@ parse_realigned_bam <-
}

#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
#' @importFrom future plan
wrt_tr_to_csv <-
function(bc_tr_count_dict,
Expand All @@ -51,7 +53,7 @@ wrt_tr_to_csv <-
transcript_dict_ref = NULL,
has_UMI = TRUE) {
future::plan(future::multisession)
callBasilisk(flames_env, function(bc_tr_count_dict,
basiliskRun(env = flames_env, fun = function(bc_tr_count_dict,
transcript_dict,
csv_f,
transcript_dict_ref,
Expand Down Expand Up @@ -101,6 +103,7 @@ wrt_tr_to_csv <-
#' \code{bulk} (bulk, single or multi-sample), or \code{sc_multi_sample} (single-cell, multiple samples)
#' @return The count matrix will be saved in the output folder as \code{transcript_count.csv.gz}.
#' @importFrom reticulate import_from_path dict
#' @importFrom basilisk basiliskRun
quantify_gene <- function(annotation, outdir, n_process, pipeline = "sc_single_sample") {
cat(format(Sys.time(), "%X %a %b %d %Y"), "quantify genes \n")

Expand All @@ -116,7 +119,7 @@ quantify_gene <- function(annotation, outdir, n_process, pipeline = "sc_single_s
stop("Incorrect number of genome alignment files found.\n")
}

callBasilisk(flames_env, function(annotation, outdir,pipeline) {
basiliskRun(env = flames_env, fun = function(annotation, outdir,pipeline) {
python_path <- system.file("python", package = "FLAMES")
count <- reticulate::import_from_path("count_gene", python_path)
count$quantification(annotation, outdir, pipeline, n_process)
Expand All @@ -135,6 +138,7 @@ quantify_gene <- function(annotation, outdir, n_process, pipeline = "sc_single_s
#' @param pipeline The pipeline type as a character string, either \code{sc_single_sample} (single-cell, single-sample),
#' \code{bulk} (bulk, single or multi-sample), or \code{sc_multi_sample} (single-cell, multiple samples)
#' @return The count matrix will be saved in the output folder as \code{transcript_count.csv.gz}.
#' @importFrom basilisk basiliskRun
#' @importFrom reticulate import_from_path dict
#' @examples
#' temp_path <- tempfile()
Expand Down Expand Up @@ -173,7 +177,7 @@ quantify_transcript <- function(annotation, outdir, config, pipeline = "sc_singl
stop("Incorrect number of realignment files found.\n")
}

callBasilisk(flames_env, function(config_dict, annotation, outdir, pipeline) {
basiliskRun(env = flames_env, fun = function(config_dict, annotation, outdir, pipeline) {
python_path <- system.file("python", package = "FLAMES")
count <- reticulate::import_from_path("count_tr", python_path)
count$quantification(config_dict, annotation, outdir, pipeline)
Expand Down
17 changes: 11 additions & 6 deletions R/sc_longread.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
blocks_to_junctions <- function(block) {
junctions <- callBasilisk(flames_env, function(block) {
junctions <- basiliskRun(env = flames_env, fun = function(block) {
python_path <- system.file("python", package = "FLAMES")

sc <-
Expand All @@ -12,11 +13,12 @@ blocks_to_junctions <- function(block) {
}

#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
remove_similar_tr <-
function(gene_to_transcript,
transcript_to_exon,
thr = 10) {
callBasilisk(flames_env, function(gene_tran, tr_exon, thr) {
basiliskRun(env = flames_env, fun = function(gene_tran, tr_exon, thr) {
python_path <- system.file("python", package = "FLAMES")

sc <-
Expand All @@ -31,9 +33,10 @@ remove_similar_tr <-
}

#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
get_gene_flat <- function(gene_to_transcript, transcript_to_exon) {
gene_flat <-
callBasilisk(flames_env, function(gene_tran, tran_exon) {
basiliskRun(env = flames_env, fun = function(gene_tran, tran_exon) {
python_path <- system.file("python", package = "FLAMES")

sc <-
Expand All @@ -45,12 +48,13 @@ get_gene_flat <- function(gene_to_transcript, transcript_to_exon) {
}

#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
get_gene_blocks <-
function(gene_dict,
chr_to_gene,
gene_to_transcript) {
gene_blocks <-
callBasilisk(flames_env, function(g_dict, chr_gene, gene_tran) {
basiliskRun(env = flames_env, fun = function(g_dict, chr_gene, gene_tran) {
python_path <- system.file("python", package = "FLAMES")

sc <-
Expand All @@ -63,6 +67,7 @@ get_gene_blocks <-
}

#' @importFrom reticulate import_from_path
#' @importFrom basilisk basiliskRun
group_bam2isoform <-
function(bam_in,
out_gff3,
Expand All @@ -76,7 +81,7 @@ group_bam2isoform <-
config,
downsample_ratio,
raw_gff3 = NULL) {
callBasilisk(flames_env, function(bin,
basiliskRun(env = flames_env, fun = function(bin,
o_gff3,
o_stat,
summary,
Expand Down Expand Up @@ -114,4 +119,4 @@ group_bam2isoform <-
)

c(out_gff3, out_stat) # output files
}
}
3 changes: 2 additions & 1 deletion R/sc_mutations.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#'
#' @importFrom utils write.csv
#' @importFrom S4Vectors head
#' @importFrom basilisk basiliskRun
#'
#' @examples
#' outdir <- tempfile()
Expand Down Expand Up @@ -90,7 +91,7 @@ sc_mutations <- function(sce, barcode_tsv, bam_short, out_dir, genome_fa, annot,
}

python_path <- system.file("python", package = "FLAMES")
callBasilisk(flames_env, function(fa, bam, dir, barcode, gff, positions, mincov, reportpct) {
basiliskRun(env = flames_env, fun = function(fa, bam, dir, barcode, gff, positions, mincov, reportpct) {
convert <- reticulate::import_from_path("sc_mutations", python_path)
convert$sc_mutations(fa, bam, dir, barcode, gff, positions, mincov, reportpct)
}, fa = genome_fa, bam = ifelse(missing("bam_short"), FALSE, bam_short), dir = out_dir, barcode = barcode_tsv, gff = annot, positions = known_positions, mincov = min_cov, reportpct = report_pct)
Expand Down
23 changes: 0 additions & 23 deletions man/callBasilisk.Rd

This file was deleted.

0 comments on commit fc64827

Please sign in to comment.