-
Notifications
You must be signed in to change notification settings - Fork 0
/
taxonmatcher.py
executable file
·38 lines (35 loc) · 1.76 KB
/
taxonmatcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
from taxonmatcher_scripts.nsr import Nsr #Nederlands soorten register
import argparse
# Retrieve the commandline arguments
parser = argparse.ArgumentParser(description='taxonmatcher')
parser.add_argument('-i', '--input', metavar='namelist or blast output', dest='input', type=str, required=True)
parser.add_argument('-r', '--reference', metavar='taxonomy reference', dest='reference', type=str, required=True, choices=['nsr'])
parser.add_argument('-t', '--type', dest='type', type=str, required=True, choices=['nameslist', 'blast'])
parser.add_argument('-o', '--output', metavar='output', dest='output', type=str, required=True)
parser.add_argument('-n', '--nsr', help='nsr reference path', dest='nsr', type=str, required=False)
parser.add_argument('-g', '--gbif', help='gbif reference path', dest='gbif', type=str, required=False)
args = parser.parse_args()
if args.reference == "nrs":parser.error("missing -n/--nsr")
def get_input_list():
namesList = []
if args.type == "nameslist":
with open(args.input, "r") as names:
for x in names:
namesList.append(x.strip())
elif args.type == "blast":
with open(args.input, "r") as blast:
for x in blast:
namesList.append(x.split("\t")[-1].split(" / ")[-1])
return namesList
def main():
names = get_input_list()
if args.reference == "nsr":
nsr = Nsr(args.nsr)
matches = nsr.match(names)
with open(args.output, "a") as output:
output.write("\t".join(["#Input","#MatchType","#Synonym name","#Accepted name","#Kingdom","#Phylum","#Class","#Order","#Family","#Genus","#Metadata"]) + "\n")
for x in matches:
output.write("\t".join(x)+"\n")
if __name__ == "__main__":
main()