4
4
from org .opentreeoflife .taxa import Taxonomy , Nexson , Flag
5
5
from org .opentreeoflife .conflict import ConflictAnalysis , Disposition
6
6
7
- repo_dir = '../repo' # directory containing repo clones
8
-
9
- default_shard = os .path .join (repo_dir , 'phylesystem-1' )
10
-
11
7
# Report generation
12
8
13
9
# Report on every tree in every study
@@ -19,6 +15,7 @@ def report_on_trees(study_ids, shard, refs, outfile):
19
15
count = 0
20
16
for study_id in study_ids :
21
17
study = get_study (study_id , shard )
18
+ if study == None : continue
22
19
for tree in tree_iter_nexson_proxy (study ):
23
20
row = report_on_tree (tree , study , refs )
24
21
writer .writerow (row )
@@ -154,7 +151,7 @@ def ingroup(self):
154
151
155
152
# shard is the path to the root of the repository (or shard) clone
156
153
157
- def study_id_to_path (study_id , shard = default_shard ):
154
+ def study_id_to_path (study_id , shard ):
158
155
(prefix , number ) = study_id .split ('_' , 1 )
159
156
if len (number ) == 1 :
160
157
residue = '_' + number
@@ -183,45 +180,13 @@ def gobble_study(study_id, phylesystem):
183
180
# should do try/catch for file-not-found
184
181
if not os .path .exists (filepath ):
185
182
# foo, should be using try/catch
186
- print '** Not found:' , self . filepath
183
+ print '** Not found:' , filepath
187
184
return None
188
185
return NexsonProxy (filepath )
189
186
190
187
def import_tree (tree ):
191
188
return Nexson .importTree (tree .nexson_tree , tree ._nexson_proxy .reftax_otus , tree .tree_id )
192
189
193
- # Study/tree ids in a collection
194
-
195
- def collection_treespecs (path ):
196
- with open (path , 'r' ) as infile :
197
- collection_json = json .load (infile )
198
- return map (lambda coll : (coll [u'studyID' ], coll [u'treeID' ]),
199
- collection_json [u'decisions' ])
200
-
201
- synthesis_treespecs = [] # rank order
202
- trees_in_synthesis = {}
203
-
204
- def read_synthesis_collections ():
205
- if len (synthesis_treespecs ) > 0 : return
206
- for collection_name in ['fungi' ,
207
- 'safe-microbes' ,
208
- 'metazoa' ,
209
- 'plants' ]:
210
- path = os .path .join (repo_dir , 'collections-1/collections-by-owner/opentreeoflife' , collection_name + '.json' )
211
- print 'reading' , path
212
- for treespec in collection_treespecs (path ):
213
- synthesis_treespecs .append (treespec )
214
- trees_in_synthesis [treespec ] = True
215
-
216
- def in_synthesis (study_id , tree_id ):
217
- if len (trees_in_synthesis ) == 0 :
218
- read_synthesis_collections ()
219
- treespec = (study_id , tree_id )
220
- if treespec in trees_in_synthesis :
221
- return trees_in_synthesis [treespec ]
222
- else :
223
- return False
224
-
225
190
# Utilities associated with obtaining study and tree lists for reporting
226
191
227
192
# All study ids within a given phylesystem (shard)
@@ -231,12 +196,13 @@ def all_study_ids(shard):
231
196
top = os .path .join (shard , 'study' )
232
197
hundreds = os .listdir (top )
233
198
for dir in hundreds :
234
- dir2 = os .path .join (top , dir )
235
- if os .path .isdir (dir2 ):
236
- dirs = os .listdir (dir2 )
237
- for study_dir in dirs :
238
- # if os.path.isdir(study_dir): ... ? ...
239
- ids .append (study_dir )
199
+ if not dir .startswith ('.' ):
200
+ dir2 = os .path .join (top , dir )
201
+ if os .path .isdir (dir2 ):
202
+ dirs = os .listdir (dir2 )
203
+ for study_dir in dirs :
204
+ # if os.path.isdir(study_dir): ... ? ...
205
+ ids .append (study_dir )
240
206
print len (ids ), 'studies'
241
207
return ids
242
208
@@ -263,6 +229,7 @@ def load_tree(path):
263
229
print count , 'ids'
264
230
return tree
265
231
232
+ repo_dir = '../..' # directory containing repo clones
266
233
registry_dir = os .path .join (repo_dir , 'reference-taxonomy' , 'registry' )
267
234
268
235
# consider comparing the "^ot:focalClade" to the induced root
@@ -274,7 +241,7 @@ def load_tree(path):
274
241
argparser .add_argument ('--out' , dest = 'outfile' , default = '-' )
275
242
276
243
argparser .add_argument ('--shard' , dest = 'shard' ,
277
- default = default_shard ,
244
+ default = os . path . join ( repo_dir , 'phylesystem-1' ) ,
278
245
help = 'root directory of repository (shard) containing nexsons' )
279
246
argparser .add_argument ('--ref' , dest = 'refs' , nargs = '+' ,
280
247
default = os .path .join (registry_dir , 'draftversion4.tre' ), # synthetic tree is a newick...
0 commit comments