Skip to content
Snippets Groups Projects
Commit 349eb1e7 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Added config module and used it in the module scripts

parent 8a98d304
No related branches found
No related tags found
No related merge requests found
import os
import yaml
def get_install_location():
"""Finds the location directory of the tool"""
script_path = os.path.realpath(__file__)
script_dir = os.path.dirname(script_path)
install_dir = os.path.dirname(script_dir)
return install_dir
def get_script_location():
return os.path.join(get_install_location(),'bin')
def get_template_location():
return os.path.join(get_install_location(),'templates')
def get_modules_location():
return os.path.join(get_install_location(),'modules')
def get_profiles_location():
return os.path.join(get_install_location(),'profiles')
def get_config_file():
return os.path.join(get_install_location(), 'config.yaml')
def load_config_file():
config = {}
with (open(get_config_file())) as f:
config = yaml.load(f)
return config
def get_module_manifests():
mypath = get_modules_location()
return [os.path.join(mypath, f) for f in os.listdir(mypath) if os.path.isfile(os.path.join(mypath, f))]
def load_modules():
modules = []
for manifest in get_module_manifests():
with (open(manifest)) as f:
modules.append(yaml.load(f))
return modules
def load_config():
config = load_config_file()
config['modules'] = load_modules()
return config
if __name__ == "__main__":
"""prints the configuration"""
import config
from pprint import pformat
print('Install location: ' + config.get_install_location())
print('Script lcoation: ' + config.get_script_location())
print('Config location: ' + config.get_config_file())
print('Available module manifests:\n\t' + '\n\t'.join(config.get_module_manifests()) + '\n')
print('Config content:\n' + pformat(config.load_config_file()) + '\n')
print('Manifest content:\n' + pformat(config.load_modules()) + '\n')
print('Aggregated config:\n' + pformat(config.load_config()) + '\n')
#!/usr/bin/env python3
import argparse
import yaml
import os
import config
from os import system
def get_config_file():
"""Finds the config file, that is located in the directory above script"""
script_path = os.path.realpath(__file__)
script_dir = os.path.dirname(script_path)
config_dir = os.path.dirname(script_dir)
config_file = os.path.join(config_dir, 'config.yaml')
return config_file
def get_blastp_tool():
"""Extracts the configuration entry for blastp. If it is not present, it defaults to blastp"""
tool = None
with open(get_config_file()) as f:
config = yaml.load(f)
tool = config['tools'].get('blastp', 'blastp')
return tool
blastp_tool = config.load_config()['tools'].get('blastp', 'blastp')
parser = argparse.ArgumentParser(description='Identify homologues in the swissprot database')
parser.add_argument('--info', '-i', action='store_true')
parser.add_argument('--fasta', '-f', required=True, help='A fasta file with aminoacid sequences')
parser.add_argument('--evalue', '-e', default='0.0001', help='Evalue cutoff')
parser.add_argument('--alignment', '-a', action='store_true', help='Include alignments in btop format')
args = parser.parse_args()
if args.info:
print("blast against swissprot\n")
exit(0)
format = '7 qseqid sseqid pident qstart qend sstart send evalue bitscore'
if args.alignment:
format += ' btop'
system(get_blastp_tool() + " -db /vol/biodb/uniprot/uniprot_sprot.fasta -num_threads 7 -outfmt '" + format + "' -out - -query " + args.fasta)
system(blastp_tool + " -db /vol/biodb/uniprot/uniprot_sprot.fasta -num_threads 7 -outfmt '" + format + "' -out - -query " + args.fasta)
#!/usr/bin/env python3
import argparse
import yaml
import os
import config
from os import system
def get_config_file():
"""Finds the config file, that is located in the directory above script"""
script_path = os.path.realpath(__file__)
script_dir = os.path.dirname(script_path)
config_dir = os.path.dirname(script_dir)
config_file = os.path.join(config_dir, 'config.yaml')
return config_file
def get_signalp_tool():
"""Extracts the configuration entry for signalp. If it is not present, it defaults to signalp"""
tool = None
with open(get_config_file()) as f:
config = yaml.load(f)
tool = config['tools'].get('signalp', 'signalp')
return tool
signalp_tool = config.load_config()['tools'].get('signalp', 'signalp')
parser = argparse.ArgumentParser(description='Find signal peptides in amino acid sequences')
parser.add_argument('--fasta', '-f', required=True, help='A fasta file with aminoacid sequences')
parser.add_argument('--organism', '-o', choices=['euk', 'gram+', 'gram-'], default='euk', help='The organism type')
args = parser.parse_args()
system(get_signalp_tool() + " -t " + args.organism + " " + args.fasta)
system(signalp_tool + " -t " + args.organism + " " + args.fasta)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment