예제 #1
0
파일: qa.py 프로젝트: nhoffman/opiates
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()
예제 #2
0
    def test05(self):
        args = Args(infile = self.infile,
                    outfile = None,
                    outdir = None)

        outfile = get_outfile(args)
        log.debug(outfile)
예제 #3
0
    def test06(self):
        args = Args(infile = self.infile,
                    outfile = None,
                    outdir = None)

        outfile = get_outfile(args, include_version = False)
        log.debug(outfile)
예제 #4
0
    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)
예제 #5
0
    def test01(self):
        args = Args(infile = self.infile,
                    outfile = None,
                    outdir = None)

        outfile = get_outfile(args, label = 'qa')
        log.debug(outfile)
예제 #6
0
    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)
예제 #7
0
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)
예제 #8
0
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()
예제 #9
0
파일: qa.py 프로젝트: nhoffman/opiates
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()
예제 #10
0
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))
예제 #11
0
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))
예제 #12
0
    def test06(self):
        args = Args(infile=self.infile, outfile=None, outdir=None)

        outfile = get_outfile(args, include_version=False)
        log.debug(outfile)
예제 #13
0
    def test05(self):
        args = Args(infile=self.infile, outfile=None, outdir=None)

        outfile = get_outfile(args)
        log.debug(outfile)
예제 #14
0
    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)
예제 #15
0
    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)
예제 #16
0
    def test01(self):
        args = Args(infile=self.infile, outfile=None, outdir=None)

        outfile = get_outfile(args, label="qa")
        log.debug(outfile)