Beispiel #1
0
    def _get_template_sequence_in_target_range(self, alignment, target_range):
        """
        For the given target sequence range, this function returns the
        corresponding sequence of the template, according to the given alignment.
        """

        target_start = 0
        while not is_amino_acid_char(alignment.target_alignment[target_start]):
            target_start += 1

        start = target_start
        n_aa = 0
        while n_aa < target_range.start and start < len(
                alignment.target_alignment):
            if is_amino_acid_char(alignment.target_alignment[start]):
                n_aa += 1
            start += 1

        end = start
        n_aa = 0
        while n_aa < target_range.get_length() and end < len(
                alignment.target_alignment):
            if is_amino_acid_char(alignment.target_alignment[end]):
                n_aa += 1
            end += 1

        return alignment.template_alignment[start:end]
Beispiel #2
0
 def count_aligned_residues(self, id1, id2):
     nalign = 0
     for i in range(len(self.aligned_sequences[id1])):
         if is_amino_acid_char(self.aligned_sequences[id1][i]) and \
                 is_amino_acid_char(self.aligned_sequences[id2][i]):
             nalign += 1
     return nalign
Beispiel #3
0
    def _get_template_sequence_in_target_range(self, alignment, target_range):

        """
        For the given target sequence range, this function returns the
        corresponding sequence of the template, according to the given alignment.
        """

        target_start = 0
        while not is_amino_acid_char(alignment.target_alignment[target_start]):
            target_start += 1

        start = target_start
        n_aa = 0
        while n_aa < target_range.start and start < len(alignment.target_alignment):
            if is_amino_acid_char(alignment.target_alignment[start]):
                n_aa += 1
            start += 1

        end = start
        n_aa = 0
        while n_aa < target_range.get_length() and end < len(alignment.target_alignment):
            if is_amino_acid_char(alignment.target_alignment[end]):
                n_aa += 1
            end += 1

        return alignment.template_alignment[start: end]
Beispiel #4
0
    def _merge_alignments(self, alignment1, alignment2):
        span1 = alignment1.get_relative_span()
        span2 = alignment2.get_relative_span()

        # make sure span1 is the N-sided:
        if span2 < span1:
            span1, span2 = swap(span1, span2)
            alignment1, alignment2 = swap(alignment1, alignment2)

        # Determine alignment positions of span1 and span2:
        i1 = 0
        naa = 0
        while naa < span1.end:
            if is_amino_acid_char(alignment1.template_alignment[i1]):
                naa += 1
            i1 += 1

        i2 = 0
        naa = 0
        while naa < span2.start:
            if is_amino_acid_char(alignment2.template_alignment[i2]):
                naa += 1
            i2 += 1

        return TargetTemplateAlignment(alignment1.target_alignment[: i1] + alignment2.target_alignment[i2: ],
                                       alignment1.template_alignment[: i1] + alignment2.template_alignment[i2: ])
Beispiel #5
0
 def count_aligned_residues(self, id1, id2):
     nalign = 0
     for i in range(len(self.aligned_sequences[id1])):
         if is_amino_acid_char(self.aligned_sequences[id1][i]) and \
                 is_amino_acid_char(self.aligned_sequences[id2][i]):
             nalign += 1
     return nalign
Beispiel #6
0
    def _merge_alignments(self, alignment1, alignment2):
        span1 = alignment1.get_relative_span()
        span2 = alignment2.get_relative_span()

        # make sure span1 is the N-sided:
        if span2 < span1:
            span1, span2 = swap(span1, span2)
            alignment1, alignment2 = swap(alignment1, alignment2)

        # Determine alignment positions of span1 and span2:
        i1 = 0
        naa = 0
        while naa < span1.end:
            if is_amino_acid_char(alignment1.template_alignment[i1]):
                naa += 1
            i1 += 1

        i2 = 0
        naa = 0
        while naa < span2.start:
            if is_amino_acid_char(alignment2.template_alignment[i2]):
                naa += 1
            i2 += 1

        return TargetTemplateAlignment(alignment1.target_alignment[: i1] + alignment2.target_alignment[i2: ],
                                       alignment1.template_alignment[: i1] + alignment2.template_alignment[i2: ])
Beispiel #7
0
 def get_covered_template_residues_indices(self):
     n = 0
     covered = []
     for i in range(len(self.aligned_sequences['target'])):
         if is_amino_acid_char(self.aligned_sequences['template'][i]):
             if is_amino_acid_char(self.aligned_sequences['target'][i]):
                 covered.append(n)
             n += 1
     return covered
Beispiel #8
0
 def get_percentage_coverage(self):
     nalign = 0
     ntar = 0
     for i in range(len(self.aligned_sequences['target'])):
         if is_amino_acid_char(self.aligned_sequences['target'][i]):
             ntar += 1
             if is_amino_acid_char(self.aligned_sequences['template'][i]):
                 nalign += 1
     return (100.0 * nalign) / ntar
