How to call BBMap, SAMTools and GATK from Python or Ruby?
4
0
Entering edit mode
6.7 years ago
vassialk ▴ 200

How to call BBMap, SAMTools and GATK from Python or Ruby? Need some example scripts, please.

software sequencing wgs • 4.4k views
ADD COMMENT
1
Entering edit mode

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.

ADD REPLY
2
Entering edit mode
6.7 years ago

In python use the subprocess library. No clue about Ruby, though it has an equivalent of making system calls.

ADD COMMENT
0
Entering edit mode

thank you, are there any actual sample scripts available somewhere?

ADD REPLY
1
Entering edit mode
6.7 years ago
Tky ★ 1.0k

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/
    """ 
ADD COMMENT
0
Entering edit mode

Thank you --------------------------

ADD REPLY
1
Entering edit mode
8 weeks ago
kojix2 ▴ 220

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" )
ADD COMMENT
1
Entering edit mode

With python you can do os.system with a string that you create that matches what you would type into the command line

ADD REPLY
0
Entering edit mode
3.2 years ago

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
ADD COMMENT

Login before adding your answer.

Traffic: 1772 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6