How to use seq2str method in Robotframework

Best Python code snippet using robotframework

Run Robotframework automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

digits.py

Source: digits.py Github

copy
1#!/usr/bin/env python
2"""
3Solution to Project Euler Problem
4http://projecteuler.net/
5
6by Apalala <[email protected]>
7(cc) Attribution-ShareAlike
8http://creativecommons.org/licenses/by-sa/3.0/
9
10Dealing with digits.
11"""
12from memoization import memoize
13
14
15def seq2str(q):
16    return "".join(str(c) for c in q)
17
18
19def sdigits(n):
20    return (c for c in str(n))
21
22
23def digits(n):
24    return (int(c) for c in str(n))
25
26
27def sorted_digits(n):
28    return tuple(sorted(digits(n)))
29
30
31def last_k_digits(k, n):
32    return n % (10 ** k)
33
34
35@memoize
36def digits_upto(k, i=0):
37    return seq2str(range(i, min(k + 1, 10)))
38
39
40def digits_downfrom(k, i=0):
41    return seq2str(range(min(k + 1, 10), i, -1))
42
43
44def sorted_digits_str(n):
45    return seq2str(sorted(str(n)))
46
47
48def is_semi_pandigital(n):
49    s = str(n)
50    return "0" not in s and len(s) == len(set(s))
51
52
53def is_pandigital(n):
54    d = str(n)
55    return sorted(d) == list(digits_upto(len(d), 1))
56
57
58def digit_rotations(n):
59    d = str(n)
60    for i in range(len(d)):
61        yield int(d[i:] + d[:i])
62
Full Screen

distance.py

Source: distance.py Github

copy
1
2"""
3Distance module
4
5Find distance between sequences
6
7Written by Marshall Beddoe <[email protected]>
8Copyright (c) 2004 Baseline Research
9
10Licensed under the LGPL
11"""
12
13#
14# Note: Gaps are denoted by the integer value 256 as to avoid '_' problems
15#
16
17import align, zlib
18from Numeric import *
19
20__all__ = [ "Distance", "Entropic", "PairwiseIdentity", "LocalAlignment" ]
21
22class Distance:
23
24    """Implementation of classify base class"""
25
26    def __init__(self, sequences):
27        self.sequences = sequences
28        self.N = len(sequences)
29
30        # NxN Distance matrix
31        self.dmx = zeros((self.N, self.N), Float)
32
33        for i in range(len(sequences)):
34            for j in range(len(sequences)):
35                self.dmx[i][j] = -1
36
37        self._go()
38
39    def __repr__(self):
40        return "%s" % self.dmx
41
42    def __getitem__(self, i):
43        return self.dmx[i]
44
45    def __len__(self):
46        return len(self.dmx)
47
48    def _go(self):
49        """Perform distance calculations"""
50        pass
51
52class Entropic(Distance):
53
54    """Distance calculation based off compression ratios"""
55
56    def _go(self):
57
58        # Similarity matrix
59        similar = zeros((self.N, self.N), Float)
60
61        for i in range(self.N):
62            for j in range(self.N):
63                similar[i][j] = -1
64
65        #
66        # Do compression ratio calculations
67        #
68        for i in range(self.N):
69            for j in range(self.N):
70
71                if similar[i][j] >= 0:
72                    continue
73
74                seq1 = self.sequences[i][1]
75                seq2 = self.sequences[j][1]
76
77                # Convert sequences to strings, gaps denoted by '_'
78                seq1str = ""
79                for x in seq1:
80                    if x == 256:
81                        seq1str += '_'
82                    else:
83                        seq1str += chr(x)
84
85                seq2str = ""
86                for x in seq2:
87                    if x == 256:
88                        seq2str += '_'
89                    else:
90                        seq2str += chr(x)
91
92                comp1 = zlib.compress(seq1str)
93                comp2 = zlib.compress(seq2str)
94
95                if len(comp1) > len(comp2):
96                    score = len(comp2) * 1.0 / len(comp1) * 1.0
97                else:
98                    score = len(comp1) * 1.0 / len(comp2) * 1.0
99
100                similar[i][j] = similar[j][i] = score
101
102        #
103        # Distance matrix
104        #
105        for i in range(self.N):
106            for j in range(self.N):
107                self.dmx[i][j] = similar[i][i] - similar[i][j]
108
109
110class PairwiseIdentity(Distance):
111
112    """Distance through basic pairwise similarity"""
113
114    def _go(self):
115
116        # Similarity matrix
117        similar = zeros((self.N, self.N), Float)
118
119        for i in range(self.N):
120            for j in range(self.N):
121                similar[i][j] = -1
122
123        #
124        # Find pairs
125        #
126        for i in range(self.N):
127            for j in range(self.N):
128
129                if similar[i][j] >= 0:
130                    continue
131
132                seq1 = self.sequences[i][1]
133                seq2 = self.sequences[j][1]
134
135                minlen = min(len(seq1), len(seq2))
136
137                len1 = len2 = idents = 0
138
139                for x in range(minlen):
140                    if seq1[x] != 256:
141                        len1 += 1.0
142
143                        if seq1[x] == seq2[x]:
144                            idents += 1.0
145
146                    if seq2[x] != 256:
147                        len2 += 1.0
148
149                m = max(len1, len2)
150
151                similar[i][j] = idents / m
152
153        #
154        # Distance matrix
155        #
156        for i in range(self.N):
157            for j in range(self.N):
158                self.dmx[i][j] = similar[i][i] - similar[i][j]
159
160class LocalAlignment(Distance):
161
162    """Distance through local alignment similarity"""
163
164    def __init__(self, sequences, smx=None):
165        self.smx = smx
166
167        # If similarity matrix is None, make a quick identity matrix
168        if self.smx == None:
169
170            self.smx = zeros((257, 257), Float)
171
172            for i in range(257):
173                for j in range(257):
174                    if i == j:
175                        self.smx[i][j] = 1.0
176                    else:
177                        self.smx[i][j] = 0.0
178
179        Distance.__init__(self, sequences)
180
181    def _go(self):
182
183        # Similarity matrix
184        similar = zeros((self.N, self.N), Float)
185
186        for i in range(self.N):
187            for j in range(self.N):
188                similar[i][j] = -1
189
190        #
191        # Compute similarity matrix of SW scores
192        #
193        for i in range(self.N):
194            for j in range(self.N):
195
196                if similar[i][j] >= 0:
197                    continue
198
199                seq1 = self.sequences[i][1]
200                seq2 = self.sequences[j][1]
201
202                (nseq1, nseq2, edits1, edits2, score, gaps) = \
203                    align.SmithWaterman(seq1, seq2, self.smx, 0, 0)
204
205                similar[i][j] = similar[j][i] = score
206
207        #
208        # Compute distance matrix of SW scores
209        #
210        for i in range(self.N):
211            for j in range(self.N):
212
213                if self.dmx[i][j] >= 0:
214                    continue
215
216                self.dmx[i][j] = 1 - (similar[i][j] / similar[i][i])
217                self.dmx[j][i] = self.dmx[i][j]
218
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Robotframework on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)