[gt-users] method to either delete a child from a FeatureNode, or to update its type
La Rota, Mauricio
MAURICIO.LAROTA at PIONEER.COM
Thu Apr 30 02:24:20 CEST 2009
Hi Sascha and Gordon,
Is there a way to update the type of an already existing child feature? What about to remove it and recreate a correct one?
I am trying to correct the type for the wrongly labeled UTRs in the GFF files I am working with (I sent two sample GFF files yesterday in the thread "A series of questions regarding GenomeTools C and its Python interface") and since I don't see a way to modify (or have access to) a FeatureNode's type with something like FeatureNode.setType() I was instead trying to remove the child node (with fn.__del__) and recreating a new one in its place.
Of the two choices, it might be cleaner just o update the type. The sample GFF contains some gene models for which the UTRs labels are reversed (5' should be 3' or viceversa).
Please see my python function below where I was trying to take a pointer to the current child_feature, checking it and returning the same one if nothing needed updating or destroying it and recreating a new one. See line annotated with "****"
Thanks,
Mauricio.
I would call it like this:
haveSeenCDS = False
fni = FeatureNodeIteratorDirect(feature)
tfn = fni.next()
while tfn:
.... some operations here ..
tfn = assertUTR_ok(seqid, feature, tfn , haveSeenCDS)
if (tfn.get_type() == "CDS"):
haveSeenCDS = True
.... more operations here ..
tfn = fni.next()
==== function is below ====
def assertUTR_ok(fn_seqid, fn_parent, fn , SeenCDS):
# first let's make sure we are dealing with a UTR
fn_type = fn.get_type()
if not (fn_type.endswith("prime_UTR") ):
return fn
# Ok, now operate on this item
fn_strand = fn.get_strand()
fn_start,fn_end = fn.get_range()
fn_new_type = ""
# Have SEEN CDS
if (SeenCDS):
if (fn_strand == "+"): # we know this should be a 3'UTR
fn_new_type = "three_prime_UTR"
else: # fn_strand == "-" # should be 5'UTR
fn_new_type = "five_prime_UTR"
# Have NOT seen CDS
else: # SeenCDS == False
if (fn_strand == "+"):
fn_new_type = "five_prime_UTR"
else:
fn_new_type = "three_prime_UTR"
# Now check if labeled correctly
if (fn_type == fn_new_type):
return fn
else:
# make new copy of fn, with correct type
new_child = FeatureNode.create_new(fn_seqid, \
fn_new_type, fn_start, fn_end, fn_strand)
# attach all other attributes
new_child.set_source(fn.get_source())
for thistag, thisval in fn.each_attribute():
new_child.add_attribute(thistag, thisval)
# add new_child to its parent
fn_parent.add_child(new_child)
# delete offending child node
fn.__del__() **** <- does not seem to delete the node
return new_child
====
This communication is for use by the intended recipient and contains
information that may be Privileged, confidential or copyrighted under
applicable law. If you are not the intended recipient, you are hereby
formally notified that any use, copying or distribution of this e-mail,
in whole or in part, is strictly prohibited. Please notify the sender by
return e-mail and delete this e-mail from your system. Unless explicitly
and conspicuously designated as "E-Contract Intended", this e-mail does
not constitute a contract offer, a contract amendment, or an acceptance
of a contract offer. This e-mail does not constitute a consent to the
use of sender's contact information for direct marketing purposes or for
transfers of data to third parties.
Francais Deutsch Italiano Espanol Portugues Japanese Chinese Korean
http://www.DuPont.com/corp/email_disclaimer.html
More information about the gt-users
mailing list