Esempio n. 1
0
    def _swap_query_and_sbjct(self):
        """
        USE WITH CARE!!!
        Swap query and sbjct sequences and positions.
        This enables easier comparison in some cases.
        It is done WITHIN THIS INITIALIZED object.
        That is what I mean with use with care.
        Recommended usage is only with the helper function
            ``swap_query_and_sbjct``
        Usage:
            ``swapped_pacb = swap_query_and_sbjct(pacb)``
        """
        # first swap the data from the basal PacbP clas
        PacbP._swap_query_and_sbjct(self)

        # swap strings and orf objects
        self.query_dna, self.sbjct_dna = self.sbjct_dna, self.query_dna

        # swap coordinates
        (a,b,c) = (self.query_dna_start, self.query_dna_end, self.query_dna_length)
        (d,e,f) = (self.sbjct_dna_start, self.sbjct_dna_end, self.sbjct_dna_length)
        (self.query_dna_start, self.query_dna_end, self.query_dna_length) = (d,e,f)
        (self.sbjct_dna_start, self.sbjct_dna_end, self.sbjct_dna_length) = (a,b,c)

        # and swap the alignment on all positions
        for adp_pos in self._positions:
            adp_pos._swap_query_and_sbjct()
Esempio n. 2
0
    def _strip_one_left_position(self):
        """
        """
        # no truncation possible -> PacbP does not exist anymore
        if self.length == 0: raise ZeroSizedPacb

        if self.query[0] != "-":
            self.query_dna          = self.query_dna[3:]
            self.query_dna_start    = self.query_dna_start+3
            self.query_dna_length   = self.query_dna_length-3

        if self.sbjct[0] != "-":
            self.sbjct_dna          = self.sbjct_dna[3:]
            self.sbjct_dna_start    = self.sbjct_dna_start+3
            self.sbjct_dna_length   = self.sbjct_dna_length-3

        # increase `position` counter for all existing positions
        for pos in self._positions: pos.position-=1

        # and pop leading aligned position
        self._positions.pop(0)

        # COMPENSATE self._original_alignment_pos_start and end
        if self._original_alignment_pos_start > 0: 
            self._original_alignment_pos_start-=1
            self._original_alignment_pos_end-=1
        elif self._original_alignment_pos_start==0:
            self._original_alignment_pos_end-=1
        else:
            raise "WHATEVER; coords for original alignment not oke"

        # correct all the protein coordinates and strings
        PacbP._strip_one_left_position(self)
Esempio n. 3
0
    def _strip_one_rigth_position(self):
        """
        """
        # no truncation possible -> PacbP does not exist anymore
        if self.length == 0: raise ZeroSizedPacb

        if self.query[-1] != "-":
            self.query_dna          = self.query_dna[0:-3]
            self.query_dna_end      = self.query_dna_end-3
            self.query_dna_length   = self.query_dna_length-3

        if self.sbjct[-1] != "-":
            self.sbjct_dna          = self.sbjct_dna[0:-3]
            self.sbjct_dna_end      = self.sbjct_dna_end-3
            self.sbjct_dna_length   = self.sbjct_dna_length-3

        # COMPENSATE self._original_alignment_pos_end
        if len(self._positions) == self._original_alignment_pos_end:
            self._original_alignment_pos_end-=1
        elif len(self._positions) > self._original_alignment_pos_end:
            pass
        else:
            raise "WHATEVER; coords for original alignment not oke"

        # and pop trailing aligned position
        self._positions.pop()

        # correct all the protein coordinates and strings
        PacbP._strip_one_rigth_position(self)
Esempio n. 4
0
    def _swap_query_and_sbjct(self):
        """
        USE WITH CARE!!!
        Swap query and sbjct sequences and positions.
        This enables easier comparison in some cases.
        It is done WITHIN THIS INITIALIZED object.
        That is what I mean with use with care.
        Recommended usage is only with the helper function
            ``swap_query_and_sbjct``
        Usage:
            ``swapped_pacb = swap_query_and_sbjct(pacb)``
        """
        # first swap the data from the basal PacbP clas
        PacbP._swap_query_and_sbjct(self)

        # swap strings and orf objects
        self.query_dna, self.sbjct_dna = self.sbjct_dna, self.query_dna

        # swap coordinates
        (a, b, c) = (self.query_dna_start, self.query_dna_end,
                     self.query_dna_length)
        (d, e, f) = (self.sbjct_dna_start, self.sbjct_dna_end,
                     self.sbjct_dna_length)
        (self.query_dna_start, self.query_dna_end,
         self.query_dna_length) = (d, e, f)
        (self.sbjct_dna_start, self.sbjct_dna_end,
         self.sbjct_dna_length) = (a, b, c)

        # and swap the alignment on all positions
        for adp_pos in self._positions:
            adp_pos._swap_query_and_sbjct()
Esempio n. 5
0
    def _strip_one_rigth_position(self):
        """
        """
        # no truncation possible -> PacbP does not exist anymore
        if self.length == 0: raise ZeroSizedPacb

        if self.query[-1] != "-":
            self.query_dna = self.query_dna[0:-3]
            self.query_dna_end = self.query_dna_end - 3
            self.query_dna_length = self.query_dna_length - 3

        if self.sbjct[-1] != "-":
            self.sbjct_dna = self.sbjct_dna[0:-3]
            self.sbjct_dna_end = self.sbjct_dna_end - 3
            self.sbjct_dna_length = self.sbjct_dna_length - 3

        # COMPENSATE self._original_alignment_pos_end
        if len(self._positions) == self._original_alignment_pos_end:
            self._original_alignment_pos_end -= 1
        elif len(self._positions) > self._original_alignment_pos_end:
            pass
        else:
            raise "WHATEVER; coords for original alignment not oke"

        # and pop trailing aligned position
        self._positions.pop()

        # correct all the protein coordinates and strings
        PacbP._strip_one_rigth_position(self)
