From f74b56ca209ec20736ca69cf70363ebc8dc0b8dc Mon Sep 17 00:00:00 2001 From: Andrew Page Date: Thu, 7 May 2020 14:50:32 +0100 Subject: [PATCH] extended species database details --- VERSION | 2 +- scripts/socru_species | 7 ++++++- socru/Schemas.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 5859406..530cdd9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.3 +2.2.4 diff --git a/scripts/socru_species b/scripts/socru_species index d08a90d..29bb555 100755 --- a/scripts/socru_species +++ b/scripts/socru_species @@ -17,10 +17,15 @@ parser = argparse.ArgumentParser( description = 'List all available species', usage = 'socru_species [options]', formatter_class=argparse.ArgumentDefaultsHelpFormatter) + +parser.add_argument('--extended', '-e', action='store_true', help='Extended information about the species databases', default = False) parser.add_argument('--debug', action='store_true', help='Turn on debugging', default = False) parser.add_argument('--verbose', '-v', action='store_true', help='Turn on verbose output', default = False) parser.add_argument('--version', action='version', version=str(version)) options = parser.parse_args() -Schemas(options.verbose).print_all() +if options.extended: + Schemas(options.verbose).print_extended() +else: + Schemas(options.verbose).print_all() diff --git a/socru/Schemas.py b/socru/Schemas.py index bac42e6..286b476 100644 --- a/socru/Schemas.py +++ b/socru/Schemas.py @@ -2,6 +2,7 @@ from os import listdir from os.path import isdir import pkg_resources +import yaml class Schemas: def __init__(self, verbose): @@ -14,6 +15,47 @@ def all_available(self): def print_all(self): for d in sorted(self.all_available()): print(d) + + def extended(self): + db_info = {} + for species in listdir(self.base_directory): + + db_dir = os.path.join(self.base_directory, species) + db_file = os.path.join(self.base_directory, species,'profile.txt.yml') + + if not os.path.exists(db_file): + continue + + with open(db_file, 'r') as metadatafh: + try: + metadata = yaml.load(metadatafh, yaml.SafeLoader) + dnaA_fragment_number = 0 + dnaa_forward_orientation = False + dif_fragment_number = 0 + reference_genome = '' + + if 'dnaa_fragment' in metadata: + dnaA_fragment_number = int(metadata['dnaa_fragment']) + dnaa_forward_orientation = metadata['dnaa_forward_orientation'] + + if 'dif_fragment' in metadata: + dif_fragment_number = int(metadata['dif_fragment']) + + if 'reference_genome' in metadata: + reference_genome = str(metadata['reference_genome']) + + db_info[species] = [species, dnaA_fragment_number, dnaa_forward_orientation, dif_fragment_number, reference_genome] + + + except yaml.YAMLError as exc: + print(exc) + return db_info + + def print_extended(self): + extended_details = self.extended() + print("\t".join(['Species','dnaA fragment No.', 'dnaA forward orientation', 'dif fragment No.', 'Reference'])) + for species in sorted(extended_details): + print("\t".join( [ str(a) for a in extended_details[species] ])) def database_directory(self, db_dir, species):