Exemplo n.º 1
0
def fill_and_write_instance_config(assnake_db, fna_db_dir, bwa_index_dir,
                                   conda_dir, drmaa_log_dir,
                                   instance_config_location):
    '''
    Accepts all the necessary config props and dumps them to the provided location as file

    :return: location of instance config file if everything is ok, None otherwise
    '''
    dir_of_this_file = os.path.dirname(os.path.abspath(__file__))

    assnake_install_dir = (dir_of_this_file.replace('assnake/commands',
                                                    'snake'))

    config_template_loc = os.path.join(dir_of_this_file,
                                       '../snake/config_template.yml')
    config_template = read_yaml(config_template_loc)

    config_template['assnake_db'] = assnake_db
    config_template['assnake_install_dir'] = assnake_install_dir
    config_template['fna_db_dir'] = fna_db_dir
    config_template['bwa_index_dir'] = bwa_index_dir
    config_template['conda_dir'] = conda_dir
    config_template['drmaa_log_dir'] = drmaa_log_dir

    os.makedirs(fna_db_dir, exist_ok=True)
    os.makedirs(bwa_index_dir, exist_ok=True)
    os.makedirs(conda_dir, exist_ok=True)
    os.makedirs(drmaa_log_dir, exist_ok=True)

    with open(instance_config_location, 'w+') as file:
        _ = yaml.dump(config_template, file, sort_keys=False)

    return instance_config_location
Exemplo n.º 2
0
def read_assnake_instance_config():
    '''
    Reads particular assnake instance config. It is stored inside assnake database as config.yaml (Name subject to change). 
    :return: Returns dict if instance config exists, None otherwise.
    '''
    # TODO optimize number of times this is called
    # print('reading instance config')

    internal_config = read_internal_config()
    instance_config_loc = internal_config['instance_config_loc']

    if os.path.isfile(instance_config_loc):
        return read_yaml(instance_config_loc)
    else:
        return None
Exemplo n.º 3
0
def read_internal_config():
    '''
    Reads the config at ~/.config/assnake/internal_config.yaml and returns as dict
    '''
    internal_config_loc = os.path.join(str(Path.home()),
                                       '.config/assnake/internal_config.yaml')

    if os.path.isfile(internal_config_loc):
        internal_config = read_yaml(internal_config_loc)
        return internal_config
    else:
        internal_config_dir = os.path.join(str(Path.home()),
                                           '.config/assnake/')

        os.makedirs(internal_config_dir, exist_ok=True)

        if not os.path.isfile(internal_config_loc):
            with open(internal_config_loc, 'w+') as file:
                _ = yaml.dump({'instance_config_loc': 'not_set'},
                              file,
                              sort_keys=False)
        return {'instance_config_loc': ''}
Exemplo n.º 4
0
def cli(ctx):
    """\b
   ___    ____   ____   _  __   ___    __ __   ____
  / _ |  / __/  / __/  / |/ /  / _ |  / //_/  / __/
 / __ | _\ \   _\ \   /    /  / __ | / ,<    / _/  
/_/ |_|/___/  /___/  /_/|_/  /_/ |_|/_/|_|  /___/


\b  
O---o Welcome to the Assnake, Traveller!
 O-o  If you found yorself here, 
  O   than you are exploring the land of the MICROBIOME.
 o-O  Here you can find weapons and spells
o---O that will help you to analyse your data.
O---o The tools that are presented here 
 O-o  are for metagenomics studies on ILLUMINA data.
  O   You can check quality and preprocess your data, 
 o-O  assemble it, map, bin the contigs, 
o---O make taxonomic annotations, functional annotations,
O---o and work with 16s rRNA data.
"""

    dir_of_this_file = os.path.dirname(os.path.abspath(__file__))

    instance_config = read_assnake_instance_config()

    if instance_config is not None:
        wc_config = read_yaml(
            os.path.join(dir_of_this_file, '../snake/wc_config.yaml'))
        ctx.obj = {
            'config': instance_config,
            'wc_config': wc_config,
            'requested_dfs': [],
            'requests': [],
            'sample_sets': [],
            'requested_results': []
        }
Exemplo n.º 5
0
    def from_location(cls,
                      name,
                      result_type,
                      location,
                      input_type,
                      additional_inputs=[],
                      description='',
                      with_presets=False,
                      static_files_dir_name='static',
                      invocation_command=None,
                      preset_preparation=None,
                      preset_file_format='json'):
        '''
        This method is a wrapper for creating an instance of Result class by grabbing the snakefiles and wc_config automatically 
        from user-provided `location`. How can we make grabbing the location automatic? 

        :param name:       Name of the Result, will also appear as a command name.
        :param location:   Absolute location where files are stored. We need it in order to grab .smk and wc_config and all other static files.
        :param input_type: Type of primary input for this result. Currently we use illumina_sample, illumina_sample_set, illumina_strand_file, illumina_strand_file_set 

        :param additional_inputs:  Any additional inputs for the Result. Usually it would be Database, Reference and their mixes.
        :param invocation_command: Users can pass custom invocation commands that will be used in CLI instead of auto-generated ones. Useful for custom logic in CLI.
        :param preset_preparation: Functions that tells the Result how to save it's presets to database. 
        :param preset

        :param description: Description of the Result, will also appear as a short help in CLI.
        '''
        # Find all smk files for Result. This is snakemake workflows.
        workflows = glob.glob(os.path.join(location, 'workflow*.smk'))
        # Find all wc_config files.
        wc_config = os.path.join(location, 'wc_config.yaml')
        # Find default config files
        default_config = os.path.join(location, 'default_config.yaml')

        if len(workflows) == 0:  # No workflow files found
            print('===', name)
            print('No workflow files found')

        # Check for config file with wildcards and load.
        if os.path.isfile(wc_config):
            wc_config = read_yaml(wc_config)
            result_wc = wc_config[name + '_wc']
        else:
            # print('No wc config file found for result', name)
            wc_config = {}
            result_wc = ''

        if os.path.isfile(default_config):
            default_config = read_yaml(default_config)
        else:
            # print('No default_config file found for result', name)
            default_config = None

        if with_presets:
            preset_manager = PresetManager(
                dir_in_database=os.path.join('presets', name),
                included_presets_dir=os.path.join(location, 'presets'),
                static_files_dir_name=static_files_dir_name,
                preset_file_format=preset_file_format)
        else:
            preset_manager = None

        x = cls(
            name=name,
            workflows=workflows,
            result_type=result_type,
            result_wc=result_wc,
            input_type=input_type,
            additional_inputs=additional_inputs,
            invocation_command=invocation_command,
            preset_preparation=preset_preparation,
            wc_config=wc_config,
            preset_manager=preset_manager,
            description=description,
        )

        return x
Exemplo n.º 6
0
def load_wc_config():
    dir_of_this_file = os.path.dirname(os.path.abspath(__file__))
    return (read_yaml(os.path.join(dir_of_this_file,
                                   '../snake/wc_config.yaml')))
Exemplo n.º 7
0
 def read_deployed_config(self):
     if self.assnake_config is not None:
         def_loc = os.path.join(self.assnake_config['assnake_db'], 'module_configs', self.name + '.yaml')
         if os.path.isfile(def_loc):
             return read_yaml(def_loc)
     return None