Created
January 2, 2013 03:50
-
-
Save jdan/4431980 to your computer and use it in GitHub Desktop.
Solutions to the first 6 ROSALIND (http://rosalind.info) problems in Python
This file contains hidden or 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
# 1 Jan 2013 | |
if __name__ == '__main__': | |
s = raw_input() | |
# f(char) counts the instances of `char` in `s` | |
f = lambda c: len(filter(lambda i: i == c, s)) | |
print ' '.join(map(str, [f('A'), f('C'), f('G'), f('T')])) |
This file contains hidden or 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
# 1 Jan 2013 | |
if __name__ == '__main__': | |
s = raw_input() | |
print s.replace('T', 'U') |
This file contains hidden or 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
# 1 Jan 2013 | |
if __name__ == '__main__': | |
s = raw_input() | |
c = lambda i: {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}[i] | |
s = map(c, s) | |
s.reverse() | |
print ''.join(s) |
This file contains hidden or 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
# 1 Jan 2013 | |
if __name__ == '__main__': | |
gc = lambda s: float(len(filter(lambda c: c == 'G' or c == 'C', s))) / len(s) | |
data = [] | |
name = '' | |
strand = '' | |
while True: | |
try: | |
line = raw_input() | |
if line[0] == '>': | |
if len(name): data.append([strand, name]) | |
name = line[1:] | |
strand = '' | |
else: | |
strand += line | |
except EOFError: | |
if len(name): data.append([strand, name]) | |
break | |
data = map(lambda e: [gc(e[0]), e[1]], data) | |
data.sort() | |
data.reverse() | |
print data[0][1] | |
print str(data[0][0] * 100) + '%' |
This file contains hidden or 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
# 1 Jan 2013 | |
if __name__ == '__main__': | |
a = raw_input() | |
b = raw_input() | |
print len([1 for i in range(len(a)) if a[i] != b[i]]) |
This file contains hidden or 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
# 1 Jan 2013 | |
if __name__ == '__main__': | |
strand = raw_input() | |
seq = raw_input() | |
print ' '.join([str(i+1) for i in range(len(strand)) if strand[i:i+len(seq)] == seq]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment