Exemplo n.º 1
0
def test_help(capsys):
    args.build_parser(modules=get_all_modules()).print_help()
    out, err = capsys.readouterr()
    assert "--minimal" not in out

    args.build_parser(modules=get_all_modules()).print_help(show_all=True)
    out_all, err_all = capsys.readouterr()
    assert err == err_all and not err
    # make sure show_all does something
    assert out != out_all
    assert "--minimal" in out_all
Exemplo n.º 2
0
    def test_config_files(self):
        # TODO change some values in the file generated and check they're kept
        with TemporaryDirectory(change=True):
            args.build_parser()
            parser = args.build_parser(modules=get_all_modules())
            default_options = parser.parse_args([])
            parser.write_to_config_file("default_options.cfg")

            parser = args.build_parser(modules=get_all_modules(), from_config_file=True)
            from_file = parser.parse_args(["@default_options.cfg"])
            assert vars(default_options) == vars(from_file)
Exemplo n.º 3
0
 def setUp(self):
     options = build_config(
         ["--minimal", "--enable-tta", "--tta-threshold", "0"],
         isolated=True,
         modules=antismash.get_all_modules())
     self.old_config = get_config().__dict__
     self.options = update_config(options)
Exemplo n.º 4
0
 def setUp(self):
     self.options = build_config(["--minimal"],
                                 isolated=True,
                                 modules=antismash.get_all_modules())
     assert not nrps_pks.is_enabled(self.options)
     self.tracker = minimock.TraceTracker()
     minimock.mock("nrps_pks.run_on_record", tracker=self.tracker)
Exemplo n.º 5
0
    def test_nisin_complete(self):
        with TemporaryDirectory() as output_dir:
            args = [
                "--minimal", "--enable-tta", "--tta-threshold", "0",
                "--output-dir", output_dir,
                helpers.get_path_to_nisin_genbank()
            ]
            options = build_config(args,
                                   isolated=True,
                                   modules=antismash.get_all_modules())
            antismash.run_antismash(helpers.get_path_to_nisin_genbank(),
                                    options)

            # regen the results
            update_config(
                {"reuse_results": os.path.join(output_dir, "nisin.json")})
            prior_results = read_data(None, options)
            record = prior_results.records[0]
            results = prior_results.results[0]
            tta_results = tta.regenerate_previous_results(
                results.get("antismash.modules.tta"), record, options)
            assert isinstance(tta_results, tta.TTAResults)
            assert len(tta_results.features) == 174

            # raise the threshold above the gc_content and ensure regenned has no hits
            update_config({"tta_threshold": 0.65})
            tta_results = tta.regenerate_previous_results(
                results.get("antismash.modules.tta"), record, options)
            assert isinstance(tta_results, tta.TTAResults)
            assert not tta_results.features
Exemplo n.º 6
0
    def setUp(self):
        self._old_max_evalue = cluster_hmmer.MAX_EVALUE
        self._old_min_score = cluster_hmmer.MIN_SCORE
        cluster_hmmer.MAX_EVALUE = 0.02
        cluster_hmmer.MIN_SCORE = 1.
        self.config = build_config([],
                                   isolated=True,
                                   modules=antismash.get_all_modules())
        self.latest_pfam = pfamdb.find_latest_database_version(
            self.config.database_dir)
        self.tracer = TraceTracker()
        self.file_list = [
            'Pfam-A.hmm', 'Pfam-A.hmm.h3f', 'Pfam-A.hmm.h3i', 'Pfam-A.hmm.h3m',
            'Pfam-A.hmm.h3p'
        ]
        mock('antismash.common.path.locate_file',
             returns_iter=self.file_list,
             tracker=self.tracer)
        mock('antismash.common.subprocessing.run_hmmscan', returns=[])

        self.expected_trace = """Called antismash.common.path.locate_file(
    '{0}/pfam/{1}/Pfam-A.hmm')
Called antismash.common.path.locate_file(
    '{0}/pfam/{1}/Pfam-A.hmm.h3f')
Called antismash.common.path.locate_file(
    '{0}/pfam/{1}/Pfam-A.hmm.h3i')
Called antismash.common.path.locate_file(
    '{0}/pfam/{1}/Pfam-A.hmm.h3m')
Called antismash.common.path.locate_file(
    '{0}/pfam/{1}/Pfam-A.hmm.h3p')""".format(self.config.database_dir,
                                             self.latest_pfam)
