Created
December 15, 2013 08:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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