|
8 | 8 | parser._optionals.title = "Available options" |
9 | 9 | 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 .") |
10 | 10 | 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.") |
11 | 12 | group = parser.add_mutually_exclusive_group(required=True) |
12 | 13 | group2 = parser.add_mutually_exclusive_group(required=False) |
13 | 14 | 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 | 27 | if args.Output is None: |
27 | 28 | parser.error("Output files (-o) must be specified when using -R/-E functions") |
28 | 29 |
|
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") |
32 | 33 |
|
33 | 34 |
|
34 | 35 | #Check function |
|
54 | 55 | #Check for errors in input files |
55 | 56 | ##Check geno and snp compatibility |
56 | 57 | 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): |
58 | 59 | if lineNo=="": |
59 | 60 | lineNo=line.strip().split()[0] |
60 | 61 | elif lineNo==line.strip().split()[0]: |
|
63 | 64 | raise IOError("Input .snp and .geno files do not match.") |
64 | 65 |
|
65 | 66 | ##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: |
67 | 68 | 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]: |
69 | 70 | break |
70 | 71 | else: |
71 | 72 | raise IOError("Input .ind and .geno files do not match.") |
|
93 | 94 | Sex = {} |
94 | 95 | Pop = {} |
95 | 96 | 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]): |
97 | 98 | fields=line.strip().split() |
98 | 99 | if fields[1] == i: |
99 | 100 | Index[fields[1]]=(int(fields[0]) -1) |
|
118 | 119 | for i in Samples: |
119 | 120 | try: print (i, Sex[i], Pop[i], sep="\t", file=IndOutFile) |
120 | 121 | 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) |
122 | 123 |
|
123 | 124 | for line in SnpFile: |
124 | 125 | print (line, end="", file =SnpOutFile) |
|
0 commit comments