Skip to content

Commit

Permalink
Merge pull request #24 from andrewjpage/master
Browse files Browse the repository at this point in the history
extended species database details
  • Loading branch information
andrewjpage authored May 7, 2020
2 parents 25343cc + f74b56c commit cf9c649
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.2.3
2.2.4
7 changes: 6 additions & 1 deletion scripts/socru_species
Original file line number Diff line number Diff line change
Expand Up @@ -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()
42 changes: 42 additions & 0 deletions socru/Schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from os import listdir
from os.path import isdir
import pkg_resources
import yaml

class Schemas:
def __init__(self, verbose):
Expand All @@ -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):
Expand Down

0 comments on commit cf9c649

Please sign in to comment.