Skip to content

Commit f1c880d

Browse files
committed
Added suffix option.
1 parent 5f03536 commit f1c880d

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

eigenstrat_database_tools.py

100755100644
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
parser._optionals.title = "Available options"
99
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 .")
1010
parser.add_argument("-o", "--Output", type=str, metavar="<OUTPUT FILES PREFIX>", required=False, help="The desired output file prefix. Three output files are created, <OUTPUT FILES PREFIX>.geno , <OUTPUT FILES PREFIX>.snp and <OUTPUT FILES PREFIX>.ind .")
11+
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.")
1112
group = parser.add_mutually_exclusive_group(required=True)
1213
group2 = parser.add_mutually_exclusive_group(required=False)
1314
group.add_argument("-C", "--Check", type=argparse.FileType('r'), metavar="<INPUT FILE>", required=False, help="Check the -i .ind file and the second .ind file for duplicate individuals. Population assignment and/or individual sex are not checked, only individual names. Names are case sensitive.")
@@ -26,9 +27,9 @@
2627
if args.Output is None:
2728
parser.error("Output files (-o) must be specified when using -R/-E functions")
2829

29-
IndFile = open(args.Input+".ind", "r")
30-
GenoFile = open(args.Input+".geno", "r")
31-
SnpFile = open(args.Input+".snp", "r")
30+
IndFile = open(args.Input+".ind"+args.Suffix, "r")
31+
GenoFile = open(args.Input+".geno"+args.Suffix, "r")
32+
SnpFile = open(args.Input+".snp"+args.Suffix, "r")
3233

3334

3435
#Check function
@@ -54,7 +55,7 @@
5455
#Check for errors in input files
5556
##Check geno and snp compatibility
5657
lineNo = ""
57-
for line in sh.grep(sh.wc("-l", args.Input+".geno", args.Input+".snp"), args.Input):
58+
for line in sh.grep(sh.wc("-l", args.Input+".geno"+args.Suffix, args.Input+".snp"+args.Suffix), args.Input):
5859
if lineNo=="":
5960
lineNo=line.strip().split()[0]
6061
elif lineNo==line.strip().split()[0]:
@@ -63,9 +64,9 @@
6364
raise IOError("Input .snp and .geno files do not match.")
6465

6566
##Check geno and ind compatibility
66-
with open(args.Input+".geno", "r") as f:
67+
with open(args.Input+".geno"+args.Suffix, "r") as f:
6768
for line in f:
68-
if str(len(line.strip())) == sh.wc("-l", args.Input+".ind").strip().split()[0]:
69+
if str(len(line.strip())) == sh.wc("-l", args.Input+".ind"+args.Suffix).strip().split()[0]:
6970
break
7071
else:
7172
raise IOError("Input .ind and .geno files do not match.")
@@ -93,7 +94,7 @@
9394
Sex = {}
9495
Pop = {}
9596
for i in Samples:
96-
for line in sh.grep(sh.cat("-n",args.Input+".ind"), "{}".format(i),_ok_code=[0,1]):
97+
for line in sh.grep(sh.cat("-n",args.Input+".ind"+args.Suffix), "{}".format(i),_ok_code=[0,1]):
9798
fields=line.strip().split()
9899
if fields[1] == i:
99100
Index[fields[1]]=(int(fields[0]) -1)
@@ -118,7 +119,7 @@
118119
for i in Samples:
119120
try: print (i, Sex[i], Pop[i], sep="\t", file=IndOutFile)
120121
except KeyError:
121-
print ("Individual \"",i,"\" not found in ",args.Input+".ind file.", sep="", file=sys.stderr)
122+
print ("Individual \"",i,"\" not found in ",args.Input+".ind"+args.Suffix+" file.", sep="", file=sys.stderr)
122123

123124
for line in SnpFile:
124125
print (line, end="", file =SnpOutFile)

0 commit comments

Comments
 (0)