annotate txtdiagnosis.py @ 1:b94872d65050 draft default tip

"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
author azomics
date Thu, 16 Jul 2020 07:35:26 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
1 #!/usr/bin/env python
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
2 ######################################################################
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
3 # Copyright (c) 2016 Northrop Grumman.
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
4 # All rights reserved.
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
5 ######################################################################
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
6 import pandas as pd
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
7 from argparse import ArgumentParser
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
8 import sys
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
9
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
10
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
11 def is_number(s):
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
12 try:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
13 float(s)
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
14 return True
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
15 except ValueError:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
16 return False
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
17
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
18
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
19 def error_report(input_file, fname, output_file):
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
20 errors = 0
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
21 df = pd.read_table(input_file)
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
22 with open(output_file, "w") as outf:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
23 for cols in df.columns.values:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
24 if df[cols].count() != len(df[cols]):
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
25 with open(input_file, "r") as checkfile:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
26 fl = checkfile.readline()
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
27 count_lines = 1
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
28 for checklines in checkfile:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
29 to_check = checklines.strip().split("\t")
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
30 count_lines += 1
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
31 for item in to_check:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
32 if not is_number(item):
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
33 errors += 1
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
34 outf.write(" ".join(["WARNING: line", str(count_lines), "in", fname, "contains non-numeric results\n"]))
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
35 if errors == 0:
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
36 outf.write("No errors in the file.\n")
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
37 return
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
38
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
39
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
40 if __name__ == "__main__":
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
41 parser = ArgumentParser(
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
42 prog="txtDiagnosis",
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
43 description="Reports potential errors in text-converted FCS files")
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
44
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
45 parser.add_argument(
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
46 '-i',
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
47 dest="input_file",
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
48 required=True,
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
49 help="File location for the text file.")
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
50
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
51 parser.add_argument(
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
52 '-n',
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
53 dest="filename",
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
54 required=True,
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
55 help="Filename location for the text file.")
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
56
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
57 parser.add_argument(
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
58 '-o',
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
59 dest="output_file",
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
60 required=True,
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
61 help="Name of the output file.")
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
62
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
63 args = parser.parse_args()
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
64
b94872d65050 "planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/txt_diagnosis commit 41bbf946c933eb16a0a7d0eac7928e7bf7f465ca"
azomics
parents:
diff changeset
65 error_report(args.input_file, args.filename, args.output_file)