コード例 #1
0
ファイル: sequtils_test.py プロジェクト: nhoffman/Seq
    def test_find_exec(self):
        cmd = "ls"
        path = Seq.find_exec(cmd)
        self.assertTrue(path)
        if path:
            out = subprocess.call([path], stdout=open(os.devnull, "w"))

        self.assertTrue(out == 0)
コード例 #2
0
ファイル: run_clustalw_test.py プロジェクト: nhoffman/Seq
import sys
import os
import unittest
import logging

import config

import Seq

log = logging

module_name = os.path.split(sys.argv[0])[1].rstrip('.py')
outputdir = config.outputdir
datadir = config.datadir

clustalw_path = Seq.find_exec('clustalw')

class TestClustalwInstalled(unittest.TestCase):
    def test1(self):
        if not clustalw_path:
            log.error('clustalw could not be found - skipping tests in this module')

if clustalw_path is not None:
    class TestRunClustalw(unittest.TestCase):

        def setUp(self):
            self.file1 = os.path.join(datadir, '10patients.fasta')
            self.funcname = '_'.join(self.id().split('.')[-2:])
            self.outfile = os.path.join(outputdir,self.funcname)

        def test1(self):
コード例 #3
0
ファイル: run_hmmer_test.py プロジェクト: nhoffman/Seq
import sys
import os
import unittest
import logging

import config

import Seq

log = logging

module_name = os.path.split(sys.argv[0])[1].rstrip('.py')
outputdir = config.outputdir
datadir = config.datadir

hmmbuild_path = Seq.find_exec('hmmbuild')

class TestHmmerInstalled(unittest.TestCase):
    def test1(self):
        if hmmbuild_path is None:
            log.error('hmmer software could not be found - skipping tests in this module')

if hmmbuild_path is not None:
    class TestRunHmmer(unittest.TestCase):

        def setUp(self):
            self.file1 = os.path.join(datadir, 's_trimmed.aln')
            self.funcname = '_'.join(self.id().split('.')[-2:])
            self.outfile = os.path.join(outputdir,self.funcname)

        def test1(self):
コード例 #4
0
ファイル: run_fasta_test.py プロジェクト: nhoffman/Seq
import os
import unittest
import logging
import pprint

import config

import Seq

log = logging

module_name = os.path.split(sys.argv[0])[1].rstrip('.py')
outputdir = config.outputdir
datadir = config.datadir

fasta_path = Seq.find_exec('fasta35')

class TestFastaInstalled(unittest.TestCase):
    def test1(self):
        if fasta_path is None:
            log.error('fasta35 could not be found - skipping tests in this module')


if fasta_path is not None:
    class TestRunFasta(unittest.TestCase):

        def setUp(self):
            self.file1 = os.path.join(datadir, '10patients.fasta')
            self.funcname = '_'.join(self.id().split('.')[-2:])
            self.outfile = os.path.join(outputdir,self.funcname)
コード例 #5
0
ファイル: run_fasta.py プロジェクト: nhoffman/Seq
def run(query, target, e_val=10, outfile=None,
    fastapath=None, format=10, cleanup=True):

    """Returns a dict keyed by (seqname1,seqname2) pairs containing
    alignment data.

    * query - Seq object or filename of fasta format sequences
    * target - list of Seq objects or filename of fasta format sequences
    * e_val - (see FASTA3* documentation)
    * outfile - name of output file
    * outdir - directory to write fasta output
    * fastapath - name of directory containing fasta3* executable
    * format - (see FASTA3* documentation)
    * cleanup - if True, delete fasta output file
    """

    # see http://helix.nih.gov/apps/bioinfo/fasta3x.txt
    # format = 10 for machine-readable alignments, 0 for traditional aligns

    if outfile:
        outdir = os.path.abspath(os.path.split(outfile)[0])
    else:
        outdir = TEMPDIR
        outfile = os.path.join(outdir, randomname(12)+ALIGN_SUFFIX)

    query_file, query_is_file = get_path_or_write_file(query, outdir)
    target_file, target_is_file = get_path_or_write_file(target, outdir)

    fasta_prog = Seq.find_exec('fasta35', fastapath)
    if fasta_prog is None:
        raise OSError('fasta35 could not be found')

    # -A Force Smith-Waterman alignment
    # -H Omit Histogram
    # -q Quiet - does not prompt for any input.
    # -m format
    # -z 0 estimates the significance of the match from the mean and standard deviation of the library scores, without correcting for library sequence length.
    # -d number of sequences to display
    # -E maximum expect value to display

    fastacmd = ' '.join("""
    %(fasta_prog)s
    -A
    -H
    -q
    -z 0
    -m %(format)s
    -O %(outfile)s
    %(query_file)s
    %(target_file)s""".split())

    cmd = fastacmd % locals()
    log.info( cmd )

    cmd_output = commands.getoutput(cmd)
    log.debug(cmd_output)

    # check for successful execution
    if not os.access(outfile,os.F_OK):
        log.critical('The following command failed:')
        log.critical(cmd)
        log.critical('...with output:')
        log.critical(cmd_output)
        raise Seq.ExecutionError(cmd_output)

    # parse the data
    data = parseFasta(open(outfile).read())

    if cleanup:
        if not query_is_file:
            os.remove(query_file)
        if not target_is_file:
            os.remove(target_file)
        os.remove(outfile)
        query_file = target_file = outfile = None

    for k in data.keys():
        data[k]['file_q'] = query_file
        data[k]['file_t'] = target_file
        data[k]['file_out'] = outfile

    return data
コード例 #6
0
ファイル: run_infernal_test.py プロジェクト: nhoffman/Seq
import os
import unittest
import logging
import pprint

import config

import Seq

log = logging

module_name = os.path.split(sys.argv[0])[1].rstrip('.py')
outputdir = config.outputdir
datadir = config.datadir

cmbuild_path = Seq.find_exec('cmbuild')

class TestInfernalInstalled(unittest.TestCase):
    def test1(self):
        if not cmbuild_path:
            log.error('Infernal software could not be found - skipping tests in this module')

class Test_Run(unittest.TestCase):

    def setUp(self):
        self.funcname = '_'.join(self.id().split('.')[-2:])
        self.outfile = os.path.join(outputdir,self.funcname)
        self.has_space = os.path.join(outputdir,'name with spaces')
        self.no_space = os.path.join(outputdir,'nameWithoutSpaces')

        os.system('echo `date` has space > "%s"' % self.has_space)