Esempio n. 6
0
    def _strip_one_left_position(self):
        """
        """
        # no truncation possible -> PacbP does not exist anymore
        if self.length == 0: raise ZeroSizedPacb

        if self.query[0] != "-":
            self.query_dna = self.query_dna[3:]
            self.query_dna_start = self.query_dna_start + 3
            self.query_dna_length = self.query_dna_length - 3

        if self.sbjct[0] != "-":
            self.sbjct_dna = self.sbjct_dna[3:]
            self.sbjct_dna_start = self.sbjct_dna_start + 3
            self.sbjct_dna_length = self.sbjct_dna_length - 3

        # increase `position` counter for all existing positions
        for pos in self._positions:
            pos.position -= 1

        # and pop leading aligned position
        self._positions.pop(0)

        # COMPENSATE self._original_alignment_pos_start and end
        if self._original_alignment_pos_start > 0:
            self._original_alignment_pos_start -= 1
            self._original_alignment_pos_end -= 1
        elif self._original_alignment_pos_start == 0:
            self._original_alignment_pos_end -= 1
        else:
            raise "WHATEVER; coords for original alignment not oke"

        # correct all the protein coordinates and strings
        PacbP._strip_one_left_position(self)
Esempio n. 7
0
 def __init__(self,
              input=("", "", 0, 0),
              blastp_hsp=None,
              MATRIX=None,
              gff={}):
     """ """
     PacbP.__init__(self,
                    input=input,
                    blastp_hsp=blastp_hsp,
                    MATRIX=MATRIX,
                    gff=gff)
Esempio n. 8
0
    def __init__(self,
                 input=("", "", 0, 0),
                 blastp_hsp=None,
                 MATRIX={},
                 pacbp=None,
                 input_dna=("", "", 0, 0)):
        """
        """
        # first, get to the point of an instantiated PacbP object
        if str(pacbp.__class__) in ['pacb.PacbP', 'pacb.pacbp.PacbP']:
            # loop over all attributes, and copy all true attributes
            # skip the `__`-starting attributes and the `instancemethods`
            for attr in dir(pacbp):
                if attr[0:2] == "__": continue
                if str(type(getattr(pacbp,
                                    attr))) != "<type 'instancemethod'>":
                    # copy this attribute from PacbP to PacbPDNA
                    setattr(self, attr, getattr(pacbp, attr))
            # and move the original hsp object
            self._hsp = pacbp._hsp
            # check if a non-default matrix was applied
            if MATRIX:
                self.MATRIX = MATRIX
        else:
            # call the __init__ function of the basal PacbP class
            if MATRIX:
                PacbP.__init__(self,
                               input=input,
                               blastp_hsp=blastp_hsp,
                               MATRIX=MATRIX)
            else:
                PacbP.__init__(self, input=input, blastp_hsp=blastp_hsp)

        # set the PacbPDNA specific attributes
        self.query_dna = ""
        self.query_dna_start = 0
        self.query_dna_end = 0
        self.query_dna_length = 0
        self.sbjct_dna = ""
        self.sbjct_dna_start = 0
        self.sbjct_dna_end = 0
        self.sbjct_dna_length = 0
        self._positions = []
        # and finish initialization
        self._initialize(input_dna)
        self._alignment2positions()
        # set start and end positions of the original alignment
        # this is needed to calculate the `entropy` of a position
        # in the alignment
        self._original_alignment_pos_start = 0
        self._original_alignment_pos_end = len(self._positions)
Esempio n. 9
0
    def __init__(self,input=("","",0,0),blastp_hsp=None,MATRIX={},
        pacbp=None,input_dna=("","",0,0)):
        """
        """
        # first, get to the point of an instantiated PacbP object
        if str(pacbp.__class__) in ['pacb.PacbP','pacb.pacbp.PacbP']:
            # loop over all attributes, and copy all true attributes
            # skip the `__`-starting attributes and the `instancemethods`
            for attr in dir(pacbp):
                if attr[0:2] == "__": continue
                if str(type(getattr(pacbp,attr))) != "<type 'instancemethod'>":
                    # copy this attribute from PacbP to PacbPDNA
                    setattr(self,attr,getattr(pacbp,attr))
            # and move the original hsp object
            self._hsp = pacbp._hsp
            # check if a non-default matrix was applied
            if MATRIX:
                self.MATRIX = MATRIX
        else:
            # call the __init__ function of the basal PacbP class
            if MATRIX:
                PacbP.__init__(self,input=input,blastp_hsp=blastp_hsp,MATRIX=MATRIX)
            else:
                PacbP.__init__(self,input=input,blastp_hsp=blastp_hsp)

        # set the PacbPDNA specific attributes
        self.query_dna          = ""
        self.query_dna_start    = 0
        self.query_dna_end      = 0
        self.query_dna_length   = 0
        self.sbjct_dna          = ""
        self.sbjct_dna_start    = 0
        self.sbjct_dna_end      = 0
        self.sbjct_dna_length   = 0
        self._positions         = []
        # and finish initialization
        self._initialize(input_dna)
        self._alignment2positions()
        # set start and end positions of the original alignment
        # this is needed to calculate the `entropy` of a position
        # in the alignment
        self._original_alignment_pos_start = 0
        self._original_alignment_pos_end   = len(self._positions)
Esempio n. 10
0
 def __init__(self,input=("","",0,0),blastp_hsp=None,MATRIX=None,gff={}):
     """ """
     PacbP.__init__(self,input=input,blastp_hsp=blastp_hsp,MATRIX=MATRIX,gff=gff)