Skip to content

Commit 03bc773

Browse files
authored
Merge pull request #11 from aanil/master
Updates for compatibility with multiqc 1.22.3
2 parents 3f9b9a6 + 52931bc commit 03bc773

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

multiqc_ngi/multiqc_ngi.py

+47-37
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
__version__ = version("multiqc_ngi")
2020

21-
from multiqc import report, config
22-
from multiqc.utils import util_functions
21+
from multiqc import report, config, utils
2322

2423
log = logging.getLogger('multiqc')
24+
log.setLevel(logging.DEBUG)
2525

2626
report.ngi = dict()
2727

@@ -64,7 +64,7 @@ class ngi_metadata():
6464

6565
def __init__(self):
6666

67-
log.debug("Running MultiQC_NGI v{} (after modules)".format(__version__))
67+
log.debug(f"Running MultiQC_NGI v{__version__} (after modules)")
6868

6969
# Global try statement to catch any unhandled exceptions and stop MultiQC from crashing
7070
try:
@@ -83,7 +83,7 @@ def __init__(self):
8383
return None
8484

8585
# Run WGS Piper specific cleanup
86-
for f in report.searchfiles:
86+
for f in report.prep_ordered_search_files_list('piper_ngi')[1]:
8787
if 'piper_ngi' in f[1].split(os.sep):
8888
log.info("Looks like WGS data - cleaning up report")
8989
self.ngi_wgs_cleanup()
@@ -93,7 +93,7 @@ def __init__(self):
9393
self.couch = None
9494
self.test_data = None
9595
if 'test_database' in config.kwargs and config.kwargs['test_database'] is not None:
96-
log.info("Using test data instead of connecting to StatusDB: {}".format(config.kwargs['test_database']))
96+
log.info(f"Using test data instead of connecting to StatusDB: {config.kwargs['test_database']}")
9797
with open(config.kwargs['test_database'], 'r') as tdata:
9898
self.test_data = json.loads(tdata.read())
9999
else:
@@ -106,7 +106,7 @@ def __init__(self):
106106
# Get project ID
107107
pids = None
108108
if 'project' in config.kwargs and config.kwargs['project'] is not None:
109-
log.info("Using supplied NGI project id: {}".format(config.kwargs['project']))
109+
log.info(f"Using supplied NGI project id: {config.kwargs['project']}")
110110
pids = config.kwargs['project']
111111
self.s_names = set()
112112
for x in report.general_stats_data:
@@ -116,7 +116,7 @@ def __init__(self):
116116

117117
if len(pids) == 1:
118118
pid = list(pids.keys())[0]
119-
log.info("Found one NGI project id: {}".format(pid))
119+
log.info(f"Found one NGI project id: {pid}")
120120

121121
# Get the metadata for the project
122122
self.get_ngi_project_metadata(pid)
@@ -139,7 +139,7 @@ def __init__(self):
139139
log.info("Not pushing results to StatusDB. To do this, use --push or set config push_statusdb: True")
140140

141141
elif len(pids) > 1:
142-
log.info("Found {} NGI project IDs: {}".format(len(pids), ", ".join(pids)))
142+
log.info(f"Found {len(pids)} NGI project IDs: {', '.join(pids)}")
143143
for pid, s_names in pids.items():
144144
self.get_ngi_samples_metadata(pid, s_names)
145145
self.general_stats_sample_meta()
@@ -148,7 +148,7 @@ def __init__(self):
148148

149149

150150
except Exception as e:
151-
log.error("MultiQC_NGI v{} crashed! Skipping...".format(__version__))
151+
log.error(f"MultiQC_NGI v{__version__} crashed! Skipping...")
152152
log.exception(e)
153153
log.error("Continuing with base MultiQC execution.")
154154

@@ -228,20 +228,20 @@ def get_ngi_project_metadata(self, pid):
228228
try:
229229
p_summary = p_summary['value']
230230
except TypeError:
231-
log.error("statusdb returned no rows when querying {}".format(pid))
231+
log.error(f"statusdb returned no rows when querying {pid}")
232232
return None
233-
log.debug("Found metadata for NGI project '{}'".format(p_summary['project_name']))
233+
log.debug(f"Found metadata for NGI project '{p_summary['project_name']}'")
234234

235-
config.title = '{}: {}'.format(pid, p_summary['project_name'])
235+
config.title = f"{pid}: {p_summary['project_name']}"
236236
config.project_name = p_summary['project_name']
237237
if config.analysis_dir and ('qc_ngi' in str(config.analysis_dir[0]) or 'qc_ngi' in os.listdir()):
238238
infix = 'qc'
239239
else:
240240
infix = 'pipeline'
241241
config.output_fn_name = f'{p_summary["project_name"]}_{infix}_{config.output_fn_name}'
242-
config.data_dir_name = '{}_{}'.format(p_summary['project_name'], config.data_dir_name)
243-
log.debug("Renaming report filename to '{}'".format(config.output_fn_name))
244-
log.debug("Renaming data directory to '{}'".format(config.data_dir_name))
242+
config.data_dir_name = f'{p_summary['project_name']}_{config.data_dir_name}'
243+
log.debug(f"Renaming report filename to '{config.output_fn_name}'")
244+
log.debug(f"Renaming data directory to '{config.data_dir_name}'")
245245