Exemplo n.º 7
0
 def test_minimal(self):
     with TemporaryDirectory(change=True) as tempdir:
         self.options = build_config(["--minimal", "--output-dir", tempdir],
                                     isolated=True, modules=antismash.get_all_modules())
         with patch.object(nrps_pks, "run_on_record", side_effect=RuntimeError("shouldn't run")):
             antismash.main.run_antismash(helpers.get_path_to_balhymicin_genbank(),
                                          self.options)
Exemplo n.º 8
0
 def test_CP009369(self):  # pylint: disable=invalid-name
     " tests the special case HMM files for rodeo "
     config = build_config(["--minimal", "--enable-thiopeptides"],
                           isolated=True,
                           modules=antismash.get_all_modules())
     record_path = path.get_full_path(__file__, 'data', 'CP009369.1.gbk')
     results = helpers.run_and_regenerate_results_for_module(
         record_path, thiopeptides, config)
     assert results
     assert len(results.motifs) == 1
     prepeptide = results.motifs[0]
     self.assertAlmostEqual(1934.6, prepeptide.monoisotopic_mass, places=1)
     self.assertAlmostEqual(1936.0, prepeptide.molecular_weight, places=1)
     assert prepeptide.leader == "MVKSIIKARESGRFYETKYLKGGEEMKEQKELKNEEFELDVEFLDLDEVSAIPETTA"
     assert prepeptide.core == "SSGTSSCSASSTCGSSSCCGSC"
     assert not prepeptide.macrocycle
     assert prepeptide.peptide_subclass == "Type III"
     assert prepeptide.core_features == 'Central ring: pyridine trisubstituted'
     assert prepeptide.tail == ''
     for calc, expected in zip(prepeptide.alternative_weights, [
             1954.0, 1972.1, 1990.1, 2008.1, 2026.1, 2044.1, 2062.2, 2080.2,
             2098.2, 2116.2, 2134.2, 2152.3, 2170.3
     ]):
         self.assertAlmostEqual(calc, expected, places=1)
     assert len(prepeptide.to_biopython()) == 2  # no tail
Exemplo n.º 9
0
 def setUp(self):
     self.original_min_score = full_hmmer.MIN_SCORE
     self.original_max_evalue = full_hmmer.MAX_EVALUE
     self.options = build_config(["--fullhmmer", "--minimal"],
                                 isolated=True,
                                 modules=antismash.get_all_modules())
     self.pfam_db = pfamdb.get_latest_db_path(self.options.database_dir)
Exemplo n.º 10
0
 def setUp(self):
     self._old_max_evalue = tigrfam.MAX_EVALUE
     self._old_min_score = tigrfam.MIN_SCORE
     tigrfam.MAX_EVALUE = 0.02
     tigrfam.MIN_SCORE = 1.
     self.config = build_config([],
                                isolated=True,
                                modules=antismash.get_all_modules())
Exemplo n.º 11
0
 def test_minimal(self):
     with TemporaryDirectory(change=True) as tempdir:
         self.options = build_config(["--minimal", "--output-dir", tempdir],
                                     isolated=True, modules=antismash.get_all_modules())
         antismash.main.run_antismash(helpers.get_path_to_balhymicin_genbank(),
                                      self.options)
     # make sure it didn't run
     minimock.assert_same_trace(self.tracker, "")
