mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-29 17:42:12 +08:00
Data validation. Please please please take a look and give me some input.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
Fix errors in a dataset.
|
||||
For now, only removing erroneous lines is supported.
|
||||
|
||||
usage: %prog input errorsfile output
|
||||
-x, --ext: dataset extension (type)
|
||||
-m, --methods=N: comma separated list of repair methods
|
||||
"""
|
||||
from cookbook import doc_optparse
|
||||
from galaxy import model
|
||||
from fileinput import FileInput
|
||||
from galaxy import util
|
||||
|
||||
def main():
|
||||
options, args = doc_optparse.parse( __doc__ )
|
||||
|
||||
try:
|
||||
if options.methods: methods = options.methods.split(",")
|
||||
ext = options.ext
|
||||
except:
|
||||
doc_optparse.exception()
|
||||
|
||||
in_file = open(args[0], "r")
|
||||
error_file = open(args[1], "r")
|
||||
out_file = open(args[2], "w")
|
||||
|
||||
# string_to_object errors
|
||||
error_list = util.string_to_object(error_file.read())
|
||||
# index by error type and then by line number
|
||||
error_lines = {}
|
||||
error_types = {}
|
||||
for error in error_list:
|
||||
if error.linenum:
|
||||
if error.linenum in error_lines:
|
||||
error_lines[error.linenum].append(error)
|
||||
else:
|
||||
error_lines[error.linenum] = [error]
|
||||
error_type = error.__class__.__name__
|
||||
if error_type in error_types:
|
||||
error_types[error_type].append(error)
|
||||
else:
|
||||
error_types[error_type] = [error]
|
||||
|
||||
linenum = 0
|
||||
for line in in_file:
|
||||
linenum += 1
|
||||
# write unless
|
||||
if "lines" in methods:
|
||||
if linenum in error_lines:
|
||||
line = None
|
||||
# other processing here?
|
||||
if line:
|
||||
out_file.write(line)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user