예제 #1
0
파일: config.py 프로젝트: cokelaer/damona
    def __init__(self):
        from easydev import CustomConfig
        configuration = CustomConfig("damona", verbose=True)

        #  let us add a damona.cfg in it. This will store URLs to look for singularities
        # This is done only once to not overwrite user options
        self.user_config_dir = pathlib.Path(configuration.user_config_dir)

        self.config_file = self.user_config_dir / "damona.cfg"
        if self.config_file.exists() is False:  #pragma: no cover
            with open(self.config_file, "w") as fout:
                fout.write("[general]\n")
                fout.write("show_init_warning_message=False\n\n")
                fout.write("[urls]\n")
                for k, v in urls.items():
                    fout.write("{}={}".format(k, v))
        else:
            logger.debug("damona.cfg file exists already. Reading it")

        # read the config
        self.read()

        # create the shell script once for all
        created = self.add_shell()
        if created:
            logger.critical(
                "Please start a new shell to benefit from "
                "the configuration file and activate/deactivate command")
            sys.exit(1)
예제 #2
0
 def _init_config_file(self):
     # do not import sequana, save time, let us use easydev
     from easydev import CustomConfig
     configuration = CustomConfig("sequana", verbose=False)
     sequana_config_path = configuration.user_config_dir
     path = sequana_config_path + os.sep + "pipelines"
     if os.path.exists(path):
         pass
     else:  #pragma: no cover
         os.mkdir(path)
     self.config_path = path
     return path
예제 #3
0
파일: setup.py 프로젝트: cokelaer/damona
def copyfile():
    try:
        # This is to make sure users get the newest version installed
        # If it fails, this will be copied again when calling damona for the
        # first time.
        from easydev import CustomConfig
        configuration = CustomConfig("damona", verbose=True)
        damona_config_path = configuration.user_config_dir
        with open("damona/shell/damona.sh", "r") as fin:
            with open(damona_config_path + os.sep + "damona.sh", "w") as fout:
                fout.write(fin.read())
    except:
        # could not copy the file, we will do it when starting damona for the
        # first time. 
        pass
예제 #4
0
try:
    # This is not striclty speaking required to run and use bioservices
    # However, some functions and python notebooks included in bioservices do
    import pandas as pd
except:
    print("BioServices %s warning: pandas is not installed on your system." %
          version)
    print(
        "Some features requires this library and future version of BioServices may use it."
    )

# Initialise the config directory if not already done
from easydev import CustomConfig

configuration = CustomConfig("bioservices", verbose=False)
bspath = configuration.user_config_dir

# Add bioservices.uniprot to sys.modules to prevent cycles in our imports
#import bioservices.uniprot
#bioservices.uniprot  # Stop flake8 error

from . import settings
from .settings import *

from . import services
from .services import *

from . import biodbnet
from .biodbnet import *
예제 #5
0
import pkg_resources
try:
    version = pkg_resources.require("sequana")[0].version
except:
    version = ">=0.7.1"

try:
    from easydev.logging_tools import Logging
    logger = Logging("sequana", "WARNING")
except:
    import colorlog
    logger = colorlog.getLogger("sequana")

from easydev import CustomConfig
configuration = CustomConfig("sequana", verbose=False)
sequana_config_path = configuration.user_config_dir

# This must be import before all other modules (sequana_data function)
from .datatools import sequana_data

from .assembly import *
from .adapters import AdapterReader, FindAdaptersFromDesign, Adapter
from .bamtools import BAM, SAMFlags, SAM, CRAM
from .bedtools import GenomeCov
from .cigar import Cigar
from .coverage import Coverage
from .expdesign import ExpDesignAdapter
from .fastq import FastQ, FastQC, Identifier
from .fasta import FastA
from .freebayes_vcf_filter import VCF_freebayes
from .freebayes_bcf_filter import BCF_freebayes
예제 #6
0
def test_config_custom():
    c = CustomConfig('dummy')
    c.init()
    c.user_config_dir
    c.remove()
