def action(args): controls, sample_groups = get_input(args.infile, split_description=args.split_desc) qadata = qa_from_csv(qafile) matrix = read_matrix(matrix_file) style = "screen" if args.outfile == sys.stdout else "file" outfile = get_outfile(args, label="qa", ext="csv") if args.calculate_ion_ratios: qadata = add_ion_ratios(qadata, controls) # if a single compound is specified, define lambda cond to use as # a filter if args.compound_id: cond = lambda c: c["COMPOUND_id"] == args.compound_id else: cond = lambda c: True # controls compounds = [Compound(c, matrix, **qadata[c["COMPOUND_id"]]) for c in flatten(controls.values()) if cond(c)] display_controls(compounds, outfile=outfile, show_all=args.show_all, message=not args.outcomes_only, style=style) compounds = [Compound(c, matrix, **qadata[c["COMPOUND_id"]]) for c in flatten(sample_groups.values()) if cond(c)] display_specimens(compounds, outfile=outfile, show_all=args.show_all, message=not args.outcomes_only, style=style) if args.outfile is None: outfile.close()
def test05(self): args = Args(infile = self.infile, outfile = None, outdir = None) outfile = get_outfile(args) log.debug(outfile)
def test06(self): args = Args(infile = self.infile, outfile = None, outdir = None) outfile = get_outfile(args, include_version = False) log.debug(outfile)
def test03(self): args = Args(infile = self.infile, outfile = open(path.join(self.outdir, 'outfile.csv'), 'w'), outdir = None) outfile = get_outfile(args, label = 'qa') log.debug(outfile)
def test01(self): args = Args(infile = self.infile, outfile = None, outdir = None) outfile = get_outfile(args, label = 'qa') log.debug(outfile)
def test04(self): outdir = mkdir(path.join(self.outdir, 'subdir'), clobber = True) args = Args(infile = self.infile, outfile = None, outdir = outdir) outfile = get_outfile(args, label = 'qa') log.debug(outfile)
def action(args): fmt = 'json' samples = get_input(args.infile) if args.sanitize: samples = remove_patient_info(samples) outfile = get_outfile(args, ext=fmt) json.dump(samples, outfile, indent=4)
def action(args): controls, sample_groups = get_input(args.infile, split_description = args.split_desc) qadata = qa_from_csv(qafile) matrix = read_matrix(matrix_file) style = 'screen' if args.outfile == sys.stdout else 'file' outfile = get_outfile(args, label = 'results', ext = 'csv') if args.calculate_ion_ratios: qadata = add_ion_ratios(qadata, controls) samples = get_samples(controls, sample_groups, qadata, matrix) display_results(samples, outfile, style = style, grouped = args.grouped) if args.outfile is None: outfile.close()
def action(args): controls, sample_groups = get_input(args.infile, split_description=args.split_desc) qadata = qa_from_csv(qafile) matrix = read_matrix(matrix_file) style = 'screen' if args.outfile == sys.stdout else 'file' outfile = get_outfile(args, label='qa', ext='csv') if args.calculate_ion_ratios: qadata = add_ion_ratios(qadata, controls) # if a single compound is specified, define lambda cond to use as # a filter if args.compound_id: cond = lambda c: c['COMPOUND_id'] == args.compound_id else: cond = lambda c: True # controls compounds = [ Compound(c, matrix, **qadata[c['COMPOUND_id']]) for c in flatten(controls.values()) if cond(c) ] display_controls(compounds, outfile=outfile, show_all=args.show_all, message=not args.outcomes_only, style=style) compounds = [ Compound(c, matrix, **qadata[c['COMPOUND_id']]) for c in flatten(sample_groups.values()) if cond(c) ] display_specimens(compounds, outfile=outfile, show_all=args.show_all, message=not args.outcomes_only, style=style) if args.outfile is None: outfile.close()
def action(args): nullchar = "." if args.outfile == sys.stdout else "" fmt = lambda s: "%.2f" % s if isinstance(s, float) else (s or nullchar) controls, sample_groups = get_input(args.infile) qadata = qa_from_csv(qafile) outfile = get_outfile(args, label="ion_ratios", ext="csv") std_ids, std_names = zip(*[(i, n) for i, n in CONTROL_NAMES if n.startswith("std")]) headers = ["qa_id", "qa_compound"] + list(std_names) + ["ion_ratio_avg_calc", "ion_ratio_avg"] writer = csv.DictWriter(outfile, fieldnames=headers, extrasaction="ignore") ion_ratios = mean_ion_ratios(controls, set(std_ids)) for compound_id, d in ion_ratios.items(): if compound_id == min(ion_ratios.keys()): writer.writerow(dict(zip(headers, headers))) d.update(qadata[compound_id]) writer.writerow(dict((k, fmt(d.get(k))) for k in headers))
def action(args): nullchar = '.' if args.outfile == sys.stdout else '' fmt = lambda s: '%.2f' % s if isinstance(s, float) else (s or nullchar) controls, sample_groups = get_input(args.infile) qadata = qa_from_csv(qafile) outfile = get_outfile(args, label='ion_ratios', ext='csv') std_ids, std_names = zip(*[(i, n) for i, n in CONTROL_NAMES if n.startswith('std')]) headers = ['qa_id', 'qa_compound'] + \ list(std_names) + ['ion_ratio_avg_calc', 'ion_ratio_avg'] writer = csv.DictWriter(outfile, fieldnames=headers, extrasaction='ignore') ion_ratios = mean_ion_ratios(controls, set(std_ids)) for compound_id, d in ion_ratios.items(): if compound_id == min(ion_ratios.keys()): writer.writerow(dict(zip(headers, headers))) d.update(qadata[compound_id]) writer.writerow(dict((k, fmt(d.get(k))) for k in headers))
def test06(self): args = Args(infile=self.infile, outfile=None, outdir=None) outfile = get_outfile(args, include_version=False) log.debug(outfile)
def test05(self): args = Args(infile=self.infile, outfile=None, outdir=None) outfile = get_outfile(args) log.debug(outfile)
def test04(self): outdir = mkdir(path.join(self.outdir, "subdir"), clobber=True) args = Args(infile=self.infile, outfile=None, outdir=outdir) outfile = get_outfile(args, label="qa") log.debug(outfile)
def test03(self): args = Args(infile=self.infile, outfile=open(path.join(self.outdir, "outfile.csv"), "w"), outdir=None) outfile = get_outfile(args, label="qa") log.debug(outfile)
def test01(self): args = Args(infile=self.infile, outfile=None, outdir=None) outfile = get_outfile(args, label="qa") log.debug(outfile)