Parent operations

Note that all arguments to the Parent constructor are optional and any combination of them may be passed. The operations below will fail with an exception if required data is not present.

Instantiate a Parent with a child location and its own parent

This Parent object represents a slice of chr1 (positions 1000-2000). It specifies a child location within the slice, whose coordinates relative to the slice are positions 70-80. It also specifies its own parent, the complete chr1, relative to which it specifies coordinates 1000-2000.

[ ]:
from inscripta.biocantor.location.location_impl import SingleInterval, Strand
from inscripta.biocantor.parent import Parent


parent = Parent(id="chr1_1000_2000",
                sequence_type="chromosome_slice",
                location=SingleInterval(70, 80, Strand.PLUS),
                parent=Parent(id="chr1",
                              sequence_type="chromosome",
                              location=SingleInterval(1000, 2000, Strand.PLUS)))

Simple attributes

ID

[ ]:
parent.id
'chr1_1000_2000'

Sequence

[ ]:
parent.sequence is None
True

Sequence type

[ ]:
parent.sequence_type
'chromosome_slice'

Child location relative to this parent

[ ]:
parent.location
<SingleInterval 70-80:+>

Child strand relative to this parent

[ ]:
parent.strand
<Strand.PLUS: 1>

Parent of this parent

[ ]:
parent.parent
<Parent: id=chr1, type=chromosome, strand=+, location=<SingleInterval 1000-2000:+>, sequence=None, parent=None>

Operations with other Parent objects in a hierarchy

Compare with another Parent, ignoring child location

[ ]:
other_parent_1 = Parent(id="chr1_1000_2000",
                        sequence_type="chromosome_slice",
                        location=SingleInterval(120, 130, Strand.PLUS),
                        parent=Parent(id="chr1",
                                      sequence_type="chromosome",
                                      location=SingleInterval(1000, 2000, Strand.PLUS)))

parent.equals_except_location(other_parent_1)
True
[ ]:
other_parent_2 = Parent(id="chr1_3000_4000",
                        sequence_type="chromosome_slice",
                        location=SingleInterval(70, 80, Strand.PLUS),
                        parent=Parent(id="chr1",
                                      sequence_type="chromosome",
                                      location=SingleInterval(3000, 4000, Strand.PLUS)))

parent.equals_except_location(other_parent_2)
False

Retrieve nearest ancestor Parent of a given sequence type

[ ]:
parent.first_ancestor_of_type("chromosome")
<Parent: id=chr1, type=chromosome, strand=+, location=<SingleInterval 1000-2000:+>, sequence=None, parent=None>
[ ]:
parent.has_ancestor_of_type("other_seq_type")
False

Operations on child location

Lift over child location to the parent of this parent

Lift the child location relative to this chromosome slice up to the parent of this parent (the full chromosome)

[ ]:
parent.lift_child_location_to_parent()
<SingleInterval <Parent: id=chr1, type=chromosome, strand=+, location=<SingleInterval 1070-1080:+>, sequence=None, parent=None>:1070-1080:+>

Reset or remove child location

Useful for reusing the same Parent object for multiple children with different relative locations

[ ]:
parent.reset_location(SingleInterval(50, 60, Strand.MINUS))
<Parent: id=chr1_1000_2000, type=chromosome_slice, strand=-, location=<SingleInterval 50-60:->, sequence=None, parent=<Parent: id=chr1, type=chromosome, strand=+, location=<SingleInterval 1000-2000:+>, sequence=None, parent=None>>
[ ]:
parent.strip_location_info()
<Parent: id=chr1_1000_2000, type=chromosome_slice, strand=None, location=None, sequence=None, parent=<Parent: id=chr1, type=chromosome, strand=+, location=<SingleInterval 1000-2000:+>, sequence=None, parent=None>>
[ ]: