| 45 | super(Uniprot21, self).__init__(chars, encoding=encoding) |
| 46 | |
| 47 | class decoder_set: |
| 48 | def __iter__(self): |
| 49 | return iter(self.x) |
| 50 | def __init__(self, path='generate_data/protein/generate1.txt', alphabet=Uniprot21()): |
| 51 | print('# loading array:', path, file=sys.stderr) |
| 52 | |
| 53 | sequences = self.load(path, alphabet) |
| 54 | # seq_data = [] |
| 55 | # for i in range(len(sequences)): |
| 56 | # x =alphabet.decode(sequences[i].astype('uint8')) |
| 57 | # seq_data.append(x.decode()) |
| 58 | # self.x = seq_data |
| 59 | self.x = [[alphabet.decode(seq.astype('uint8')).decode() for seq in sublist] for sublist in sequences] |
| 60 | print('# decode', len(self.x), 'sequences', file=sys.stderr) |
| 61 | |
| 62 | def load(self, path, alphabet): |
| 63 | data = np.loadtxt(path) |
| 64 | data = data - np.ones(data.shape) |
| 65 | # sequence = [] |
| 66 | # star = 0 |
| 67 | # for i in range(data.shape[0]): |
| 68 | # where_zero = np.where(data[i] == -1) |
| 69 | # for j in range(np.size(where_zero)): |
| 70 | # end = where_zero[0][j] |
| 71 | # # sequence length fillter |
| 72 | # if end - star > 1: |
| 73 | # sequence[i].append(data[i][star:end]) |
| 74 | # star = where_zero[0][j] + 1 |
| 75 | |
| 76 | sequence = [[] for _ in range(data.shape[0])] |
| 77 | for i in range(data.shape[0]): |
| 78 | star = 0 |
| 79 | where_zero = np.where(data[i] == -1)[0] |
| 80 | for j in range(len(where_zero)): |
| 81 | end = where_zero[j] |
| 82 | # sequence length filter |
| 83 | if end - star > 1: |
| 84 | sequence[i].append(data[i][star:end]) |
| 85 | star = end + 1 |
| 86 | # Check for a sequence after the last -1 |
| 87 | if data.shape[1] - star > 1: |
| 88 | sequence[i].append(data[i][star:]) |
| 89 | |
| 90 | return sequence |
| 91 | |
| 92 | def len_select(data): |
| 93 | min_length = 10 |