comparison txt_diagnosis/txtdiagnosis.py @ 0:e1f0194cf8fc draft

Uploaded
author immport-devteam
date Mon, 27 Feb 2017 13:07:11 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e1f0194cf8fc
1 #!/usr/bin/env python
2 ######################################################################
3 # Copyright (c) 2016 Northrop Grumman.
4 # All rights reserved.
5 ######################################################################
6 from __future__ import print_function
7 from __future__ import division
8 import pandas as pd
9 from argparse import ArgumentParser
10 import sys
11
12
13 def is_number(s):
14 try:
15 float(s)
16 return True
17 except ValueError:
18 return False
19
20
21 def error_report(input_file, fname, output_file):
22 errors = 0
23 df = pd.read_table(input_file)
24 with open(output_file, "w") as outf:
25 for cols in df.columns.values:
26 if df[cols].count() != len(df[cols]):
27 with open(input_file, "r") as checkfile:
28 fl = checkfile.readline()
29 count_lines = 1
30 for checklines in checkfile:
31 to_check = checklines.strip().split("\t")
32 count_lines += 1
33 for item in to_check:
34 if not is_number(item):
35 errors += 1
36 outf.write(" ".join(["WARNING: line", str(count_lines), "in", fname, "contains non-numeric results\n"]))
37 if errors == 0:
38 outf.write("No errors in the file.\n")
39 return
40
41
42 if __name__ == "__main__":
43 parser = ArgumentParser(
44 prog="txtDiagnosis",
45 description="Reports potential errors in text-converted FCS files")
46
47 parser.add_argument(
48 '-i',
49 dest="input_file",
50 required=True,
51 help="File location for the text file.")
52
53 parser.add_argument(
54 '-n',
55 dest="filename",
56 required=True,
57 help="Filename location for the text file.")
58
59 parser.add_argument(
60 '-o',
61 dest="output_file",
62 required=True,
63 help="Name of the output file.")
64
65 args = parser.parse_args()
66
67 error_report(args.input_file, args.filename, args.output_file)
68 sys.exit(0)