예제 #7
0
__version__ = "0.1.2"
import pkg_resources
try:
    version = pkg_resources.require('bioconvert')[0].version
except:
    version = __version__

import os
import colorlog

# This will create a HOME/.config/bioconvert where files (e.g., executables)
# can be downloaded
from easydev import CustomConfig
configuration = CustomConfig("bioconvert", verbose=True)

os.environ["GOPATH"]= os.environ["HOME"]+"/go"
os.environ["PATH"] = os.environ["GOPATH"]+"/bin/:"+os.environ["PATH"]

from easydev.logging_tools import Logging
logger = Logging("bioconvert", "INFO")


def bioconvert_script(filename, where=None):
    bioconvert_path = bioconvert.__path__[0]
    share = os.path.join(bioconvert_path, 'misc')
    if where:
        filename = os.path.join(share, where, filename)
    else:
        filename = os.path.join(share, filename)
    if not os.path.exists(filename):
        raise FileNotFoundError('unknown file {}'.format(filename))
예제 #8
0
    def teardown(self, check_schema=True, check_input_files=True):
        """Save all files required to run the pipeline and perform sanity checks


        We copy the following files into the working directory:

        * the config file (config.yaml)
        * a NAME.sh that contains the snakemake command
        * the Snakefile (NAME.rules)

        For book-keeping and some parts of the pipelines, we copied the config
        file and its snakefile into the .sequana directory. We also copy
        the logo.png file if present into this .sequana directory

        and if present:

        * the cluster_config configuration files for snakemake
        * multiqc_config file for mutliqc reports
        * the schema.yaml file used to check the content of the
          config.yaml file

        if the config.yaml contains a requirements section, the files requested
        are copied in the working directory

        """

        if check_input_files:
            self.check_input_files()

        # the config file
        self.config._update_yaml()
        self.config.save("{}/{}/config.yaml".format(self.workdir, ".sequana"))
        try:
            os.symlink("{}/config.yaml".format(".sequana"),
                       "{}/config.yaml".format(self.workdir))
        except:
            pass

        # the command
        with open("{}/{}.sh".format(self.workdir, self.name), "w") as fout:
            fout.write(self.command)

        # the snakefile
        shutil.copy(self.module.snakefile,
                    "{}/{}".format(self.workdir, ".sequana"))
        try:
            os.symlink("{}/{}.rules".format(".sequana", self.name),
                       "{}/{}.rules".format(self.workdir, self.name))
        except:
            pass

        # the cluster config if any
        if self.module.logo:
            shutil.copy(self.module.logo,
                        "{}/{}".format(self.workdir, ".sequana"))

        # the cluster config if any
        if self.module.cluster_config:
            shutil.copy(self.module.cluster_config, "{}".format(self.workdir))

        # the multiqc if any
        if self.module.multiqc_config:
            shutil.copy(self.module.multiqc_config, "{}".format(self.workdir))

        # the schema if any
        if self.module.schema_config:
            shutil.copy(self.module.schema_config, "{}".format(self.workdir))

            # This is the place where we can check the entire validity of the
            # inputs based on the schema
            if check_schema:
                #logger.info("Checking config file with schema")
                from sequana import SequanaConfig
                cfg = SequanaConfig("{}/config.yaml".format(self.workdir))
                cfg.check_config_with_schema("{}/schema.yaml".format(
                    self.workdir))

        # finally, we copy the files be found in the requirements section of the
        # config file.
        self.copy_requirements()

        # some information
        msg = "Check the script in {}/{}.sh as well as "
        msg += "the configuration file in {}/config.yaml.\n"
        print(
            self.colors.purple(
                msg.format(self.workdir, self.name, self.workdir)))

        msg = "Once ready, execute the script {}.sh using \n\n\t".format(
            self.name)
        if self.options.run_mode == "slurm":
            msg += "cd {}; sbatch {}.sh\n\n".format(self.workdir, self.name)
        else:
            msg += "cd {}; sh {}.sh\n\n".format(self.workdir, self.name)
        print(self.colors.purple(msg))

        # Save an info.txt with the command used
        with open(self.workdir + "/.sequana/info.txt", "w") as fout:
            #
            from sequana import version
            fout.write("# sequana version: {}\n".format(version))
            fout.write("# sequana_{} version: {}\n".format(
                self.name, self._get_package_version()))
            cmd1 = os.path.basename(sys.argv[0])
            fout.write(" ".join([cmd1] + sys.argv[1:]))

        # save environement
        try:
            cmd = "conda list"
            with open("{}/.sequana/env.yml".format(self.workdir), "w") as fout:
                subprocess.call(cmd.split(), stdout=fout)
            logger.debug("Saved your conda environment into env.yml")
        except:
            cmd = "pip freeze"
            with open("{}/.sequana/pip.yml".format(self.workdir), "w") as fout:
                subprocess.call(cmd.split(), stdout=fout)
            logger.debug(
                "Saved your pip environement into pip.txt (conda not found)")

        # General information
        from easydev import CustomConfig
        configuration = CustomConfig("sequana", verbose=False)
        sequana_config_path = configuration.user_config_dir
        completion = sequana_config_path + "/pipelines/{}.sh".format(self.name)
        if os.path.exists(completion):
            with open(completion, "r") as fin:
                line = fin.readline()
                if line.startswith("#version:"):
                    version = line.split("#version:")[1].strip()
                    from distutils.version import StrictVersion
                    if StrictVersion(version) < StrictVersion(
                            self._get_package_version()):
                        msg = (
                            "The version {} of your completion file for the"
                            "  {} pipeline seems older than the installed"
                            " pipeline itself ({}). "
                            "Please, consider updating the completion file {}"
                            " using the following command: \n\t sequana_completion --name {}\n"
                            "available in the sequana_pipetools package (pip "
                            "install sequana_completion)")
                        msg = msg.format(version, self.name,
                                         self._get_package_version(),
                                         completion, self.name)
                        logger.info(msg)

        else:
            # we could print a message to use the sequana_completion tools
            # be maybe boring on the long term
            pass