Exemplo n.º 12
0
def main(args: List[str]) -> int:
    """ The entrypoint of antiSMASH as if it was on the command line

        Arguments:
            args: a list of args as would be given on the command line
                    e.g. ["inputfile", "--minimal", "--enable-nrps_pks"]

        Returns:
            zero if successful, non-zero otherwise

    """
    all_modules = antismash.get_all_modules()
    parser = antismash.config.args.build_parser(from_config_file=True,
                                                modules=all_modules)

    # if --help, show help texts and exit
    if set(args).intersection({"-h", "--help", "--help-showall"}):
        parser.print_help(None, "--help-showall" in args)
        return 0

    options = antismash.config.build_config(args, parser=parser)

    if options.write_config_file:
        parser.write_to_config_file(options.write_config_file,
                                    options.__dict__)
        return 0

    # if -V, show version text and exit
    if options.version:
        print("antiSMASH %s" % get_version())
        return 0

    if len(options.sequences) > 1:
        parser.error("Only one sequence file should be provided")
        return 1
    if len(options.sequences) < 1 and not options.reuse_results \
            and not options.check_prereqs_only and not options.list_plugins:
        parser.error(
            "One of an input file or --reuse-results must be specified")
        return 1
    if options.sequences and options.reuse_results:
        parser.error("Provide a sequence file or results to reuse, not both.")
        return 1
    if options.sequences:
        sequence = options.sequences[0]
        if not os.path.exists(sequence):
            parser.error("Input file does not exist: %s" % sequence)
            return 1
    else:
        sequence = ""

    if options.reuse_results and not os.path.exists(options.reuse_results):
        parser.error("Input file does not exist: %s" % options.reuse_results)
        return 1

    options.version = get_version()

    return antismash.run_antismash(sequence, options)
Exemplo n.º 13
0
 def setUp(self):
     self._old_max_evalue = full_hmmer.MAX_EVALUE
     self._old_min_score = full_hmmer.MIN_SCORE
     full_hmmer.MAX_EVALUE = 0.02
     full_hmmer.MIN_SCORE = 1.
     self.config = build_config([],
                                isolated=True,
                                modules=antismash.get_all_modules())
     self.latest_pfam = pfamdb.find_latest_database_version(
         self.config.database_dir)
 def test_options(self):
     assert rrefinder.check_options(self.options) == []
     assert rrefinder.check_prereqs(self.options) == []
     assert rrefinder.is_enabled(self.options)
     
     options = build_config(["--minimal", "--rre-run", "--rre-cutoff", "-10"],
               isolated=True, modules=antismash.get_all_modules())
     issues = rrefinder.check_options(options)
     assert len(issues) == 1
     assert issues[0] == 'Supplied RREFinder cutoff is negative: %s' %options.rre_cutoff
Exemplo n.º 15
0
    def setUp(self):
        options = build_config(self.get_args(),
                               isolated=True,
                               modules=antismash.get_all_modules())
        self.old_config = get_config().__dict__
        self.options = update_config(options)

        self.record = self.build_record(
            helpers.get_path_to_nisin_with_detection())

        prepare_data()
Exemplo n.º 16
0
def build_json_data(
    records: List[Record],
    results: List[Dict[str, module_results.ModuleResults]], options: ConfigType
) -> Tuple[List[Dict[str, Any]], List[Dict[str, Union[str, List[JSONOrf]]]],
           Dict[str, Dict[str, Dict[str, Any]]]]:
    """ Builds JSON versions of records and domains for use in drawing SVGs with
        javascript.

        Arguments:
            records: a list of Records to convert
            results: a dictionary mapping record id to a list of ModuleResults to convert
            options: antiSMASH options

        Returns:
            a tuple of
                a list of JSON-friendly dicts representing records
                a list of JSON-friendly dicts representing domains
    """

    from antismash import get_all_modules  # TODO break circular dependency
    js_records = js.convert_records(records, results, options)

    js_domains: List[Dict[str, Union[str, List[JSONOrf]]]] = []
    js_results = {}

    for i, record in enumerate(records):
        json_record = js_records[i]
        json_record['seq_id'] = "".join(char for char in json_record['seq_id']
                                        if char in string.printable)
        for region, json_region in zip(record.get_regions(),
                                       json_record['regions']):
            handlers = find_plugins_for_cluster(get_all_modules(), json_region)
            region_results = {}
            for handler in handlers:
                # if there's no results for the module, don't let it try
                if handler.__name__ not in results[i]:
                    continue
                if "generate_js_domains" in dir(handler):
                    domains_by_region = handler.generate_js_domains(
                        region, record)
                    if domains_by_region:
                        js_domains.append(domains_by_region)
                if hasattr(handler, "generate_javascript_data"):
                    region_results[
                        handler.__name__] = handler.generate_javascript_data(
                            record, region, results[i][handler.__name__])
            if region_results:
                js_results[RegionLayer.build_anchor_id(
                    region)] = region_results

    return js_records, js_domains, js_results
    def test_options(self):
        assert rrefinder.check_options(self.options) == []
        assert rrefinder.check_prereqs(self.options) == []
        assert rrefinder.is_enabled(self.options)

        options = build_config([
            "--minimal", "--rre", "--rre-cutoff", "-10", "--rre-minlength",
            "-1"
        ],
                               isolated=True,
                               modules=antismash.get_all_modules())
        issues = rrefinder.check_options(options)
        assert len(issues) == 2
        assert "RREFinder cutoff is negative" in issues[0]
        assert "RREFinder minimum length is negative" in issues[1]
