python - easy method for spliting substrings of a given length from a string -
i have 34-mer string like
atggggtttccc...ctg
i want possible 6-mer substrings in string. can suggest way this.
assuming have contiguous, can use slicing in list comprehension
>>> s = 'agtaatggcgattgagggtccactgtcctggtac' >>> [s[i:i+6] in range(len(s)-5)] ['agtaat', 'gtaatg', 'taatgg', 'aatggc', 'atggcg', 'tggcga', 'ggcgat', 'gcgatt', 'cgattg', 'gattga', 'attgag', 'ttgagg', 'tgaggg', 'gagggt', 'agggtc', 'gggtcc', 'ggtcca', 'gtccac', 'tccact', 'ccactg', 'cactgt', 'actgtc', 'ctgtcc', 'tgtcct', 'gtcctg', 'tcctgg', 'cctggt', 'ctggta', 'tggtac']
Comments
Post a Comment