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