Skip to content

Instantly share code, notes, and snippets.

@canimus
Forked from vestalisvirginis/dna_functions.py
Last active September 1, 2019 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canimus/356c38798a2ac4790bf66e7c86e94d40 to your computer and use it in GitHub Desktop.
Save canimus/356c38798a2ac4790bf66e7c86e94d40 to your computer and use it in GitHub Desktop.
dna manipulation functions
from functional import seq # PyFunctional
from itertools import product
def all_kmers(k):
'''return list of all dna carthesien products of length k'''
all = list(product('ACGT', repeat=k))
return seq(all).map(lambda x: ''.join(x)).to_list()
def kmer_per_segment(dna_segment, k):
'''return all the dna substrings of length k of the different dna strings in dna list'''
return [dna_segment[i:i+k] for i in range(len(dna_segment)-(k-1))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment