Run a shell script in R with multithreading

1.3k views Asked by At

I want to run a shell script (BLAST+ in NCBI) in R with command system(), but it seems to use only one thread even if I set multiple threads in the shell script. What should I do to use multiple threads in this case?

The code is system("blastp -query query.fasta -db db.fasta -num_threads 16 -outfmt \"6 qseqid sseqid pident ppos evalue bitscore qcovs\" -out out.tsv")

How do I get this run with 16 cores in R? Thanks!

1

There are 1 answers

2
user 123342 On

With parallel:

library(parallel)
ncore = 4

syscall = system("blastp -query query.fasta -db db.fasta -num_threads 16 -outfmt \"6 qseqid sseqid pident ppos evalue bitscore qcovs\" -out out.tsv")
mclapply(1:ncore,syscall,mc.cores=ncore)