Exemplo n.º 18
0
    def test_nisin_complete(self):
        with TemporaryDirectory() as output_dir:
            args = [
                "run_antismash.py", "--minimal", "--enable-lanthipeptides",
                "--output-dir", output_dir
            ]
            options = build_config(args,
                                   isolated=True,
                                   modules=antismash.get_all_modules())
            antismash.run_antismash(helpers.get_path_to_nisin_genbank(),
                                    options)

            # make sure the html_output section was tested
            with open(os.path.join(output_dir, "index.html")) as handle:
                content = handle.read()
                assert "nisA leader / core peptide" in content
Exemplo n.º 19
0
    def test_thiostrepton_full(self):
        def callback(outdir):
            # make sure the html_output section was tested
            with open(os.path.join(outdir, "index.html")) as handle:
                content = handle.read()
                assert "ACN52291.1 leader / core peptide, putative Type II" in content

        config = build_config(["--minimal", "--enable-thiopeptides"],
                              isolated=True,
                              modules=antismash.get_all_modules())

        record_path = path.get_full_path(__file__, 'data',
                                         'thiostrepton_before_analysis.gbk')
        regenned_results = helpers.run_and_regenerate_results_for_module(
            record_path, thiopeptides, config, callback=callback)
        assert regenned_results
        assert len(regenned_results.motifs) == 1
        self.check_thiostrepton_values(regenned_results.motifs[0])
Exemplo n.º 20
0
    def test_trees_complete(self):
        with TemporaryDirectory() as output_dir:
            args = [
                "--minimal", "--enable-genefunctions", "--smcog-trees",
                "--output-dir", output_dir,
                helpers.get_path_to_nisin_genbank()
            ]
            options = build_config(args,
                                   isolated=True,
                                   modules=antismash.get_all_modules())
            antismash.run_antismash(helpers.get_path_to_nisin_genbank(),
                                    options)

            with open(os.path.join(output_dir, "nisin.json")) as res_file:
                assert "antismash.modules.smcog_trees" in res_file.read()

            tree_files = list(
                glob.glob(os.path.join(output_dir, "smcogs", "*.png")))
            assert len(tree_files) == 7
            sample_tree = tree_files[0]

            # regen the results
            update_config(
                {"reuse_results": os.path.join(output_dir, "nisin.json")})
            prior_results = read_data(None, options)
            record = prior_results.records[0]
            results = prior_results.results[0]
            tree_results = results["antismash.modules.smcog_trees"]

            smcogs_results = smcog_trees.regenerate_previous_results(
                tree_results, record, options)
            assert len(smcogs_results.tree_images) == 7
            assert os.path.exists(sample_tree)

            os.unlink(sample_tree)
            assert not os.path.exists(sample_tree)

            # attempt to regen the results, the deleted tree image will prevent it
            prior_results = read_data(None, options)
            record = prior_results.records[0]
            results = prior_results.results[0]
            smcogs_results = smcog_trees.regenerate_previous_results(
                tree_results, record, options)
            assert smcogs_results is None
Exemplo n.º 21
0
    def setUp(self):
        self.old_config = get_config().__dict__
        options = build_config(self.get_args(),
                               isolated=True,
                               modules=antismash.get_all_modules())
        self.options = update_config(options)
        update_config({"cpus": 1})
        # prevent multiprocess testing from taking place, to stop signals
        # being caught awkwardly in the test itself

        # as smcogs_trees depends on genefunctions.smcogs' data, ensure that's ready to go
        assert genefunctions.prepare_data() == []

        assert smcog_trees.check_prereqs() == []
        assert smcog_trees.check_options(self.options) == []
        assert smcog_trees.is_enabled(self.options)

        self.record = self.build_record(
            helpers.get_path_to_nisin_with_detection())
