Mercurial > repos > cpt > cpt_search_file
comparison editDB.py @ 1:6e3a843b6304 draft
planemo upload commit 94b0cd1fff0826c6db3e7dc0c91c0c5a8be8bb0c
author | cpt |
---|---|
date | Mon, 05 Jun 2023 02:53:18 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:bd2ff2c7e806 | 1:6e3a843b6304 |
---|---|
1 # Remove duplicate terms. As well as add any that is needed. | |
2 | |
3 import explodeJSON as ej | |
4 from explodeJSON import save_dict_to_json | |
5 | |
6 | |
7 ### create new key | |
8 def add_new_key(db, add_key=[]): | |
9 """Set of keys to add to the database""" | |
10 for new_key in add_key: | |
11 db[new_key] = [] | |
12 | |
13 return db | |
14 | |
15 | |
16 ### Add values to dbase: | |
17 def add_value_to_term(index_val, db, add_value=[]): | |
18 """index value, put in value""" | |
19 for val in add_value: | |
20 db[index_val].append(val) | |
21 | |
22 return db | |
23 | |
24 | |
25 ### Remove values from dbase: | |
26 def remove_value_from_term(index_val, db, remove_value=[]): | |
27 """remove values from list""" | |
28 for val in remove_value: | |
29 db[index_val].remove(val) | |
30 | |
31 return db | |
32 | |
33 | |
34 ### Terms to add from a file | |
35 def add_from_file(input_file, index_val, db, sep="\n"): | |
36 """input file, new line separated currently, and append files to correct key, return is altered dictionary""" | |
37 terms = open(input_file).read().splitlines() | |
38 db = add_value_to_term(index_val, db, terms) | |
39 return db | |
40 | |
41 | |
42 if __name__ == "__main__": | |
43 | |
44 lysis_json = "data/lysis-family-v1.0.2.json" # insert json of choice | |
45 db = ej.explodeJSON(lysis_json) | |
46 db = db.readJSON() | |
47 # revise_db = add_new_key(db=db,add_key=["spanins"]) | |
48 # files = ["data/term_additions/200505_holin_domains.txt","data/term_additions/200505_Spanin_Domains.txt"] | |
49 terms = [ | |
50 "DUF2570", | |
51 "PF10828", | |
52 "IPR022538", | |
53 "DUF2514", | |
54 "PF10721", | |
55 "IPR019659", | |
56 "DUF2681", | |
57 "PF10883", | |
58 "IPR020274", | |
59 ] | |
60 # revise_db = add_from_file(files[0],"holin_domains",revise_db) | |
61 # revise_db = add_from_file(files[1],"spanin_domains",revise_db) | |
62 revise_db = add_value_to_term("spanin_domains", db, add_value=terms) | |
63 save_dict_to_json(obj=revise_db, filename="data/lysis-family-v1.0.3.json") |