obi grep: updated to work with the new line selection class and within
the local sequence environment, and progress bar functioning
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
from obitools3.apps.progress cimport ProgressBar # @UnresolvedImport
|
||||
from obitools3.obidms._obidms import OBIDMS, OBIView, OBIView_NUC_SEQS # TODO cimport doesn't work
|
||||
|
||||
from obitools3.obidms._obidms import OBIDMS, OBIView, OBIView_line_selection # TODO cimport doesn't work
|
||||
|
||||
from functools import reduce
|
||||
import time
|
||||
|
||||
__title__="Grep view lines that match the given predicates"
|
||||
@ -43,7 +43,7 @@ def addOptions(parser):
|
||||
group=parser.add_argument_group('obi grep specific options')
|
||||
|
||||
group.add_argument('--predicate','-p',
|
||||
action="store", dest="grep:predicate",
|
||||
action="append", dest="grep:predicates",
|
||||
metavar='<PREDICATE>',
|
||||
default=None,
|
||||
type=str,
|
||||
@ -59,29 +59,33 @@ def run(config):
|
||||
iview = d.open_view(config['obi']['inputview'])
|
||||
|
||||
# Initialize the progress bar
|
||||
#pb = ProgressBar(len(iview), config, seconde=5)
|
||||
pb = ProgressBar(len(iview), config, seconde=5)
|
||||
|
||||
# Apply filter
|
||||
# TODO try both kinds of line selection functions to check efficiency
|
||||
selection = []
|
||||
selection = OBIView_line_selection(iview)
|
||||
for i in range(len(iview)) :
|
||||
#pb(i)
|
||||
pb(i)
|
||||
line = iview[i]
|
||||
if isinstance(iview, OBIView_NUC_SEQS) : # put this somewhere else for efficiency
|
||||
sequence = line
|
||||
if eval(config['grep']['predicate']) :
|
||||
|
||||
loc_env = {'sequence': line, 'line': line} # TODO add taxonomy
|
||||
|
||||
good = (reduce(lambda bint x, bint y: x and y,
|
||||
(bool(eval(p, loc_env, line))
|
||||
for p in config['grep']['predicates']), True))
|
||||
|
||||
if good :
|
||||
selection.append(i)
|
||||
|
||||
# Create output view with the line selection
|
||||
oview = d.new_view(config['obi']['outputview'], view_to_clone=iview, line_selection=selection, comments="obi grep: "+config['grep']['predicate']+"\n")
|
||||
oview = d.new_view(config['obi']['outputview'], line_selection=selection, comments="obi grep: "+str(config['grep']['predicates'])+"\n")
|
||||
|
||||
repr(oview)
|
||||
#print("\n")
|
||||
#print(repr(oview))
|
||||
|
||||
iview.close()
|
||||
oview.close()
|
||||
d.close()
|
||||
|
||||
print("Done.")
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user