-
Notifications
You must be signed in to change notification settings - Fork 7
/
cual-id
72 lines (62 loc) · 2.65 KB
/
cual-id
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
import click
import sys
from cualid.label import get_barcodes
from cualid.mint import create_ids
from cualid.fix import fix_ids, format_output, parse_ids
@click.group()
def cli():
pass
@cli.group()
def create():
"""Command to create barcode labels or sample ids."""
pass
@create.command("labels")
@click.argument('input', type=click.File('U'), required=True)
@click.option('-o', '--output-pdf', type=click.STRING, required=True)
@click.option('--suppress-ids', is_flag=True)
@click.option('--barcode', type=click.STRING, required=False)
def barcode_generator(input, output_pdf, suppress_ids, barcode):
"""This script generates a pdf of barcodes"""
if suppress_ids and barcode == 'none':
click.ClickException("Please don't do that").show()
exit()
barcodes = get_barcodes(input, output_pdf, suppress_ids, barcode)
barcodes.save()
@create.command("ids")
@click.argument('number-of-ids', type=int)
@click.option('-l', '--length', type=int, default=8, required=False)
@click.option('-f', '--fail-threshold', type=float, default=0.99, required=False)
@click.option('-e', '--existing-ids', type=click.File('U'), default=None, required=False)
def sample_id_generator(number_of_ids, length, fail_threshold, existing_ids):
"""This script generates a file of sample IDs"""
if fail_threshold >= 1:
raise ValueError("")
collected = 0
if existing_ids:
existing_ids = parse_ids(existing_ids, 0)
for hrid, uuid_ in create_ids(number_of_ids, length,
failure_threshold=fail_threshold,
existing_ids=existing_ids):
collected += 1
click.echo("%s\t%s" %(hrid, uuid_))
if collected != number_of_ids:
click.echo(
"\033[1;31m"
"Could only collect %d out of %d.\nGreater than %f%% of the"
" generated CualIDs were not sufficiently unique."
"\033[0;0m" % (collected, number_of_ids, fail_threshold * 100), err=True)
@cli.command("fix")
@click.argument('ids-to-be-corrected', type=click.File('U'), required=True)
@click.option('--correct-ids', type=click.File('U'), required=True)
@click.option('-s', '--show', type=click.STRING, default='DFN', required=False)
@click.option('-a', '--all', is_flag=True, default=False, required=False)
def correct_ids(correct_ids, ids_to_be_corrected, show, all):
"""Compare a set of possibly invalid IDs against a correct set of IDs
to identify errors in the IDs"""
if all:
show = 'DFNV'
for line in format_output(fix_ids(correct_ids, ids_to_be_corrected), show):
click.echo(line)
if __name__ == '__main__':
cli()