예제 #9
0
__version__ = "0.1.2"
import pkg_resources
try:
    version = pkg_resources.require(bioconvert)[0].version
except:
    version = __version__

# Creates the data directory if it does not exist
from easydev import CustomConfig
PATH = CustomConfig("bioconvert").user_config_dir

import colorlog


def init_logger():
    handler = colorlog.StreamHandler()
    formatter = colorlog.ColoredFormatter(
        "%(log_color)s%(levelname)-8s : %(module)s :%(reset)s %(message)s",
        datefmt=None,
        reset=True,
        log_colors={
            'DEBUG': 'cyan',
            'INFO': 'green',
            'WARNING': 'yellow',
            'ERROR': 'red',
            'CRITICAL': 'red,bg_white',
        },
        secondary_log_colors={},
        style='%')
    handler.setFormatter(formatter)
    logger = colorlog.getLogger('bioconvert')
예제 #10
0
__version__ = "0.1.2"
import pkg_resources
try:
    version = pkg_resources.require("biokit")[0].version
except:
    version = __version__

# Creates the data directory if it does not exist
from easydev import CustomConfig
biokitPATH = CustomConfig("biokit").user_config_dir

import colorlog as logger
def biokit_debug_level(level="WARNING"):
    """A deubg level setter at top level of the library"""
    assert level in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
    logging_level = getattr(logger.logging.logging, level)
    logger.getLogger().setLevel(logging_level)


from biokit import viz
from biokit.viz import *

from biokit import io


from biokit import stats
from biokit.network import *

from biokit import sequence
from biokit.sequence import *
예제 #11
0
def test_config_custom():
    c = CustomConfig('dummy')
    c.init()
    c.user_config_dir
    c.remove()