Beispiel #9
0
 def get_percentage_coverage(self):
     nalign = 0
     nq = 0
     for i in range(len(self.aligned_sequences['query'])):
         if is_amino_acid_char(self.aligned_sequences['query'][i]):
             nq += 1
             if is_amino_acid_char(self.aligned_sequences['subject'][i]):
                 nalign += 1
     return (100.0 * nalign) / nq
Beispiel #10
0
 def get_covered_template_residues_indices(self):
     n = 0
     covered = []
     for i in range(len(self.aligned_sequences['target'])):
         if is_amino_acid_char(self.aligned_sequences['template'][i]):
             if is_amino_acid_char(self.aligned_sequences['target'][i]):
                 covered.append(n)
             n += 1
     return covered
Beispiel #11
0
 def get_percentage_coverage(self):
     nalign = 0
     ntar = 0
     for i in range(len(self.aligned_sequences['target'])):
         if is_amino_acid_char(self.aligned_sequences['target'][i]):
             ntar += 1
             if is_amino_acid_char(self.aligned_sequences['template'][i]):
                 nalign += 1
     return (100.0 * nalign) / ntar
Beispiel #12
0
 def get_percentage_coverage(self):
     nalign = 0
     nq = 0
     for i in range(len(self.aligned_sequences['query'])):
         if is_amino_acid_char(self.aligned_sequences['query'][i]):
             nq += 1
             if is_amino_acid_char(self.aligned_sequences['subject'][i]):
                 nalign += 1
     return (100.0 * nalign) / nq
Beispiel #13
0
    def is_target_residue_covered(self, residue_number):
        n = 1
        for i in range(len(self.aligned_sequences['target'])):
            if is_amino_acid_char(self.aligned_sequences['target'][i]):
                if n == residue_number and \
                        is_amino_acid_char(self.aligned_sequences['template'][i]):
                    return True
                n += 1

        return False
Beispiel #14
0
    def is_target_residue_covered(self, residue_number):
        n = 1
        for i in range(len(self.aligned_sequences['target'])):
            if is_amino_acid_char(self.aligned_sequences['target'][i]):
                if n == residue_number and \
                        is_amino_acid_char(self.aligned_sequences['template'][i]):
                    return True
                n += 1

        return False
Beispiel #15
0
    def is_query_residue_covered(self, residue_number):
        n = self.query_start

        for i in range(len(self.aligned_sequences['query'])):
            if is_amino_acid_char(self.aligned_sequences['query'][i]):
                if n == residue_number and \
                        is_amino_acid_char(self.aligned_sequences['subject'][i]):
                    return True
                n += 1

        return False
Beispiel #16
0
    def is_query_residue_covered(self, residue_number):
        n = self.query_start

        for i in range(len(self.aligned_sequences['query'])):
            if is_amino_acid_char(self.aligned_sequences['query'][i]):
                if n == residue_number and \
                        is_amino_acid_char(self.aligned_sequences['subject'][i]):
                    return True
                n += 1

        return False
Beispiel #17
0
 def get_percentage_identity(self, id1, id2):
     nalign = 0
     nid = 0
     for i in range(len(self.aligned_sequences[id1])):
         if is_amino_acid_char(self.aligned_sequences[id1][i]) and \
                 is_amino_acid_char(self.aligned_sequences[id2][i]):
             nalign += 1
             if self.aligned_sequences[id1][i] == self.aligned_sequences[id2][i]:
                 nid += 1
     if nalign > 0:
         return (100.0 * nid) / nalign
     else:
         return 0.0
Beispiel #18
0
 def get_percentage_identity(self, id1, id2):
     nalign = 0
     nid = 0
     for i in range(len(self.aligned_sequences[id1])):
         if is_amino_acid_char(self.aligned_sequences[id1][i]) and \
                 is_amino_acid_char(self.aligned_sequences[id2][i]):
             nalign += 1
             if self.aligned_sequences[id1][i] == self.aligned_sequences[
                     id2][i]:
                 nid += 1
     if nalign > 0:
         return (100.0 * nid) / nalign
     else:
         return 0.0
Beispiel #19
0
    def get_relative_span(self):
        """
        Tells the starting position of 'target' relative to
        the starting position of 'template'.
        """

        i = 0 
        while not is_amino_acid_char(self.target_alignment[i]):
            i += 1

        start = len(self.template_alignment[:i].replace('-', ''))

        i = len(self.target_alignment)
        while not is_amino_acid_char(self.target_alignment[i - 1]):
            i -= 1

        end = len(self.template_alignment[:i].replace('-', ''))

        return SequenceRange(start, end, self.get_template_sequence())
Beispiel #20
0
    def get_relative_span(self):
        """
        Tells the starting position of 'target' relative to
        the starting position of 'template'.
        """

        i = 0
        while not is_amino_acid_char(self.target_alignment[i]):
            i += 1

        start = len(self.template_alignment[:i].replace('-', ''))

        i = len(self.target_alignment)
        while not is_amino_acid_char(self.target_alignment[i - 1]):
            i -= 1

        end = len(self.template_alignment[:i].replace('-', ''))

        return SequenceRange(start, end, self.get_template_sequence())