246246
report.ngi['pid'] = pid
247247
report.ngi['project_name'] = p_summary['project_name']
@@ -263,13 +263,13 @@ def get_ngi_project_metadata(self, pid):
263263
report.ngi[i] = p_summary[j]
264264
report.ngi['ngi_header'] = True
265265
except KeyError:
266-
log.warn("Couldn't find '{}' in project summary".format(j))
266+
log.warn(f"Couldn't find '{j}' in project summary")
267267
for i, j in d_keys.items():
268268
try:
269269
report.ngi[i] = p_summary['details'][j]
270270
report.ngi['ngi_header'] = True
271271
except KeyError:
272-
log.warn("Couldn't find '{}' in project details".format(j))
272+
log.warn(f"Couldn't find '{j}' in project details")
273273

274274

275275
def get_ngi_samples_metadata(self, pid, s_names=None):
@@ -280,7 +280,7 @@ def get_ngi_samples_metadata(self, pid, s_names=None):
280280
p_view = self.couch['projects'].view('project/samples')
281281
p_samples = p_view[pid]
282282
if not len(p_samples.rows) == 1:
283-
log.error("statusdb returned {} rows when querying {}".format(len(p_samples.rows), pid))
283+
log.error(f"statusdb returned {len(p_samples.rows)} rows when querying {pid}")
284284
else:
285285
if 'sample_meta' not in report.ngi:
286286
report.ngi['sample_meta'] = dict()
@@ -310,7 +310,7 @@ def fastqscreen_genome(self):
310310
}
311311
if genome in nice_names.keys():
312312
genome = nice_names[genome]
313-
m.intro += '<p style="margin-top:20px;" class="text-info"> <span class="glyphicon glyphicon-piggy-bank"></span> The reference genome in Genomic status is {}</p>'.format(genome)
313+
m.intro += f'<p style="margin-top:20px;" class="text-info"> <span class="glyphicon glyphicon-piggy-bank"></span> The reference genome in Genomic status is {genome}</p>'
314314

315315

316316
def general_stats_sample_meta(self):
@@ -319,7 +319,7 @@ def general_stats_sample_meta(self):
319319
meta = report.ngi.get('sample_meta')
320320
if meta is not None and len(meta) > 0:
321321

322-
log.info('Found {} samples in StatusDB'.format(len(meta)))
322+
log.info(f'Found {len(meta)} samples in StatusDB')
323323

324324
# Write to file
325325
report.write_data_file(meta, 'ngi_meta')
@@ -343,7 +343,7 @@ def general_stats_sample_meta(self):
343343

344344
# Skip this sample if we don't have any matching data
345345
if s_name is None:
346-
log.debug("Skipping StatusDB metadata for sample {} as no bioinfo report logs found.".format(sid))
346+
log.debug(f"Skipping StatusDB metadata for sample {sid} as no bioinfo report logs found.")
347347
continue
348348

349349
# Make a dict to hold new data for General Stats
@@ -370,7 +370,7 @@ def general_stats_sample_meta(self):
370370
seq_lp = lp
371371
else:
372372
seq_lp = None
373-
log.warn('Found multiple sequenced lib preps for {} - skipping metadata'.format(sid))
373+
log.warn(f'Found multiple sequenced lib preps for {sid} - skipping metadata')
374374
break
375375
except KeyError:
376376
pass
@@ -387,17 +387,17 @@ def general_stats_sample_meta(self):
387387
except KeyError:
388388
pass
389389

390-
log.info("Matched meta for {} samples from StatusDB with report sample names".format(len(s_names)))
390+
log.info(f"Matched meta for {len(s_names)} samples from StatusDB with report sample names")
391391
if len(s_names) == 0:
392392
return None
393393

394394
# Deal with having more than one initial QC concentration unit
395395
formats_set = set(formats.values())
396396
if len(formats_set) > 1:
397-
log.warning("Mixture of library_validation concentration units! Found: {}".format(", ".join(formats_set)))
397+
log.warning(f"Mixture of library_validation concentration units! Found: {', '.join(formats_set)}")
398398
for s_name in gsdata:
399399
try:
400-
gsdata[s_name]['lp_concentration'] = '{} {}'.format(gsdata[s_name]['lp_concentration'], formats[s_name])
400+
gsdata[s_name]['lp_concentration'] = f'{gsdata[s_name]['lp_concentration']} {formats[s_name]}'
401401
except KeyError:
402402
pass
403403
elif len(formats_set) == 1:
@@ -443,11 +443,11 @@ def general_stats_sample_meta(self):
443443
}
444444
gsheaders['lp_concentration'] = {
445445
'namespace': 'NGI',
446-
'title': 'Lib Conc. ({})'.format(conc_units),
447-
'description': 'Library Prep: Concentration ({})'.format(conc_units),
446+
'title': f'Lib Conc. ({conc_units})',
447+
'description': f'Library Prep: Concentration ({conc_units})',
448448
'min': 0,
449449
'scale': 'YlGn',
450-
'format': '{:.,0f}',
450+
'format': '{:,.0f}',
451451
'hidden': conc_hidden
452452
}
453453
gsheaders['amount_taken'] = {
@@ -456,7 +456,7 @@ def general_stats_sample_meta(self):
456456
'description': 'Library Prep: Amount Taken (ng)',
457457
'min': 0,
458458
'scale': 'YlGn',
459-
'format': '{:.,0f}',
459+
'format': '{:,.0f}',
460460
'hidden': amounts_hidden
461461
}
462462
report.general_stats_data.append(gsdata)
@@ -524,7 +524,17 @@ def push_statusdb_multiqc_data(self):
524524
doc['samples'][sid][key] = d[s_name]
525525

