Exemplo n.º 1
0
    def test_scan_illustrate(self):

        lo.setLevel(logging.WARNING)

        # do a complete scan with a known result; specify variatn
        out, err = self.scan_illustrate(MTBC_fastq1,
                ['--variant', 'Illumina 1.8+'])
        for resistance in [
                'Streptomycin resistance::SNP781687AG=rpsL.K43R',
                'Ethambutol resistance::SNP4247431GT=embB.M306I',
                'Isoniazid resistance [2155168CG=katG.S315T]',
                'Rifampicin resistance (RRDR) [761139CG=rpoB.H445D 761140AG=rpoB.H445R]',
                'remark: low coverage (RRDR below 10x)']:
            assert resistance in out, MTBC_fastq1 + ' should have ' + resistance
        assert 'lineage 3' in out, MTBC_fastq1 + ' should be Lineage 3'

        # another tested .fsatq
        out, err = self.scan_illustrate(MTBC_fastq2)
        for resistance in [
                'Streptomycin resistance::SNP781687AG=rpsL.K43R',
                'remark: low coverage (RRDR below 10x)']:
            assert resistance in out, MTBC_fastq2 + ' should have ' + resistance
        assert 'lineage 2' in out, MTBC_fastq2 + ' should be Lineage 2'

        lo.setLevel(logging.INFO)
Exemplo n.º 2
0
    def test_fastq_variant(self):
        lo.setLevel(logging.WARNING)

        fq = self.ntf_write_quality('!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJ');
        assert fq.dQ == 0 and set(fq.variants) == set(['Illumina 1.8+', 'Sanger']), \
                'FastQ variant should be Illumina 1.8+ / Sanger (dQ=0)'

        fq = self.ntf_write_quality(';<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefgh')
        assert fq.dQ == 31 and fq.variants == ['Solexa'], \
                'FastQ variant should be Solexa (dQ=31)'

        fq = self.ntf_write_quality('OPQRSTUVWXYZ[\]^_`abcdefgh')
        assert fq.dQ == 31 and fq.variants == ['Solexa', 'Illumina 1.3+', 'Illumina 1.5+'], \
                "FastQ variant should be ['Solexa', 'Illumina 1.3+', 'Illumina 1.5+'] (dQ=31)"
        try:
            fq = self.ntf_write_quality(';<=>?@ABCDEFGHI;<=>?@ABCDEFGHI')
            raise Exception(
                    'Quality score ";<=>?@ABCDEFGHI" ambiguous, should not be decoded!')
        except FastqFileFormatException:
            pass

        # specify valid vendor variants
        fq = self.ntf_write_quality(';<=>?@ABCDEFGHI;<=>?@ABCDEFGHI',
                variant='Sanger')
        fq = self.ntf_write_quality(';<=>?@ABCDEFGHI;<=>?@ABCDEFGHI',
                variant='Solexa')

        # specify invalid vendor variant, must emit warning
        lo_assert = lo_exceptor('seems not to be compatible', logging.WARNING, True)
        fq = self.ntf_write_quality(';<=>?@ABCDEFGHI;<=>?@ABCDEFGHI',
                variant='Illumina 1.3+')
        lo_assert()

        lo.setLevel(logging.INFO)
Exemplo n.º 3
0
    def scan_illustrate(self, MTBC_fastq, scan_params=[]):

        ntf = tempfile.NamedTemporaryFile(delete=False)
        lo.setLevel(logging.WARNING)

        try:

            t0 = time.time()
            out, err = self.main(['scan', '-l', 'MTBC', '-f'] + scan_params + [
                MTBC_fastq, ntf.name])

            if time.time() - t0 > 10:
                lo.warning('scanning of %s took %.2fs' % (
                    os.path.basename(MTBC_fastq), time.time() - t0))

            out, err = self.main(['illustrate', '-r',
                ntf.name])

        finally:
            lo.setLevel(logging.INFO)
            ntf.close()
            os.remove(ntf.name)

        return out, err
Exemplo n.º 4
0
    def test_load_testsuites(self):


        def get_testsuites(out):
            line = [line for line in out.split('\n')
                    if line.startswith('testsuites=')][0]
            return set([testsuite
                for testsuite in line[line.index('=')+1:].split(',')
                if testsuite])

        def name_and_version(testsuites):
            return set([testsuite[:testsuite.find('[')]
                for testsuite in testsuites])

        def name_only(testsuites):
            return set([testsuite[:testsuite.find('-')]
                for testsuite in testsuites])

        cwd = os.getcwd()

        out, err = self.main(['info'])
        assert get_testsuites(out) == set()

        # suppress "loaded testsuite" messages
        lo.setLevel(logging.WARNING)

        MTBC_testsuites = set(['MTBC/phylo', 'MTBC/resistance', 'MTBC/spoligo'])

        # select testsuite
        out, err = self.main(['info', '-l', 'MTBC/phylo'])
        assert name_only(get_testsuites(out)) == set(['MTBC/phylo'])

        # select group
        out, err = self.main(['info', '-l', 'MTBC'])
        assert name_only(get_testsuites(out)) == MTBC_testsuites

        # select testsuite by filename
        path = os.path.join(testsuites_alt, 'MTBC', 'phylo.py')
        out, err = self.main(['info', '-l', path])
        assert name_and_version(get_testsuites(out)) == set(['MTBC/phylo-0.0'])

        # override testsuite directory using switch
        out, err = self.main(['info', '-l', 'MTBC/phylo'])
        assert name_and_version(get_testsuites(out)) != set(['MTBC/phylo-0.0'])
        out, err = self.main(['-t', testsuites_alt, 'info', '-l', 'MTBC/phylo'])
        assert name_and_version(get_testsuites(out)) == set(['MTBC/phylo-0.0'])

        # override testsuite directory using KVARQ_TESTSUITES
        os.environ['KVARQ_TESTSUITES'] = testsuites_alt
        out, err = self.main(['info', '-l', 'MTBC/phylo'])
        assert name_and_version(get_testsuites(out)) == set(['MTBC/phylo-0.0'])
        del os.environ['KVARQ_TESTSUITES']

        # time load all
        t0 = time.time()
        out, err = self.main(['info', '-L'])
        assert len(name_only(get_testsuites(out))) > 4
        if time.time() - t0 > 2:
            lo.warning('loading all testsuites takes %.2f' % (time.time() - t0))

        lo.setLevel(logging.INFO)
        os.chdir(cwd)
Exemplo n.º 5
0
 def tearDownClass(cls):
     lo.setLevel(logging.INFO)
Exemplo n.º 6
0
 def setUpClass(cls):
     lo.setLevel(logging.WARNING)
     cls.testsuite_paths = discover_testsuites([testsuites_alt])
     cls.testsuites = load_testsuites(cls.testsuite_paths, ['MTBC'])