Skip to content

Commit

Permalink
More error resilience in the face of junk from SMRTLonk
Browse files Browse the repository at this point in the history
  • Loading branch information
tbooth committed Dec 4, 2024
1 parent 2f0c088 commit 3cea7b3
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions smrtlink_get_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,17 @@ def exit(msg):
sample_record['details'][k] = int(sample_record['details'][k])

if info_yaml is not None and 'reports' in info_yaml:
cross_check_info(info_yaml['reports'], sample_record['details'])
try:
cross_check_info(info_yaml['reports'], sample_record['details'])
except RuntimeError as e:
exit(str(e))

# Shall we dump this as YAML or JSON? Other things are YAML, so stick with that.
dump_yaml(sample_record, fh=sys.stdout)

def cross_check_info(reports_dict, deets_dict):
"""Sanity check that the info we have already does match the sample.
"""Sanity check that the info we have already (in reports_dict) does match
the sample details we just fetched (deets_dict).
"""
# Check the insert size we got from metadata.xml (in sl_dict) versus the one we
# see in sample-setup.yaml (sample_dict)
Expand All @@ -125,9 +129,18 @@ def cross_check_info(reports_dict, deets_dict):
raise RuntimeError("Value mismatch in On-Plate Loading Conc")

# And the Application
run_dict = reports_dict['Run']
if run_dict['Library type'] != deets_dict['Application']:
raise RuntimeError("Value mismatch in Application")
app1 = reports_dict['Run']['Library type']
app2 = deets_dict['Application']
if app1 != app2:

# Seems we may have some leeway here. I'm not sure if it makes sense
# to add some specific exceptions but let's see.
if any( [ (app1 == x and app2.startswith(x)) or
(app2 == x and app1.startswith(x))
for x in ["other"] ] ):
L.info(f"Accepting mismatch in Application: {app1} != {app2}")
else:
raise RuntimeError(f"Value mismatch in Application: {app1} != {app2}")

def scrape_sample_details_table(html_text):

Expand Down Expand Up @@ -189,13 +202,13 @@ def parse_args(*args):

if not(parsed_args.info_yaml) and parsed_args.options:
# Because we need to get the cell id to find the right section in the options file
exit("Setting an options file only works with the .info.yaml argument")
sys.exit("Setting an options file only works with the .info.yaml argument")

if not(parsed_args.info_yaml or parsed_args.ws_name):
argparser.print_help()
exit(2)
sys.exit(2)
if parsed_args.info_yaml and parsed_args.ws_name:
exit("Please give either --ws_name or specify a .info.yaml file but not both")
sys.exit("Please give either --ws_name or specify a .info.yaml file but not both")

return parsed_args

Expand Down

0 comments on commit 3cea7b3

Please sign in to comment.