How to call BBMap, SAMTools and GATK from Python or Ruby? Need some example scripts, please.
How to call BBMap, SAMTools and GATK from Python or Ruby? Need some example scripts, please.
In python use the subprocess library. No clue about Ruby, though it has an equivalent of making system calls.
You can search the GitHub with keyword "GATK", on the left panel
Select "Code" and in Language section, check "Python".
Here is one actual script from this link , there are 2000+ such scripts, you should be able to find some useful ones for your project. And you can do same for Ruby as well.
from package import * class gatk(Package): dependencies = ['jre_oracle'] def fetch(self): f = self.fillVars('%(srcpath)s/GenomeAnalysisTK-3.3-0.tar.bz2') if not os.path.isfile(f): error('Please supply source file: %s' %f) return f workdir="gatk-3.3-0" create_workdir=True build=""" mkdir -p %(prefix)s/opt/gatk cp -R * %(prefix)s/opt/gatk cd %(prefix)s/opt/gatk """ install=""" cd %(prefix)s/opt/gatk echo "#!/bin/bash" > gatk echo "java -jar %(prefix)s/opt/gatk/GenomeAnalysisTK.jar \$@" >> gatk chmod +x gatk cp ./gatk %(prefix)s/bin/ """
In Ruby, you can call Unix commands using system
, backquotes, open3
, spawn
, etc. You can also use the Rake
and sh
.
In many cases, system
is sufficient, but do you want neat terminal outputs and useful tools? If so, tty-command is a good option.
https://github.com/piotrmurach/tty-command.
cmd.run("samtools version" )
You can run it using package plumbum
.
from plumbum import local
samtools = local['samtools'] # or relative/absolute path to samtools
print(samtools['--help']())
Output:
Program: samtools (Tools for alignments in the SAM format)
Version: 1.8 (using htslib 1.8)
Usage: samtools <command> [options]
Commands:
-- Indexing
dict create a sequence dictionary file
faidx index/extract FASTA
index index alignment
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Google would help you a lot. StackOverflow as well, there are tons of similar questions there. E.g. for Python here and here, and for Ruby here and here.