From 74f264d057906304f69d0aaca321662239d7c287 Mon Sep 17 00:00:00 2001 From: Alexander Peltzer Date: Sun, 13 Oct 2019 11:46:59 +0200 Subject: [PATCH 1/4] Add JSON Support --- Sex.DetERRmine.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sex.DetERRmine.py b/Sex.DetERRmine.py index f05ab53..fc934a7 100755 --- a/Sex.DetERRmine.py +++ b/Sex.DetERRmine.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -import sys, argparse +import sys, argparse, json from math import sqrt from collections import OrderedDict @@ -89,3 +89,5 @@ def CalcErrors(AutSnps, XSnps, YSnps, NrAut, NrX, NrY): for Ind in Names: rate,rateErr=CalcErrors(AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]]) print (Ind, AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]], rate["X"], rate["Y"], rateErr["X"], rateErr["Y"], sep="\t", file=sys.stdout) +with open('sexdetermine.json', w) as outfile: + json.dump(Names, outfile) \ No newline at end of file From d41edab190b018c70f1920a4fc3ebd8de3185555 Mon Sep 17 00:00:00 2001 From: Alexander Peltzer Date: Sun, 13 Oct 2019 13:05:30 +0200 Subject: [PATCH 2/4] Mini fix for rate Errors --- Sex.DetERRmine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sex.DetERRmine.py b/Sex.DetERRmine.py index fc934a7..d1582f9 100755 --- a/Sex.DetERRmine.py +++ b/Sex.DetERRmine.py @@ -86,8 +86,12 @@ def CalcErrors(AutSnps, XSnps, YSnps, NrAut, NrX, NrY): # SortNames=OrderedDict(sorted(Names.items(), key=lambda t: t[1])) print ("#Sample", "#SnpsAut", "#SNPsX", "#SnpsY", "NrAut", "NrX", "NrY", "x-rate", "y-rate", "Err(x-rate)", "Err(y-rate)", sep="\t", file=sys.stdout) +data=OrderedDict() for Ind in Names: rate,rateErr=CalcErrors(AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]]) + data[Ind] = [AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]], rate["X"], rate["Y"], rateErr["X"], + rateErr["Y"]] print (Ind, AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]], rate["X"], rate["Y"], rateErr["X"], rateErr["Y"], sep="\t", file=sys.stdout) + with open('sexdetermine.json', w) as outfile: - json.dump(Names, outfile) \ No newline at end of file + json.dump(data, outfile) \ No newline at end of file From 1bc002b413ad8d469f69d6ff3f675be74a762ff2 Mon Sep 17 00:00:00 2001 From: Alexander Peltzer Date: Sun, 13 Oct 2019 13:13:23 +0200 Subject: [PATCH 3/4] Better JSON output --- Sex.DetERRmine.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sex.DetERRmine.py b/Sex.DetERRmine.py index d1582f9..83bc066 100755 --- a/Sex.DetERRmine.py +++ b/Sex.DetERRmine.py @@ -89,9 +89,8 @@ def CalcErrors(AutSnps, XSnps, YSnps, NrAut, NrX, NrY): data=OrderedDict() for Ind in Names: rate,rateErr=CalcErrors(AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]]) - data[Ind] = [AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]], rate["X"], rate["Y"], rateErr["X"], - rateErr["Y"]] + data[Ind] = {"Snps Autosomal" : AutSnps, "XSnps" : XSnps, "YSnps": YSnps, "NR Aut" : NrAut[Names[Ind]],"NrX": NrX[Names[Ind]], "NrY": NrY[Names[Ind]], "RateX" : rate["X"], "RateY": rate["Y"], "RateErrX" : rateErr["X"], "RateErrY" : rateErr["Y"]} print (Ind, AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]], rate["X"], rate["Y"], rateErr["X"], rateErr["Y"], sep="\t", file=sys.stdout) -with open('sexdetermine.json', w) as outfile: +with open('sexdetermine.json', 'w') as outfile: json.dump(data, outfile) \ No newline at end of file From 28cb4172cc1ffdc33f64a869018965338bc0a57a Mon Sep 17 00:00:00 2001 From: Alexander Peltzer Date: Sun, 13 Oct 2019 13:20:32 +0200 Subject: [PATCH 4/4] Add in Metadata --- Sex.DetERRmine.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sex.DetERRmine.py b/Sex.DetERRmine.py index 83bc066..d2fabea 100755 --- a/Sex.DetERRmine.py +++ b/Sex.DetERRmine.py @@ -3,6 +3,8 @@ from math import sqrt from collections import OrderedDict +VERSION=1.1 + def CalcErrors(AutSnps, XSnps, YSnps, NrAut, NrX, NrY): SNPs=[AutSnps, XSnps, YSnps] Reads=[NrAut, NrX, NrY] @@ -87,10 +89,14 @@ def CalcErrors(AutSnps, XSnps, YSnps, NrAut, NrX, NrY): # SortNames=OrderedDict(sorted(Names.items(), key=lambda t: t[1])) print ("#Sample", "#SnpsAut", "#SNPsX", "#SnpsY", "NrAut", "NrX", "NrY", "x-rate", "y-rate", "Err(x-rate)", "Err(y-rate)", sep="\t", file=sys.stdout) data=OrderedDict() +# Add in proper tool version info to JSON output +data['Metadata'] = {'tool_name' : "Sex.DetERRmine", "version" : VERSION} for Ind in Names: rate,rateErr=CalcErrors(AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]]) data[Ind] = {"Snps Autosomal" : AutSnps, "XSnps" : XSnps, "YSnps": YSnps, "NR Aut" : NrAut[Names[Ind]],"NrX": NrX[Names[Ind]], "NrY": NrY[Names[Ind]], "RateX" : rate["X"], "RateY": rate["Y"], "RateErrX" : rateErr["X"], "RateErrY" : rateErr["Y"]} print (Ind, AutSnps, XSnps, YSnps, NrAut[Names[Ind]], NrX[Names[Ind]], NrY[Names[Ind]], rate["X"], rate["Y"], rateErr["X"], rateErr["Y"], sep="\t", file=sys.stdout) - + +#Debugging purposes only +#print(json.dumps(data, indent=4, sort_keys=True)) with open('sexdetermine.json', 'w') as outfile: json.dump(data, outfile) \ No newline at end of file