Ejemplo n.º 1
0
# -*- coding: utf-8 -*-
#
################################################################################
from configparser import ConfigParser, ExtendedInterpolation
import re
import myutils

parser = ConfigParser(interpolation=ExtendedInterpolation(),
                      strict=True,
                      allow_no_value=False)
parser.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]")

with open('config1.cfg', encoding='utf-8') as f:
    parser.read_file(f)
    myutils.showconfig1(parser)
Ejemplo n.º 2
0
# -*- coding: utf-8 -*-
#
################################################################################
from configparser import ConfigParser, ExtendedInterpolation
import re
import myutils

parser = ConfigParser(interpolation=ExtendedInterpolation(), strict=True)
parser.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]")

with open('config1.cfg', encoding='utf-8') as f:
    parser.read_file(f)
    myutils.showconfig1(parser)
Ejemplo n.º 3
0
                     basename,
                     splitext,
                     dirname,
                     expanduser)
from glob import glob
import sys
from types import ModuleType


# print('__name__ is {}'.format(__name__))
# print('__file__ is {}'.format(abspath(__file__)))
# print('os.path.dirname is {}'.format(dirname(abspath(__file__))))
print('home folder is {}'.format(expanduser('~')))

pconfig = ConfigParser(interpolation=ExtendedInterpolation())
pconfig.SECTCRE = re.compile(r"\[ *(?P<header>[^]]+?) *\]")
pconfig.read('config1.cfg', encoding='utf-8')

############################
# pretty output
#
# column widths
columns = (20, 20, 50)

header_line = '|'.join(['{:^%s}' % i for i in columns])
data_line = '|'.join(['{:<%s}' % i for i in columns])

header = header_line.format('Section', 'Option', 'Value')
print('-' * len(header))
print(header)
print('-' * len(header))
Ejemplo n.º 4
0
def ss_file_parse(file_path):

    cfg = ConfigParser(delimiters=('='),
                       allow_no_value=True,
                       empty_lines_in_values=True)
    cfg.optionxform = str
    cfg.SECTCRE = re.compile(r'\[\s*(?P<header>[^]]+?)\s*\]')

    try:
        cfg.read(file_path)
    except MissingSectionHeaderError:
        Log.err(
            'Missing section header(s) in the provided "Search Strategies" file:',
            file_path)
        exit(1)

    required_options = set(('organelle', 'min_query_length',
                            'max_query_length', 'max_query_identity',
                            'min_target_orf_length', 'max_target_orf_length'))

    ret_dict = OrderedDict()

    sections = cfg.sections()

    for s in sections:

        o = cfg.options(s)

        if not required_options <= set(o):
            missing = required_options - (required_options & set(o))
            Log.err(
                'Missing required option(s):' + ', '.join(missing) +
                'for search strategy', s)
            exit(1)

        organelle = cfg[s]['organelle']

        if organelle not in ('nucleus', 'plastid', 'mitochondrion'):
            Log.err('Organelle "' + organelle + '" should be one of:',
                    'nucleus, plastid, or mitochondrion.')
            exit(1)

        min_query_length = int(cfg[s]['min_query_length'])
        max_query_length = int(cfg[s]['max_query_length'])
        max_query_identity = float(cfg[s]['max_query_identity'])
        min_target_orf_length = int(cfg[s]['min_target_orf_length'])
        max_target_orf_length = int(cfg[s]['max_target_orf_length'])

        evalue = None
        max_hsps = None
        qcov_hsp_perc = None
        best_hit_overhang = None
        best_hit_score_edge = None
        max_target_seqs = None

        pfam_families = None
        ncbi_accessions_aa = None
        entrez_search_queries = None
        fasta_files_aa = None

        if cfg.has_option(s, 'evalue'):
            evalue = float(cfg[s]['evalue'])

        if cfg.has_option(s, 'max_hsps'):
            max_hsps = int(cfg[s]['max_hsps'])

        if cfg.has_option(s, 'qcov_hsp_perc'):
            qcov_hsp_perc = float(cfg[s]['qcov_hsp_perc'])

        if cfg.has_option(s, 'best_hit_overhang'):
            best_hit_overhang = float(cfg[s]['best_hit_overhang'])

        if cfg.has_option(s, 'best_hit_score_edge'):
            best_hit_score_edge = float(cfg[s]['best_hit_score_edge'])

        if cfg.has_option(s, 'max_target_seqs'):
            max_target_seqs = int(cfg[s]['max_target_seqs'])

        if cfg.has_option(s, 'pfam_families'):
            pfam_families = str(cfg[s]['pfam_families'])
            pfam_families = set(pfam_families.split('\n')) - \
                set(('', 'None'))
            pfam_families = _parse_pfam(pfam_entries=pfam_families,
                                        config_file_path=file_path)
            pfam_families = sorted(pfam_families)

        if cfg.has_option(s, 'ncbi_accessions_aa'):
            ncbi_accessions_aa = str(cfg[s]['ncbi_accessions_aa'])
            ncbi_accessions_aa = sorted(
                set(ncbi_accessions_aa.split('\n')) - set(('', 'None')))

        if cfg.has_option(s, 'entrez_search_queries'):
            entrez_search_queries = str(cfg[s]['entrez_search_queries'])
            entrez_search_queries = sorted(
                set(entrez_search_queries.split('\n')) - set(('', 'None')))

        if cfg.has_option(s, 'fasta_files_aa'):
            fasta_files_aa = str(cfg[s]['fasta_files_aa'])
            fasta_files_aa = set(fasta_files_aa.split('\n')) - \
                set(('', 'None'))
            fasta_files_aa = [abspath(expanduser(x)) for x in fasta_files_aa]
            fasta_files_aa = sorted(fasta_files_aa)

        section_dict = OrderedDict({
            'organelle': organelle,
            'min_query_length': min_query_length,
            'max_query_length': max_query_length,
            'max_query_identity': max_query_identity,
            'min_target_orf_length': min_target_orf_length,
            'max_target_orf_length': max_target_orf_length,
            'blast_2_evalue': evalue,
            'blast_2_max_hsps': max_hsps,
            'blast_2_qcov_hsp_perc': qcov_hsp_perc,
            'blast_2_best_hit_overhang': best_hit_overhang,
            'blast_2_best_hit_score_edge': best_hit_score_edge,
            'blast_2_max_target_seqs': max_target_seqs,
            'pfam_families': pfam_families,
            'ncbi_accessions_aa': ncbi_accessions_aa,
            'entrez_search_queries': entrez_search_queries,
            'fasta_files_aa': fasta_files_aa
        })

        ret_dict[s] = section_dict

    return ret_dict