def manage_config(cmd): """Manage genomepy config file.""" if cmd == "file": print(config.config_file) elif cmd == "show": with open(config.config_file) as f: print(f.read()) elif cmd == "generate": config_dir = user_config_dir("genomepy") if not os.path.exists(config_dir): mkdir_p(config_dir) new_config = os.path.join(config_dir, "genomepy.yaml") # existing config must be removed before norns picks up the default again if os.path.exists(new_config): os.unlink(new_config) default_config = norns.config("genomepy", default="cfg/default.yaml").config_file with open(new_config, "w") as fout, open(default_config) as fin: fout.write(fin.read()) config.config_file = new_config print(f"Created config file {new_config}") else: raise ValueError(f"Invalid config command: {cmd}")
from bucketcache import Bucket from pyfaidx import Fasta from appdirs import user_cache_dir from genomepy import exceptions from genomepy.utils import filter_fasta, get_localname from genomepy.__about__ import __version__ my_cache_dir = os.path.join(user_cache_dir("genomepy"), __version__) # Create .cache dir if it does not exist if not os.path.exists(my_cache_dir): os.makedirs(my_cache_dir) cached = Bucket(my_cache_dir, days=7) config = norns.config("genomepy", default="cfg/default.yaml") class ProviderBase(object): """Provider base class. Use to get a list of available providers: >>> ProviderBase.list_providers() ['UCSC', 'NCBI', 'Ensembl'] Create a provider: >>> p = ProviderBase.create("UCSC") >>> for name, desc in p.search("hg38"): ... print(desc) Human Dec. 2013 (GRCh38/hg38) Genome at UCSC """
import os import sys import re import norns config = norns.config("genomepy", default="cfg/default.yaml") class Plugin(object): """Plugin base class. """ active = False def name(self): n = type(self).__name__.replace("Plugin", "") return convert(n) def activate(self): self.active = True def deactivate(self): self.active = False def after_genome_download(self, genome): raise NotImplementedError("plugin should implement this method") def get_properties(self, genome): raise NotImplementedError("plugin should implement this method") def find_plugins(): """Locate and initialize all available plugins.
def test_config(): config = norns.config("genomepy", default="cfg/default.yaml") assert len(config.keys()) == 3
def test_no_arguments(): cfg = norns.config()
def test_basic(): cfg = norns.config(config_file="tests/data/simple.yaml") assert cfg["integer"] == 10 assert cfg["path"] == "/home/simon" assert 3 == len(cfg.keys())