Skip to content

Commit 4094b74

Browse files
committed
Flexible JSON output naming.
1 parent 67041bc commit 4094b74

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

eigenstrat_snp_coverage.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pandas as pd
55
from collections import OrderedDict
66

7-
VERSION = "1.0.1"
7+
VERSION = "1.0.2"
88

99
## A function to return the number of lines of a file
1010
def file_len(fname):
@@ -50,19 +50,20 @@ def get_ind_names(indf):
5050
parser.add_argument("-i", "--Input", type = str, metavar = "<INPUT FILES PREFIX>", required = True, help = "The desired input file prefix. Input files are assumed to be <INPUT PREFIX>.geno, <INPUT PREFIX>.snp and <INPUT PREFIX>.ind .")
5151
parser.add_argument("-s", "--Suffix", type = str, metavar = "<INPUT FILE SUFFIX>", required = False, default = '', help = "The suffix (if any) that follows .geno/.snp/.ind in the input files. For example, specifying '-s .txt' will treat <INPUT PREFIX>.{geno,snp,ind}.txt as the desired input files.")
5252
parser.add_argument("-o", "--Output", type = str, metavar = "<OUTPUT FILEPATH>", required = False, help = "The filepath where the output table should be saved. Omit to print to stdout.")
53-
parser.add_argument("-j", "--json", action = "store_true", help = "Create additional json formatted output file named <OUTPUT FILE>.json . [Default: '<INPUT FILES PREFIX>_eigenstrat_coverage_mqc.json']")
53+
parser.add_argument("-j", "--json", type = str, metavar = "<JSON OUTPUT FILEPATH>", default = None, help = "Create additional json formatted output file named <JSON OUTPUT FILEPATH> .")
5454
parser.add_argument("-v", "--version", action='version', version="%(prog)s {}".format(VERSION), help="Print the version and exit.")
5555
args = parser.parse_args()
5656

5757
## Set dynamic output files
5858
if args.Output == None:
5959
out_file = sys.stdout
60-
if args.json:
61-
json_output = args.Input+'_eigenstrat_coverage.json'
6260
else:
6361
out_file = open(args.Output, 'w')
64-
if args.json:
65-
json_output = args.Output+'.json'
62+
63+
if args.json == None:
64+
json_output = None
65+
else:
66+
json_output = args.json
6667

6768
## Initialise empty data table as dictionary
6869
data = {}
@@ -94,7 +95,7 @@ def get_ind_names(indf):
9495
for ind in ind_list:
9596
print(ind, data[ind]["Covered_Snps"], data[ind]["Total_Snps"], sep="\t", file=out_file)
9697

97-
if args.json:
98+
if json_output != None:
9899
with open(json_output, 'w') as json_outfile:
99100
json.dump(data, json_outfile)
100101

0 commit comments

Comments
 (0)