Data from: https://madnight.github.io/githut/#/pull_requests/2022/1
Data from: https://pypl.github.io/PYPL.html
Create dictionaries with {}, lists with []
nucs = {'A': 5, 'C': 4, 'T': 8}
counts = [5,4,8]
Both accessed with [] - dictionaries by key, lists by index
nucs['A'] # 5
counts[0] # 5
nucs['A'] = 3 # now 3
counts[0] = 3 # now 3
# Test c1 for True or False
if c1:
print("c1 was True")
# c1 was False, check c2
elif c2:
print("c1 False but c2 True")
# All checks False
else:
print("Both False")
bases = 'adenine cytosine guanine thymine' Write some code that:
Hint: Use help(str) and help(list) to see what functions are available for strings and lists
Bonus: Write a for loop to print the first letter of each (e.g. A, C, ...)
Strings can be reversed with this special slicing notation: [::-1]
s = 'abc'
r = s[::-1]
print(r)
cba
Update reverse() function to use [::-1] instead of a loop.
Do we need to do anything to complement()
?
What about reverse_complement()
?
Calling functions: length = len('abc')
def double(x):
return x * 2
def reverse_complement(seq):
return reverse(complement(seq))
Avoid using global variables in functions
open()
function:
f = open('ae.fa')
strip()
each one
for line in f:
print(line.strip())
f.close()
read_fasta(filename)
that:filename
import sys
print(sys.argv[0])
print(sys.argv[1])
$ python script.py hello
script.py
hello
help()