Skip to content

Commit 64ffcd8

Browse files
author
Philipp Angerer
committed
also converted index and taxtbl
1 parent 60067d5 commit 64ffcd8

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

taxMaps-index

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ parser.add_option(
115115
help = "Dry run (default = False)"
116116
)
117117

118-
(opt, args) = parser.parse_args()
119-
if not opt.fasta_file or not opt.corr_file or not opt.tax_file:
120-
parser.print_help()
121-
sys.exit(-1)
122-
123118

124119
######################################################### /ARGUMENTS,OPTIONS ###
125120
################################################################################
@@ -137,7 +132,15 @@ if not opt.fasta_file or not opt.corr_file or not opt.tax_file:
137132
################################################################################
138133
### MAIN #######################################################################
139134

140-
if __name__ == '__main__':
135+
def main(args=None):
136+
if args is None:
137+
args = sys.argv
138+
139+
opt, args = parser.parse_args(args)
140+
if not opt.fasta_file or not opt.corr_file or not opt.tax_file:
141+
parser.print_help()
142+
sys.exit(-1)
143+
141144
module_dir = os.path.abspath(os.path.dirname(__file__))
142145

143146
fasta_f = opt.fasta_file
@@ -160,7 +163,7 @@ if __name__ == '__main__':
160163
if sge_queue:
161164
sge_f = prefix + '.sge'
162165

163-
dry_run = opt.dry
166+
dry_run = opt.dry
164167

165168
gitax_str = ' '.join(['txM_gitax', '-i', fasta_f, '-c', gitax_f,'-t', tax_f, '2>', out_f, '>', in_f])
166169
len_str = ' '.join(['txM_fastalen', '-i', in_f, '>', len_f])
@@ -187,3 +190,5 @@ if __name__ == '__main__':
187190
###################################################################### /MAIN ###
188191
################################################################################
189192

193+
if __name__ == '__main__':
194+
main()

taxMaps-taxtbl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ parser.add_option(
6767
help = "NCBI Taxonomy nodes.dmp file (Mandatory)"
6868
)
6969

70-
(opt, args) = parser.parse_args()
71-
72-
if not opt.names_file or not opt.nodes_file:
73-
parser.print_help()
74-
exit(-1)
7570

7671
######################################################### /ARGUMENTS,OPTIONS ###
7772
################################################################################
@@ -89,30 +84,42 @@ if not opt.names_file or not opt.nodes_file:
8984
################################################################################
9085
### MAIN #######################################################################
9186

92-
if __name__ == '__main__':
87+
def main(args=None):
88+
if args is None:
89+
args = sys.argv
90+
91+
opt, args = parser.parse_args(args)
92+
93+
if not opt.names_file or not opt.nodes_file:
94+
parser.print_help()
95+
sys.exit(-1)
96+
9397
node_dict = {}
9498

9599
nodes_file = open(opt.nodes_file, 'r')
96100
for line in nodes_file:
97-
la = line.strip().split('\t')
101+
la = line.strip().split('\t')
98102
node = la[0]
99103
parent = la[2]
100104
rank = la[4]
101105
node_dict[node] = [parent, rank]
102-
nodes_file.close()
106+
nodes_file.close()
103107

104108
names_file = open(opt.names_file, 'r')
105109
for line in names_file:
106-
la = line.strip().split('\t')
110+
la = line.strip().split('\t')
107111
if la[6] == 'scientific name':
108112
node = la[0]
109113
sci_name = la[2]
110114
node_dict[node].append(sci_name)
111-
names_file.close()
115+
names_file.close()
112116

113117
for node in node_dict:
114118
node_list = [node] + node_dict[node][1:] + [':'.join(find_path(node, node_dict))]
115119
sys.stdout.write('\t'.join(node_list) + '\n')
116120

117121
###################################################################### /MAIN ###
118122
################################################################################
123+
124+
if __name__ == '__main__':
125+
main()

0 commit comments

Comments
 (0)