526526
# Save object to the database
527-
db.save(doc)
527+
try:
528+
db.save(doc)
529+
except ValueError as e:
530+
if e.args[0] == 'Out of range float values are not JSON compliant':
531+
log.debug('Error saving to StatusDB: Out of range float values are not JSON compliant, might be NaNs, trying again...')
532+
doc = json.loads(utils.util_functions.dump_json(doc, filehandle=None))
533+
db.save(doc)
534+
log.debug('Saved to StatusDB after converting NaNs to nulls')
535+
else:
536+
log.error(f'Error saving to StatusDB: {e}')
537+
528538

529539

530540
def connect_statusdb(self):
@@ -535,11 +545,11 @@ def connect_statusdb(self):
535545
sdb_config = yaml.safe_load(f)
536546
log.debug("Got MultiQC_NGI statusdb config from the home directory.")
537547
except IOError:
538-
log.debug("Could not open the MultiQC_NGI statusdb config file {}".format(conf_file))
548+
log.debug("Could not open the MultiQC_NGI statusdb config file {conf_file}")
539549
try:
540550
with open(os.environ['STATUS_DB_CONFIG'], "r") as f:
541551
sdb_config = yaml.safe_load(f)
542-
log.debug("Got MultiQC_NGI statusdb config from $STATUS_DB_CONFIG: {}".format(os.environ['STATUS_DB_CONFIG']))
552+
log.debug(f"Got MultiQC_NGI statusdb config from $STATUS_DB_CONFIG: {os.environ['STATUS_DB_CONFIG']}")
543553
except (KeyError, IOError):
544554
log.debug("Could not get the MultiQC_NGI statusdb config file from env STATUS_DB_CONFIG")
545555
log.warn("Could not find a statusdb config file")
@@ -549,10 +559,10 @@ def connect_statusdb(self):
549559
password = sdb_config['statusdb']['password']
550560
couch_url = sdb_config['statusdb']['url']
551561
except KeyError:
552-
log.error("Error parsing the config file {}".format(conf_file))
562+
log.error(f"Error parsing the config file {conf_file}")
553563
return None
554564

555-
server_url = "https://{}:{}@{}".format(couch_user, password, couch_url)
565+
server_url = f"https://{couch_user}:{password}@{couch_url}"
556566

557567
# First, test that we can see the server.
558568
try:
@@ -569,7 +579,7 @@ def connect_statusdb(self):
569579
class ngi_after_execution_finish():
570580

571581
def __init__(self):
572-
log.debug("Running MultiQC_NGI v{} (after execution finish)".format(__version__))
582+
log.debug(f"Running MultiQC_NGI v{__version__} (after execution finish)")
573583

574584
if config.kwargs.get('disable_ngi', False) is True:
575585
log.debug("Skipping MultiQC_NGI (after execution finish) as 'disable_ngi' was specified")
@@ -586,14 +596,14 @@ def __init__(self):
586596
if getattr(config, 'remote_port', None) is not None:
587597
scp_command.extend(['-P', str(config.remote_port)])
588598
scp_command.extend([config.output_fn, config.remote_destination])
589-
log.debug('Transferring report with command: {}'.format(' '.join(scp_command)))
599+
log.debug(f"Transferring report with command: {' '.join(scp_command)}")
590600
DEVNULL = open(os.devnull, 'wb')
591601
p = subprocess.Popen(scp_command, stdout=DEVNULL)
592602
pid, exit_status = os.waitpid(p.pid, 0)
593603
if exit_status != 0:
594604
log.error("Not able to copy report to remote server: Subprocess command failed.")
595605

596606
except Exception as e:
597-
log.error("MultiQC_NGI v{} crashed! Skipping...".format(__version__))
607+
log.error(f"MultiQC_NGI v{__version__} crashed! Skipping...")
598608
log.exception(e)
599609
log.error("Continuing with base MultiQC execution.")

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from setuptools import setup, find_packages
1212

13-
version = '0.6.3'
13+
version = '0.8.0'
1414

1515
setup(
1616
name = 'multiqc_ngi',

0 commit comments

Comments
 (0)