Skip to content

Commit

Permalink
added option to save output in json format
Browse files Browse the repository at this point in the history
  • Loading branch information
trvinh committed Oct 24, 2023
1 parent 60220b6 commit 7b003fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion greedyFAS/calcFAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def get_options():
outargs.add_argument("--tsv", dest="tsv", action="store_true",
help="deactivates creation of the tsv output, either use together with --raw or "
"--phyloprofile")
outargs.add_argument("--json", dest="json", action="store_true",
help="create json output")
outargs.add_argument("--phyloprofile", dest="phyloprofile", default=None, type=str,
help="activate phyloprofile output, needs mapping file for all query proteins")
outargs.add_argument("--domain", dest="domain", action="store_false",
Expand Down Expand Up @@ -178,7 +180,7 @@ def fas(args, toolpath):
"max_cardinality": args.max_cardinality, "cores": int(args.cpus), "raw": args.raw,
"bidirectional": args.bidirectional, "max_overlap": args.max_overlap,
"timelimit": args.timelimit, "phyloprofile": args.phyloprofile, "score_weights": [],
"tsv": args.tsv, "max_overlap_percentage": 0.0, "domain": args.domain, "pairwise": None,
"tsv": args.tsv, "json": args.json, "max_overlap_percentage": 0.0, "domain": args.domain, "pairwise": None,
"eInstance": args.eInstance, "eFeature": args.eFeature, "progress": True,
"empty_as_1": args.empty_as_1
}
Expand Down
16 changes: 16 additions & 0 deletions greedyFAS/mainFAS/fasOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@


from os.path import abspath
import json


def write_tsv_out(outpath, bidirectional, results):
Expand All @@ -45,6 +46,21 @@ def write_tsv_out(outpath, bidirectional, results):
out.close()


def write_json_out(outpath, bidirectional, results):
outdict = {}
for result in results[0]:
outdict[result[0], result[1]] = (result[2], ('NA', 'NA', 'NA', 'NA', 'NA'), result[3])
if bidirectional:
for result in results[1]:
outdict[result[1], result[0]] = (outdict[result[1], result[0]][0], result[2], outdict[result[1],
result[0]][2])
json_dict = {}
for pair in outdict:
json_dict['_'.join(pair)] = [f'{outdict[pair][0][0]:.4}', f'{outdict[pair][1][0]:.4}']
with open(f'{outpath}.json', 'w') as fp:
json.dump(json_dict, fp, ensure_ascii=False)


def write_domain_out_fad(seed_proteome, query_proteome, seed, query, weights, scale, seedpath, querypath, out, option,
interprokeys, phmm):
tools = option['input_linearized'] + option['input_normal']
Expand Down
6 changes: 5 additions & 1 deletion greedyFAS/mainFAS/greedyFAS.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from greedyFAS.mainFAS.fasInput import read_json
from greedyFAS.mainFAS.fasInput import check_version
from greedyFAS.mainFAS.fasOutput import write_domain_out
from greedyFAS.mainFAS.fasOutput import write_tsv_out
from greedyFAS.mainFAS.fasOutput import write_tsv_out, write_json_out
from greedyFAS.mainFAS.fasOutput import phyloprofile_out
from greedyFAS.mainFAS.fasScoring import sf_calc_score
from greedyFAS.mainFAS.fasScoring import sf_entire_calc_score
Expand Down Expand Up @@ -152,11 +152,15 @@ def fc_start(option):
phyloprofile_out(option["outpath"], True, option["phyloprofile"], (f_results, r_results))
if not option['tsv']:
write_tsv_out(option["outpath"], True, (f_results, r_results))
if option['json']:
write_json_out(option["outpath"], True, (f_results, r_results))
else:
print("calculating forward scores...")
results = fc_main(domain_count, seed_proteome, query_proteome, clan_dict, option, interprokeys, phmm)
if not option["tsv"]:
write_tsv_out(option["outpath"], False, (results, None))
if option["json"]:
write_json_out(option["outpath"], False, (results, None))
if option["phyloprofile"]:
phyloprofile_out(option["outpath"], False, option["phyloprofile"], [results, None])

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

setup(
name='greedyFAS',
version='1.17.13',
version='1.17.14',
python_requires='>=3.7.0',
description='A tool to compare protein feature architectures',
long_description=long_description,
Expand Down

0 comments on commit 7b003fa

Please sign in to comment.