Skip to content

Instantly share code, notes, and snippets.

@jdan
Created January 2, 2013 03:50
Show Gist options
  • Save jdan/4431980 to your computer and use it in GitHub Desktop.
Save jdan/4431980 to your computer and use it in GitHub Desktop.
Solutions to the first 6 ROSALIND (http://rosalind.info) problems in Python
# 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')]))
# 1 Jan 2013
if __name__ == '__main__':
s = raw_input()
print s.replace('T', 'U')
# 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)
# 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) + '%'
# 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]])
# 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