Add --length option to obiannotate to replace the old fastalength script
This commit is contained in:
@ -49,6 +49,25 @@ def addSequenceEditTagOptions(optionManager):
|
||||
default=False,
|
||||
help="only valid python expressions are allowed")
|
||||
|
||||
optionManager.add_option('-C','--clear',
|
||||
action="store_true",
|
||||
dest='clear',
|
||||
default=False,
|
||||
help="clear all tags associated to the sequences")
|
||||
|
||||
optionManager.add_option('-k','--keep',
|
||||
action='append',
|
||||
dest='keep',
|
||||
default=[],
|
||||
type="string",
|
||||
help="only keep this tag")
|
||||
|
||||
optionManager.add_option('--length',
|
||||
action="store_true",
|
||||
dest='length',
|
||||
default=False,
|
||||
help="add seqLength tag with sequence length")
|
||||
|
||||
optionManager.add_option('--with-taxon-at-rank',
|
||||
action='append',
|
||||
dest='taxonrank',
|
||||
@ -65,19 +84,28 @@ def sequenceTaggerGenerator(options):
|
||||
toSet = [x.split(':',1) for x in options.setTags if len(x.split(':',1))==2]
|
||||
newId = options.setIdentifier
|
||||
newDef = options.setDefinition
|
||||
clear = options.clear
|
||||
keep = set(options.keep)
|
||||
length = options.length
|
||||
if options.taxonomy is not None:
|
||||
annoteRank=options.taxonrank
|
||||
else:
|
||||
annoteRank=[]
|
||||
|
||||
def sequenceTagger(seq):
|
||||
for i in toDelete:
|
||||
if i in seq:
|
||||
del seq[i]
|
||||
for o,n in toRename:
|
||||
if o in seq:
|
||||
seq[n]=seq[o]
|
||||
del seq[o]
|
||||
if clear or keep:
|
||||
ks = seq.keys()
|
||||
for k in ks:
|
||||
if k not in keep:
|
||||
del seq[k]
|
||||
else:
|
||||
for i in toDelete:
|
||||
if i in seq:
|
||||
del seq[i]
|
||||
for o,n in toRename:
|
||||
if o in seq:
|
||||
seq[n]=seq[o]
|
||||
del seq[o]
|
||||
for i,v in toSet:
|
||||
try:
|
||||
val = eval(v,{'sequence':seq},seq)
|
||||
@ -86,6 +114,10 @@ def sequenceTaggerGenerator(options):
|
||||
raise e
|
||||
val = v
|
||||
seq[i]=val
|
||||
|
||||
if length:
|
||||
seq['seqLength']=len(seq)
|
||||
|
||||
if newId is not None:
|
||||
try:
|
||||
val = eval(newId,{'sequence':seq},seq)
|
||||
|
Reference in New Issue
Block a user