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,
|
default=False,
|
||||||
help="only valid python expressions are allowed")
|
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',
|
optionManager.add_option('--with-taxon-at-rank',
|
||||||
action='append',
|
action='append',
|
||||||
dest='taxonrank',
|
dest='taxonrank',
|
||||||
@@ -65,19 +84,28 @@ def sequenceTaggerGenerator(options):
|
|||||||
toSet = [x.split(':',1) for x in options.setTags if len(x.split(':',1))==2]
|
toSet = [x.split(':',1) for x in options.setTags if len(x.split(':',1))==2]
|
||||||
newId = options.setIdentifier
|
newId = options.setIdentifier
|
||||||
newDef = options.setDefinition
|
newDef = options.setDefinition
|
||||||
|
clear = options.clear
|
||||||
|
keep = set(options.keep)
|
||||||
|
length = options.length
|
||||||
if options.taxonomy is not None:
|
if options.taxonomy is not None:
|
||||||
annoteRank=options.taxonrank
|
annoteRank=options.taxonrank
|
||||||
else:
|
else:
|
||||||
annoteRank=[]
|
annoteRank=[]
|
||||||
|
|
||||||
def sequenceTagger(seq):
|
def sequenceTagger(seq):
|
||||||
for i in toDelete:
|
if clear or keep:
|
||||||
if i in seq:
|
ks = seq.keys()
|
||||||
del seq[i]
|
for k in ks:
|
||||||
for o,n in toRename:
|
if k not in keep:
|
||||||
if o in seq:
|
del seq[k]
|
||||||
seq[n]=seq[o]
|
else:
|
||||||
del seq[o]
|
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:
|
for i,v in toSet:
|
||||||
try:
|
try:
|
||||||
val = eval(v,{'sequence':seq},seq)
|
val = eval(v,{'sequence':seq},seq)
|
||||||
@@ -86,6 +114,10 @@ def sequenceTaggerGenerator(options):
|
|||||||
raise e
|
raise e
|
||||||
val = v
|
val = v
|
||||||
seq[i]=val
|
seq[i]=val
|
||||||
|
|
||||||
|
if length:
|
||||||
|
seq['seqLength']=len(seq)
|
||||||
|
|
||||||
if newId is not None:
|
if newId is not None:
|
||||||
try:
|
try:
|
||||||
val = eval(newId,{'sequence':seq},seq)
|
val = eval(newId,{'sequence':seq},seq)
|
||||||
|
Reference in New Issue
Block a user