Skip to content

Instantly share code, notes, and snippets.

@timrandg
Created December 15, 2013 08:58
Show Gist options
  • Save timrandg/7970562 to your computer and use it in GitHub Desktop.
Save timrandg/7970562 to your computer and use it in GitHub Desktop.
create all mutant sequences with m mutations or fewer from protein or DNA
class Array
def expand(master, mut)
collection = []
each do |str|
c = str.count('.')
case
when c < mut
collection << str + master[str.length]
collection << str + '.'
when c == mut
collection << str + master[str.length]
end
end
collection
end
def mutagenize_frags(master, mut, len=master.length)
var = self.dup
while var.first.length < len do
var = var.send(:expand, *[master, mut])
end
var.sort
end
end
class String
def mutagenize_frags(mut,len=self.length)
[''].mutagenize_frags(self,mut,len)
end
end
puts "ABCDEF".mutagenize_frags(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment