-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsv_to_json.py
executable file
·51 lines (36 loc) · 1.24 KB
/
tsv_to_json.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
48
49
50
51
#AUTHOR: RATTINA Vimel - 2020/02/12 - SIB & Enyo Pharma
import sys #I/O files
import os, errno #create folder
import csv #parse tsv
import logging #log file
import json
import csv
logging.basicConfig(format='%(asctime)s\t%(levelname)s\t%(message)s', filename='main.log', level=logging.DEBUG)
###Convert a tsv file to json format
## INPUTS: ##
##-A tsv file
## OUTPUTS: ##
##-A json file
###################
# FUNCTIONS #######
###################
##Function
##Function writting the output file with the propagated PPi
def tsv_to_json(tsv_file, json_output):
logging.info("Starts "+tsv_file+" conversion into json")
json_file = open(json_output, "w")
with open(tsv_file) as input_file:
reader = csv.DictReader(input_file, delimiter="\t")
data = list(reader)
json_data = json.dumps(data)
json_file.write(json_data)
json_file.close()
logging.info("Conversion into json ends")
####################
# MAIN #############
####################
if len(sys.argv) < 3:
sys.exit('Usage: %s <tsv_file> <json_output>\n<tsv_file>: a tsv file\n<json_output>: a json file' % sys.argv[0])
if __name__ == "__main__":
tsv_to_json(sys.argv[1], sys.argv[2])
#./tsv_to_json.py ppi_ntintegre ppi_ntintegre.json