Exemplo n.º 22
0
    def setUp(self):
        options = build_config(self.get_args(),
                               isolated=True,
                               modules=antismash.get_all_modules())
        self.old_config = get_config().__dict__
        self.options = update_config(options)

        assert smcogs.check_prereqs() == []
        assert smcogs.check_options(self.options) == []
        assert smcogs.is_enabled(self.options)

        self.record = self.build_record(
            helpers.get_path_to_nisin_with_detection())

        def serial_run_func(function, arg_sets, _timeout=None):
            for arg_set in arg_sets:
                function(*arg_set)

        self.old_parallel = subprocessing.parallel_function
        subprocessing.parallel_function = serial_run_func
Exemplo n.º 23
0
    def setUp(self):
        self.hits = [
            DummyHmmerHit(locus_tag="a",
                          protein_start=0,
                          protein_end=50,
                          score=38.0,
                          domain="RRE_type_A",
                          identifier="RREFam001.1"),
            DummyHmmerHit(locus_tag="b",
                          protein_start=0,
                          protein_end=90,
                          score=25.0,
                          domain="RRE_type_B",
                          identifier="RREFam002.1")
        ]

        self.hits_by_cds = {hit.locus_tag: [hit] for hit in self.hits}
        self.hits_by_protocluster = {
            1: [self.hits[0].locus_tag],
            2: [self.hits[1].locus_tag]
        }
        self.tool = 'rrefinder'
        self.database = 'RREFam.hmm'
        self.detection = 'hmmscan'

        self.min_length = 50
        self.bitscore_cutoff = 25.0

        build_config([
            "--rre",
            "--rre-cutoff",
            "%.1f" % self.bitscore_cutoff,
            "--rre-minlength",
            "%i" % self.min_length,
        ],
                     isolated=True,
                     modules=antismash.get_all_modules())

        # Here a mock so that the call to its functions can be tracked
        self.record = unittest.mock.Mock()
        self.record.id = 'test_record'
Exemplo n.º 24
0
    def test_nisin_complete(self):
        with TemporaryDirectory() as output_dir:
            args = [
                "--minimal", "--tta", "--output-dir", output_dir,
                helpers.get_path_to_nisin_genbank()
            ]
            options = build_config(args,
                                   isolated=True,
                                   modules=antismash.get_all_modules())
            antismash.run_antismash(helpers.get_path_to_nisin_genbank(),
                                    options)

            # regen the results
            update_config(
                {"reuse_results": os.path.join(output_dir, "nisin.json")})
            prior_results = read_data(None, options)
            record = prior_results.records[0]
            results = prior_results.results[0]
            regenned = regenerate_results_for_record(record, options, [tta],
                                                     results)
            tta_results = regenned["antismash.modules.tta"]
            assert isinstance(tta_results, tta.TTAResults)
            assert len(tta_results.features) == 174
Exemplo n.º 25
0
 def setup_options(self, args):
     return build_config(args,
                         isolated=True,
                         modules=antismash.get_all_modules())
 def setUp(self):
     self.options = build_config(["--minimal", "--enable-lassopeptides"],
                                 isolated=True, modules=antismash.get_all_modules())
     check_prereqs(self.options)
 def setUp(self):
     self.options = build_config(["--minimal", "--rre-run"],
                    isolated=True, modules=antismash.get_all_modules())
Exemplo n.º 28
0
 def setUp(self):
     # skipping clusterhmmer and the p450 potential hits for speed
     self.options = build_config(["--minimal"],
                                 isolated=True,
                                 modules=antismash.get_all_modules())
Exemplo n.º 29
0
 def setUp(self):
     self.options = build_config(["--minimal", "--enable-nrps-pks"],
                                 isolated=True, modules=antismash.get_all_modules())
Exemplo n.º 30
0
 def setUp(self):
     self.options = build_config(["--minimal", "--enable-lanthipeptides"],
                                 isolated=True,
                                 modules=antismash.get_all_modules())
     self.set_fimo_enabled(True)