Code Duplication    Length = 38-38 lines in 2 locations

abydos/distance/_smith_waterman.py 1 location

@@ 50-87 (lines=38) @@
47
    alignment and disallows negative scores.
48
    """
49
50
    def dist_abs(self, src, tar, gap_cost=1, sim_func=sim_ident):
51
        """Return the Smith-Waterman score of two strings.
52
53
        Parameters
54
        ----------
55
        src : str
56
            Source string for comparison
57
        tar : str
58
            Target string for comparison
59
        gap_cost : float
60
            The cost of an alignment gap (1 by default)
61
        sim_func : function
62
            A function that returns the similarity of two characters (identity
63
            similarity by default)
64
65
        Returns
66
        -------
67
        float
68
            Smith-Waterman score
69
70
        Examples
71
        --------
72
        >>> cmp = SmithWaterman()
73
        >>> cmp.dist_abs('cat', 'hat')
74
        2.0
75
        >>> cmp.dist_abs('Niall', 'Neil')
76
        1.0
77
        >>> cmp.dist_abs('aluminum', 'Catalan')
78
        0.0
79
        >>> cmp.dist_abs('ATCG', 'TAGC')
80
        1.0
81
82
        """
83
        d_mat = np_zeros((len(src) + 1, len(tar) + 1), dtype=np_float32)
84
85
        for i in range(len(src) + 1):
86
            d_mat[i, 0] = 0
87
        for j in range(len(tar) + 1):
88
            d_mat[0, j] = 0
89
        for i in range(1, len(src) + 1):
90
            for j in range(1, len(tar) + 1):

abydos/distance/_needleman_wunsch.py 1 location

@@ 129-166 (lines=38) @@
126
            return mat[(tar, src)]
127
        return mismatch_cost
128
129
    def dist_abs(self, src, tar, gap_cost=1, sim_func=sim_ident):
130
        """Return the Needleman-Wunsch score of two strings.
131
132
        Parameters
133
        ----------
134
        src : str
135
            Source string for comparison
136
        tar : str
137
            Target string for comparison
138
        gap_cost : float
139
            The cost of an alignment gap (1 by default)
140
        sim_func : function
141
            A function that returns the similarity of two characters (identity
142
            similarity by default)
143
144
        Returns
145
        -------
146
        float
147
            Needleman-Wunsch score
148
149
        Examples
150
        --------
151
        >>> cmp = NeedlemanWunsch()
152
        >>> cmp.dist_abs('cat', 'hat')
153
        2.0
154
        >>> cmp.dist_abs('Niall', 'Neil')
155
        1.0
156
        >>> cmp.dist_abs('aluminum', 'Catalan')
157
        -1.0
158
        >>> cmp.dist_abs('ATCG', 'TAGC')
159
        0.0
160
161
        """
162
        d_mat = np_zeros((len(src) + 1, len(tar) + 1), dtype=np_float32)
163
164
        for i in range(len(src) + 1):
165
            d_mat[i, 0] = -(i * gap_cost)
166
        for j in range(len(tar) + 1):
167
            d_mat[0, j] = -(j * gap_cost)
168
        for i in range(1, len(src) + 1):
169
            for j in range(1, len(tar) + 1):