-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISAtab-validator_v1.py
47 lines (38 loc) · 1.61 KB
/
ISAtab-validator_v1.py
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
from sys import argv
from isatools import isatab
import os
import json
import codecs
from tempfile import TemporaryDirectory
# Parameters
# ----------
isa_config_dir = "./isaconfig-phenotyping-basic"
isa_tab_dir = argv[1]
# Converting all characters to UTF-8
# ----------------------------------
files = [f for f in os.listdir(isa_tab_dir) if f.endswith('.txt')]
with TemporaryDirectory() as tmpdirname:
print('Created temporary directory:', tmpdirname)
print('Converting files to UTF-8.')
for f in files:
with codecs.open(isa_tab_dir + os.sep + f, 'r') as file:
lines = file.read()
with codecs.open(tmpdirname + os.sep + f, 'w', encoding='utf8') as file:
file.write(lines)
# Validating ISA-TAB with configuration files
# -------------------------------------------
try:
print('Validating isa-tab files against configuration files found in ' + isa_config_dir)
validation_log_path = isa_tab_dir + os.sep + 'validation_log.json'
report = isatab.validate(
open(os.path.join(tmpdirname, 'i_investigation.txt')), isa_config_dir)
with open(validation_log_path, 'w') as out_fp2:
json.dump(report, out_fp2, indent=4)
print('VALIDATION FINISHED')
print("* Errors found: {}\n* Warnings found: {}\n* Info messages: {}".format(
len(report['errors']), len(report['warnings']), len(report['info'])))
print('The ISA-TAB validation log file can be found at: ' +
validation_log_path)
except Exception as ioe:
print('ISA-TAB validation failed!...')
print(str(ioe))