## Shared URLS
- Learn more markdown: [link](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
- Human genome: [link](https://www.ncbi.nlm.nih.gov/projects/genome/guide/human/index.shtml)
- SNPedia: [link](https://www.snpedia.com/index.php/SNPedia)
- Project Jupyter: [link](https://jupyter.org/)
- Interesting Jupyter notebooks: [link](https://github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks)
- Try Linux terminal: [link](https://cocalc.com/doc/terminal.html)
- mybinder.org: [link](https://mybinder.org/)
- Notebooks: https://github.com/JasonJWilliamsNY/biocoding-2022-notebooks
- Zoom link: [TBD](TBD)
- JupyterHub: [TBD](TBD)
---
## Learning more after the class
**Notebooks used in this course**
- Biocoding 2020 Notebooks [link](https://github.com/JasonJWilliamsNY/biocoding-2020-notebooks)
- - You can download these materials: [link](https://github.com/JasonJWilliamsNY/biocoding-2020-notebooks/archive/master.zip)
**General Coding**
- CodeCademy: [link](https://www.codecademy.com/)
- Hour of code (also in languages other than English): [link](https://code.org/learn)
**Software installations**
Be sure you have permission to install software
- Try Ubuntu: [link](https://tutorials.ubuntu.com/tutorial/try-ubuntu-before-you-install#0)
- Python: [link](https://www.python.org/downloads/)
- Jupyter: [link](https://jupyter.org/)
- Wing IDE: [link](https://wingware.com/)
- Atom text editor: [link](https://atom.io/)
**Bioinformatics**
- Learn bioinformatics in 100 hours: [link](https://www.biostarhandbook.com/edu/course/1/)
- Rosalind bioinformatics: [link](http://rosalind.info/about/)
- Bioinformatics coursera: [link](https://www.coursera.org/learn/bioinformatics)
- Bioinformatics careers: [link](https://www.iscb.org/bioinformatics-resources-for-high-schools/careers-in-bioinformatics)
**Help**
- General software help: [link](https://stackoverflow.com/)
- Bioinformatics-specific software help: [link](https://www.biostars.org/)
---
## Account names
lanaod
kwa
chiburns
reichman
velozny
lanaos
wang
### Jupyter
- [Hub address](http://18.207.102.1:8000/hub/login)
### Notebook setup
git clone https://github.com/JasonJWilliamsNY/biocoding-2021-notebooks.git
### DNA Barcoding
- [silica DNA isolation](https://dnabarcoding101.org/lab/protocol-2.html#alternateb)
---
## Shared notes
### Markdown Practice
- My name is Jason. A useful website I like is [Space Weather](https://www.spaceweather.com/)
- hi. [link](youtube.com)
# Ron Velozny:!![logo]
- nice gif
- woah that's cute
- [openworm](https://openworm.org/)
[logo]:https://i.pinimg.com/originals/2e/c5/a5/2ec5a5c021b7d6d9e5bc5051adbb2be1.gif
### G.U.I:
------
+ defenition: graphical user interface
+ i know what gui ive never seen someone say it as a word
## Intro Python Notebook 1
#### Solve for starting volume
starting_volume =
starting_volume = starting_volume = (final_concentration * final_volume)/start_concentration
starting_volume =
starting_volume = (final_concentration * final_volume)/start_concentration
## Intro Python Notebook 2
#### Variable names
**Average weight of a mouse group?**
(avg_mass * number_of_mice)/number_of_mice
avgweight_group
avg_wgt_alpha
alpha_avg
avg_weight_alpha
avgW =
avg_alpha
**Number of mice in a group?**
avgP =
nmbmice_group
mice#nmb_alpha
alpha_pop
numberofmice
number_alpha
num_mice_alpha
#### Challenge In the cell below, print the alpha_id character by character in reverse
```python
for i in range(1,len(alpha_id)+1):
print(alpha_id[-i], end="")
```
print(alpha_id[7],alpha_id[6], alpha_id[5],alpha_id[4], alpha_id[3], alpha_id[2], alpha_id[1], alpha_id[0])
##### Create new variables that contain the initials of the experimenter for each mouse group; print the value of these new variables
alpha_initials=alpha_id[0:3:]
print(initials_alpha)
alpha_letters = (alpha_id[0:3:])
beta_letters = (beta_id[0:3:])
gamma_letters = (gamma_id[0:3:])
print(alpha_letters + beta_letters + gamma_letters)
initials_alpha = alpha_id[0:3]
initials_beta = beta_id[0:3]
initials_gamma = gamma_id[0:3]
alphaIDint = alpha_id[0:3]
betaIDint = beta_id[0:3]
gammaIDint= gamma_id[0:3]
print(alphaIDint,betaIDint,gammaIDint)
#### Create new variables that contain the ID of the experimenter for each mouse group; print the value of these new variables
exp_id_alpha = alpha_id[3:]
exp_id_beta = beta_id[3:]
exp_id_gamma = gamma_id[3:]
alpha_id = (alpha_id[3::])
beta_id = (beta_id[3::])
gamma_id = (gamma_id[3::])
print(alpha_id + beta_id + gamma_id)
#### Fasta Challenge: You should be able to do this in 3 lines of code To make the printed information move to a new line, use the newline character '\n' - used as a string with quotes Python will not print '\n' to the screen, but interpret that you mean to end one line at that location and begin a newline
sequence_name = "This is the name of the sequence."
sequence_string = "ACTAGCAGCATTGGACCATGACTAGTGACTAGCAGCATG"
print(">" + sequence_name + "\n" + sequence_string)
DNAname = "sequence 001"
DNAseaquence = "AAGCTGACGGGGAGCTAGTCTTAGTCGTACGTTCGAT"
fullFASTA = ">"+DNAname+"\n" + DNAseaquence
print(fullFASTA)
seq_name = "sequence 001"
seq = "ATTCGAGGATCGATTTCGATCGATGCTTAGCTTTAGCTTTTTTAGATCTCCCA"
fasta_format = (f">{seq_name}\n{seq}")
print(fasta_format)
sequence_title = 'Sequence Name'
sequence_actual = 'ACTAGTAGCGACTCGACGTACGCACTAGCACTACGCTACGACGACTGCATGC'
print ('>', sequence_title, "\n" , sequence_actual)
### Examining the HIV genome
#### Determine and print the length of the HIV genome
print(len(hiv_genome))
print(len(hiv_genome))
#### Create variables for and print the sequences for the following HIV genes
- gag
- pol
- vif
- vpr
- env
gag = hiv_genome[789:2291]
pol = hiv_genome[2084:5096]
vif = hiv_genome[500:5619]
vpr = hiv_genome[5558:5850]
env = hiv_genome[6044:8794]
print("gag="+hiv_genome[789:2292])
print("pol="+hiv_genome[2084:5096])
print("vif="+hiv_genome[5040:5619])
print("vpr="+hiv_genome[5558:5850])
print("env="+hiv_genome[6224:8795])
gag = hiv_genome[789:2292]
pol = hiv_genome[2084:5096]
vif = hiv_genome[5040:5619]
vpr = hiv_genome[5558:5850]
env = hiv_genome[6224:8795]
gag = hiv_genome[789:2292]
pol = hiv_genome[2084:5096]
vif = hiv_genome[5040:5619]
vpr = hiv_genome[5558:5850]
env = hiv_genome[6224:8795]
#### Generate the RNA sequence for each of the genes you have isolated above
hiv_genome_RNA = hiv_genome.replace('T','U')
print(hiv_genome_RNA)
gag_rna = gag.replace('t','u')
pol_rna = pol.replace('t','u')
vif_rna = vif.replace('t','u')
vpr_rna = vpr.replace('t','u')
env_rna = env.replace('t','u')
print(hiv_genome.replace("t","u"))
#### For each gene, generate a sum for each of the nuclotides in that gene (e.g., #of 'A',#of'U',#of'G',#of'C')
- For each gene, caculate the GC content (%)
- percent GC = sum of (G) + sum (C) / total number of nuclotides in a given gene
print(gag.count('g')+gag.count('c')/len(gag))
print(pol.count('g')+pol.count('c')/len(pol))
print(vif.count('g')+vif.count('c')/len(vif))
print(vpr.count('g')+vpr.count('c')/len(vpr))
print(env.count('g')+env.count('c')/len(env))
---
gagGC = gag.count("G") + gag.count("C")/len(gag)
polGC = pol.count("G") + pol.count("C")/len(pol)
vifGC = vif.count("G") + vif.count("C")/len(vif)
vprGC = vpr.count("G") + vpr.count("C")/len(vpr)
envGC = env.count("G") + env.count("C")/len(env)
print(str(gagGC)+"\n"+str(polGC)+"\n"+str(vifGC)+"\n"+str(vprGC)+"\n"+str(envGC)+"\n")
---
print (hiv_genome.count("a"))
print (hiv_genome.count("t"))
print (hiv_genome.count("c"))
print (hiv_genome.count("g"))
---
sum_g=hiv_genome.count("g")
sum_c=hiv_genome.count("c")
sum_total=len(hiv_genome)
print((sum_g+sum_c)/sum_total)
---
def num_nucleotides(gene_name, gene_seq):
num_A = gene_seq.count("A")
num_U = gene_seq.count("U")
num_G = gene_seq.count("G")
num_C = gene_seq.count("C")
return print(f"The number of 'A's in {gene_name} is {num_A}, the number of 'U's is {num_U}, the number of 'G's is {num_G}, the num of 'C's is {num_C}")
num_nucleotides("gag_rna", gag_rna)
## Notebook 3
#### Print the list of these HIV genes in order given the list below
- The correct order is
- gag, pol, vif, vpr, vpu, env, nef
```python
print(hiv_gene_names[1])
print(hiv_gene_names[3])
print(hiv_gene_names[2])
print(hiv_gene_names[4])
print(hiv_gene_names[5])
print(hiv_gene_names[6])
print(hiv_gene_names[0])
print(hiv_gene_names[7])
```
---
---
```python!
print(hiv_gene_names[1], hiv_gene_names[3], hiv_gene_names[2], hiv_gene_names[4], hiv_gene_names[5], hiv_gene_names[0], hiv_gene_names[6])
```
---
---
#### Write a for loop that prints 'nucleotide!' for each of the nucleotides
for nucleotide in nucleic_acids:
print("nucleotide!")
for nucleotide in nucleic_acids:
print('nucleotide!')
for nucleotides in nucleic_acids:
print (nucleotides+" nucleotide!")
#### Write a 'for' loop that prints the nucleotide name and its one-letter abbreviation.
for nucleotide in nucleic_acids:
print(nucleotide,'('+nucleotide[0]+')')
---
for nucleotide in nucleic_acids:
print(nucleotide)
print(nucleotide[0])
---
for nucleotide in nucleic_acids:
print(nucleotide[0].upper(),nucleotide)
---
```python
for nucleotide in nucleic_acids:
print(nucleotide, nucleotide[0])
```
#### Use conditionals so that if the float is greater than or equal to 0.5 consider that #'Heads' otherwise 'Tails'
```
random_int = random.randint(0,10)
if random_int /10 >= 0.5:
print('Heads!')
else:
print('Tails!')
```
---
head_tails = random.ranf(1)
if head_tails <= 0.5:
print('Heads!')
else:
print('Tails!')
---
```python
l = ""
for i in range(1000):
x = random.ranf()
if x >= 0.5:
#print("heads")
l+= "1"
else:
#print("tails")
l+= "0"
print(str(l.count("0"))+" heads")
print(str(l.count("1"))+" tails")
```
### What is a model? What are some examples? Why does science depend on this?
example
a typically generic/stereotypical/representative example of smth bigger
A model is an example of something used to understand it better
A model is an ideal version of something sometimes used to better understand a process. There are physical models of cells and such that help people understand what cells look like. Model organisms are idealized.
something we can replicate and use as an example to make assumptions about how things work
no
#### 1. Write a simulation which determines if in one round of replication HIV will mutate or not¶
```
mutation_state=["mutation","no_mutation"]
mutation_rate=[0.044,0.956]
mutation_flip=random.choice(mutation_state,p=mutation_rate)
print(mutation_flip)
```
---
```python
mutating = ['mutation','no_mutation']
mutatingC = [0.044,0.956]
Ismutating = random.choice(mutating, p = mutatingC)
print(Ismutating)
```
---
mutation_state = ['mutation','no_mutation']
mutation_probabilities = [0.44,0.56]
fair_mutate = random.choice(mutation_state,p = mutation_probabilities)
print("My mutation is %s" %fair_mutate)
---
mutation_possibility = ['a mutation', 'no mutation']
probabilities = [0.44, 0.56]
mutation_chance = random.choice(mutation_possibility, p = probabilities)
print(mutation_chance)
---
mutation_state = ["mutation", "no_mutation"]
mutation_probabilities = [0.44, 0.56]
mutation_flip = random.choice(mutation_state, p = mutation_probabilities)
print(f"The hiv genome has {mutation_flip}s")
---
```
result_list = []
for result in range(0,20):
determined_results = random.choice(mutation_possibility, p = probabilities)
result_list.append(determined_results)
print(result_list)
```
#### If HIV is in the mutation state, determine which nuclotide to mutate
---
```python
nucleic_acids_DNA = ['adenine', 'guanine', 'cytosine', 'thymine']
onefourth_prob = [0.25, 0.25,0.25, 0.25]
nucleic_results = []
for mutation in range(1,2):
fair_flip = random.choice(nucleic_acids_DNA,p = onefourth_prob)
nucleic_results.append(fair_flip)
print(nucleic_results)
```
---
```python=
options = ["a", "c","g", "t"]
optionA = [0.0, 1/33, 29/33,3/33]
optionC = [14/95, 0.0, 0.0, 81/95]
optionG = [146/152, 2/152, 0.0, 4/152]
optionT = [20/44, 18/44, 6/44,0.0]
location = random.randint(0,len(genome))
if genome[location] == "a":
genome = genome[:location] + random.choice(options, p = optionA) + genome[location:]
elif genome[location] == "c":
genome = genome[:location] + random.choice(options, p = optionC) + genome[location:]
elif genome[location] == "g":
genome = genome[:location] + random.choice(options, p = optionG) + genome[location:]
else:
genome = genome[:location] + random.choice(options, p = optionT) + genome[location:]
```
```python
randombase = random.randint(0, len(hiv_genome))
print(randombase)
print(hiv_genome[randombase])
```
```
nuclear_location=random.randint(0,len(hiv_genome))
nuclear_choose=hiv_genome[nuclear_location]
print(nuclear_choose)
ops=["a","c","g","t"]
opa=[0,1/33,29/33,3/33]
opc=[14/95,0,0,81/95]
opg=[146/152,2/152,0,4/152]
opt=[20/44,18/44,6/44,0]
if nuclear_choose=="a":
mutation_a=random.choice(ops,p=opa)
print("a to",mutation_a)
elif nuclear_choose=="c":
mutation_c=random.choice(ops,p=opc)
print("c to",mutation_c)
elif nuclear_choose=="g":
mutation_g=random.choice(ops,p=opg)
print("g to",mutation_g)
elif nuclear_choose=="t":
mutation_t=random.choice(ops,p=opt)
print("t to",mutation_t)
else:
print("error")
```
# compleated
```python
#set variables lists and strings
from numpy import random
hiv_genome = "genome way to long add later"
mutating = ['mutation','no_mutation']
mutatingC = [0.044,0.956]
mutations = 0 #number of mutations will be randomised later
options = ["a", "c","g", "t"] #pool of mutations
#chance of what to mutate to for each nucleotide
optionA = [0.0, 1/33, 29/33,3/33]
optionC = [14/95, 0.0, 0.0, 81/95]
optionG = [146/152, 2/152, 0.0, 4/152]
optionT = [20/44, 18/44, 6/44,0.0]
#initianalize amount of mutations 4.4% 200 times
for flip in range(1,200):
Ismutating = random.choice(mutating, p = mutatingC)
if Ismutating == 'mutation':
mutations += 1
#mutation function
def mutation(genome):
location = random.randint(0,len(genome))
gene = genome[location]
if gene == "a":
genome = genome[:location] + random.choice(options, p = optionA) + genome[location+1:]
elif gene == "c":
genome = genome[:location] + random.choice(options, p = optionC) + genome[location+1:]
elif gene == "g":
genome = genome[:location] + random.choice(options, p = optionG) + genome[location+1:]
elif gene == "t" :
genome = genome[:location] + random.choice(options, p = optionT) + genome[location+1:]
else:
print("inex[" + str(location) + "] is not a reconized nucleotide[a,c,t,g]")
return(genome)
print("inex[" + str(location) + "] "+gene+" > " + str(genome[location]))
return(genome)
#main()
print(hiv_genome)
for i in range(mutations):
hiv_genome = mutation(hiv_genome)
print(hiv_genome)
print(str(len(mutations)) +" mutations")
```
## Notebook 4
#### build a random dna sequence...
---
```python
#import
from numpy import random
#amount of nucleotides
initial_sequence_length = 0
final_sequence_length = 80
#lists
dna_sequence = []
my_nucleotides = ['a','t','g','c']
my_nucleotide_probs = [0.25,0.25,0.25,0.25]
#print out nucleotides
while initial_sequence_length < final_sequence_length:
nucleotide = random.choice(my_nucleotides,p=my_nucleotide_probs)
dna_sequence.append(nucleotide)
initial_sequence_length = initial_sequence_length + 1
#print the final result
print('>random_sequence (length:%d)\n%s' % (len(dna_sequence), dna_sequence))
```
---
```python
from numpy import random
final_sequence_length = 80
initial_sequence_length = 0
dna_sequence = '' #where the sequence will be stored
my_nucleotides = ['a','t','g','c'] #options of what can be added to sequence
my_nucleotide_probs = [0.25,0.25,0.25,0.25] #wiered way to store the probability of each option
while initial_sequence_length <= final_sequence_length:
nucleotide = random.choice(my_nucleotides,p=my_nucleotide_probs) #choosing one of the strings at random
dna_sequence = dna_sequence + nucleotide #adding chosen string
initial_sequence_length = initial_sequence_length + 1 #counting up to 80
print('>random_sequence (length:%d)\n%s' % (len(dna_sequence), dna_sequence))
```
# optimized it:
```python
from numpy import random
sequence_length = 80 #length of seaquence you want
dna_sequence = '' #where the sequence will be stored
my_nucleotides = ['a','t','g','c'] #options of what can be added to sequence
for i in range(sequence_length): #running function once for every nucliotide you want
dna_sequence += random.choice(my_nucleotides) #choosing a random nucliotide from the nucliotide pool and adding it to the sequence
print('>random_sequence (length:%d)\n%s' % (len(dna_sequence), dna_sequence)) #printing sequence in FASTA format
```
```
# build a random dna sequence...
from numpy import random
final_sequence_length = 80
initial_sequence_length = 0
dna_sequence = ""
my_nucleotides = ["A", "T", "G", "C"]
my_nucleotide_probs = [0.25, 0.25, 0.25, 0.25] #equal prob of each nucleotide
while initial_sequence_length < final_sequence_length: #while under desired length
random_nucleotide = random.choice(my_nucleotides, p = my_nucleotide_probs)
dna_sequence += random_nucleotide #adds random nucleotide to the dna sequence
initial_sequence_length += 1 #increases sequence length (makes sure that the while loop won't run forever)
print(f">random_sequence (length: {len(dna_sequence)})\n{dna_sequence}")
```
from numpy import random
final_sequence_length = 80 #length
initial_sequence_length = 1
dna_sequence = [] #where the sequence will be stored
my_nucleotides = ["a","t","c","g"]
my_nucleotide_probs = [0.25,0.25,0.25,0.25]
while initial_sequence_length < final_sequence_length:
nucleotide = random.choice(my_nucleotides,p=my_nucleotide_probs) #new nucleartide
dna_sequence.append(nucleotide) #add the nucleartide to to sequence
initial_sequence_length = initial_sequence_length + 1
print('>random_sequence (length:%d)''\n''%s' % (len(dna_sequence),dna_sequence))
from numpy import random
final_sequence_length = 80
initial_sequence_length = 1
dna_sequence = ''
my_nucleotides = ['a','t','g','c']
my_nucleotide_probs = [0.25,0.25,0.25,0.3]
while initial_sequence_length < final_sequence_length:
nucleotide = random.choice(my_nucleotides,p=my_nucleotide_p)
dna_sequence = dna_sequence + nucleotide
initial_sequence_length = initial_sequence_length + 1
print('>random_sequence (length:%d)\n%s' % (len(dna_sequence), dna_sequence))
#### Challenge: Your dictionary should contain the key:value pair 'beta_id':'SJW99399'. Using only that value from the my_mouse_exp dictionary, create a new entry in my_mouse_exp , experimenter which has the value SJW extracted from the 'beta_id':'SJW99399' dictionary entry.
```python
my_mouse_exp = {'alpha':{'avgp':3,'avgm':17,'id':"CGJ28371"}
,'beta':{'avgp':5,'avgm':16.4,'id':"SJW99399"}
,'gamma':{'avgp':6,'avgm':17.8,'id':"PWS29382"}}
```
```python
my_mouse_exp['experimenter'] = my_mouse_exp['beta_id'][0:3]
print(my_mouse_exp)
```
my_mouse_exp["beta_experimenter"] = my_mouse_exp["beta_id"][0:3]
print(my_mouse_exp)
#### Write the appropriate code to translate an RNA string to a protein sequence:
---
```python
protein = ""
for i in range(0,len(rna), 3):
protein+=amino_acids[rna[i:i+3]]
print(protein)
```
---
```python
startX_val = 0
loop_count = 0
rna_by3 = ((len(rna))/3)
grouped_rna = []
#This groups the RNA into groups of three into a list
while loop_count < rna_by3:
grouped_rna.append(rna[startX_val:startX_val+3])
loop_count = loop_count+1
startX_val = startX_val+3
#variables reset
loop_count=0
startX_val=0
display_list = []
#This converts the list of RNA by threes into the amino acids, then stores them in the display list
while loop_count < len(grouped_rna):
display_list.append(amino_acids[grouped_rna[startX_val]])
loop_count = loop_count + 1
startX_val = startX_val + 1
print(display_list)
```
```
rna = 'AUGCAUGCGAAUGCAGCGGCUAGCAGACUGACUGUUAUGCUGGGAUCGUGCCGCUAG'
protein = ""
for i in range(0, len(rna)-2, 3): #loops through by 3
codon = rna[i] + rna[i+1] + rna[i+2] #takes codon
protein += amino_acids[codon] #translates codon and adds it to the protein
print(protein)
```
---
#### Bonus: Can you translate this sequence in all 3 reading frames?
```python
for frame in range(3):#1 iratation for every frame
protein = "" #initialising variable to store protien
for i in range(0+frame,len(rna), 3):# goes over the entire rna seaquence in steps of 3
if i + 3<len(rna): #not to overload the function for not overloading the string
protein+=amino_acids[rna[i:i+3]] #adds it to protien
print("frame %d: %s" % (frame + 1, protein)) #prints the protien and what frame its on
```
```
rna = "AUGCAAGACAGGGAUCUAUUUACGAUCAGGCAUCGAUCGAUCGAUGCUAGCUAGCGGGAUCGCACGAUACUAGCCCGAUGCUAGCUUUUAUGCUCGUAGCUGCCCGUACGUUAUUUAGCCUGCUGUGCGAAUGCAGCGGCUAGCAGACUGACUGUUAUGCUGGGAUCGUGCCGCUAG"
def rna_conversion(reading_frame): #function w/ reading fram (1-3) as inputs
protein = ""
for i in range(reading_frame - 1, len(rna)-2, 3): #adapts for reading frame and total #
codon = rna[i:i+3] #makes codon
protein += amino_acids[codon]
return protein
rna_conversion(1)
rna_conversion(1)
rna_conversion(3) #enter a number between 1 and three to represent the diff reading frames
```
#### Translating DNA to RNA TO PROTEIN
```python
print(dna.replace("T","U"))
```
```
dna = "ACGTCGTTTACGTACGGGAGTCGTACGATCCTCCCGTAGCTCGGGATCGTTTTATCGTAGCGGGAT" #no start codon :
rna = dna.replace("T", "U") #converts the DNA to RNA
protein = ""
for i in range(0, len(rna)-2, 3): #loops through by 3 without maxing out
codon = rna[i:i+3] #takes codon
protein += amino_acids[codon] #adds letter to the protein sequence
print(protein)
```
---
```python
dna = 'ACGTCGTTTACGTACGGGAGTCGTACGATCCTCCCGTAGCTCGGGATCGTTTTATCGTAGCGGGAT'
rna = dna.replace('T','U')
startX_val = 0
loop_count = 0
rna_by3 = ((len(rna))/3)
grouped_rna = []
#This groups the RNA into groups of three into a list
while loop_count < rna_by3:
grouped_rna.append(rna[startX_val:startX_val+3])
loop_count = loop_count+1
startX_val = startX_val+3
#variables reset
loop_count=0
startX_val=0
display_list = []
#This converts the list of RNA by threes into the amino acids, then stores them in the display list
while loop_count < len(grouped_rna):
display_list.append(amino_acids[grouped_rna[startX_val]])
loop_count = loop_count + 1
startX_val = startX_val + 1
print(display_list)```
#useful commands that convert a list into a string
''.join(str(value) for value in display_list)
''.join(display_list)
---
```
```
dna = 'ACGTCGTTTACGTACGGGAGTCGTACGATCCTCCCGTAGCTCGGGATCGTTTTATCGTAGCGGGAT'
#translate dna into rna
rna= dna.replace('T','U')
#group every 3 rna sequence
start=0
end=3
genetic_code=[]
while end<len(rna):
code_single=rna[start:end]
genetic_code.append(amino_acids[code_single])
end=end+3
start=start+3
print(genetic_code)
#### Write a function that calculates the GC content of a DNA string
dna_string='acgtcgt'
def gc_content():
content_g=dna_string.count('g')
content_c=dna_string.count('c')
print((content_g+content_c)/len(dna_string))
gc_content()
---
```python
dna = 'ACGTCGTTTACGTACGGGAGTCGTACGATCCTCCCGTAGCTCGGGATCGTTTTATCGTAGCGGGAT'
def gc_content():
dna_gc = ((dna.count('G') + dna.count('C'))/len(dna))*100
print(dna_gc)
gc_content()
```
---
```
dna_sample = "aattcgatcggggtacccagataccatagacatagacataaatggac"
dna_sample = dna_sample.upper()
def percent_GC(gene_name, gene_seq):
percent_GCs = (gene_seq.count("G") + gene_seq.count("C"))/len(gene_seq)
percent_GCs = percent_GCs*100
return percent_GC, print(f"The percent of GCs in {gene_name} is {percent_GCs}%")
percent_GC("dna", dna_sample)
```
```python
def GCcont(genome):
genome = genome.lower()
return("%d" % ((genome.count("g")+genome.count("c"))/len(genome)*100)+"%")
print(GCcont(dna))
```
#### Write a function that generates a random string of DNA of random length
```python
def randomDna(mins, maxs):#function name and arguments
dna_sequence = ""#setting up str to save sequence
length = random.randint(mins,maxs)#randomising length of string from min to max
nucleotides = ['a','t','g','c']# pool of nucliotide options
for i in range(length):#irritates length number of times
dna_sequence += random.choice(nucleotides)#adds random nuclitoide from pool into sequence
return dna_sequence#returns the sequence
print(randomDna(10,100))#activates the function
```
```
nucleotides = ["A", "C", "G", "T"]
probs_of_nucleotides = [0.25, 0.25, 0.25, 0.25]
def random_dna(max_val):
rand_dna = ""
random_length_dna = random.randint(0, max_val)
for i in range(random_length_dna):
random_nucleotide = random.choice(nucleotides, p = probs_of_nucleotides)
rand_dna += random_nucleotide
return rand_dna
random_dna(100)
```
```python=
def randomdnastring():
from numpy import random
dna_state = ['A', 'T', 'G', 'C']
dnalist = []
for letter in range(1,21):
rletter = random.choice(dna_state)
dnalist.append(rletter)
print(dnalist)
randomdnastring()
```
#### Write a function that generates a random string of DNA of random a random length: use optional arguments to set the length of the strings and the probabilities of the nucleotides.
``` python =
nucleotides = ["A", "C", "G", "T"]
building_dna = ""
def random_dna(max_val = 100, probs_of_nucleotides = [0.25, 0.25, 0.25, 0.25]): #defines function with optional parameters
global building_dna
length_of_dna = random.randint(0, max_val) #picks random dna length given the max inputted
for i in range(length_of_dna):
random_nucleotide = random.choice(nucleotides, p = probs_of_nucleotides) #choses a random nucleotide given probs
building_dna += random_nucleotide #adds nucleotide to dna
print(f"{building_dna}, {length_of_dna}") #prints dna and length
random_dna(140)
```
---
```python
def randomDna(mins = 1, maxs=1000, probabilities = [0.25,0.25,0.25,0.25]):#function name and arguments
dna_sequence = ""#setting up str to save sequence
length = random.randint(mins,maxs)#randomising length of string from min to max
nucleotides = ['A','C','G','T']# pool of nucliotide options
for i in range(length):#irritates length number of times
dna_sequence += random.choice(nucleotides, p =probabilities)#adds random nuclitoide from pool into sequence
return dna_sequence#returns the sequence
Dna = randomDna(21,23, [0.33,0.33,0.14,0.20])#activates the function
print(Dna)
print(len(Dna))
```
```python
def newdnastring(a_prob = 0.25, t_prob = 0.25, g_prob = 0.25, c_prob= 0.25, provided_length = 15):
#probablities stated as first 4 optional variables, provided length also optional (deafult 15)
from numpy import random
dna_state = ['A', 'T', 'G', 'C']
dnalist = []
#letters should be added to the list above
for letter in range(0, provided_length):
#setting the variable that's added to dnalist
rletter = random.choice(dna_state, p = (a_prob, t_prob, g_prob, c_prob))
dnalist.append(rletter)
#creating a string from the list, and printing it
print(''.join(str(value) for value in dnalist))
#just examples of use, not necessary
newdnastring(provided_length = 30)
newdnastring(0.5, 0.2, 0.1, 0.2, 15)
```
from numpy import random
nucleartide_op=['a','t','c','g']
dna_sequence=[]
def dna_random_string(dna_length, dna_probabilities):
if dna_length!=-1:
for dna in range(0,dna_length):
if dna_probabilities!=-1:
dna_sequence.append(random.choice(nucleartide_op,p=dna_probabilities))
else:
dna_sequence.append(random.choice(nucleartide_op))
else:
dna_length = random.randint(1,100)
for dna in range(0,dna_length):
if dna_probabilities!=-1:
dna_sequence.append(random.choice(nucleartide_op,p=dna_probabilities))
else:
dna_sequence.append(random.choice(nucleartide_op))
print(''.join(dna_sequence))
dna_random_string()
---
```python
from numpy import random
def rand_dna(end_rand,
start_rand=0,
a_prob=0.25,
t_prob=0.25,
c_prob=0.25,
g_prob=0.25):
dna_length = random.randint(start_rand, end_rand)#Decides DNA length based on the parameters given
dna = ''#Empty string
nucleotides = ['a', 't', 'c', 'g']
one_fourthprob = [a_prob,t_prob,c_prob,g_prob]#Provides the probabilities based on the parameters given
for i in range (0,dna_length):
dna += random.choice(nucleotides, p=one_fourthprob)
print(dna)
#Runs the function
rand_dna(100,5)
```
---
#### Challenge: Write a function that generates a random protein of length L
```python=
amino_acids_val = ['I', 'I', 'I', 'M', 'T', 'T', 'T', 'T', 'N', 'N', 'K', 'K', 'S', 'S', 'R', 'R', 'L', 'L', 'L', 'L', 'P', 'P', 'P', 'P', 'H', 'H', 'Q', 'Q', 'R', 'R', 'R', 'R', 'V', 'V', 'V', 'V', 'A', 'A', 'A', 'A', 'D', 'D', 'E', 'E', 'G', 'G', 'G', 'G', 'S', 'S', 'S', 'S', 'F', 'F', 'L', 'L', 'Y', 'Y', '_', '_', 'C', 'C', '_', 'W']
def aminoacids(length):
# variable to save number of tries
tries = 0
#while loop to go on forver unless loop is broken
while True:
#restart k evry new try
k = ""
#first random nuclaic acid
k+= random.choice(amino_acids_val)
#if first nuclaic acid is M continue if it isnt restart
if k[0] == "M":
#will stop the moment a stop nuclaic acid is in the protein
while '_'not in k:
#ands amino acids
k+= random.choice(amino_acids_val)
#force function to stop if length is correct/ wont get to it if there are stop nuclaic acids
if len(k)==length:
return(k,tries)
#add try if anything goes wrong and restart
tries += 1
print(aminoacids(10))
```
```python =
def generate_random_protein(amino_acids, L = 50):
stop_codons = ["UAA", "UAG", "UGA"]
trials = 0
protein = ""
while len(protein) < L:
codon = random.choice(list(amino_acids.keys())) #takes a random codon from the amino_acids dictionary
amino_acid = amino_acids[codon] #defines amino_acid as the the letter from the dictionary
if amino_acid == "M": #if start codon
protein += amino_acid # add amino acid to the protien
elif codon in stop_codons: #if stop codon, stop
trials += 1 #adds to trials bc didn't add to protien
protein = "" #reset protien
elif len(protein) >= 1 and protein[0] == "M": #if after start codon, normal, and starts with an M
protein += amino_acid #add
return protein, trials
generate_random_protein(amino_acids, 100) #are 90 and L = 90 the same as parameters?
```
```python=
def random_amino_acids(length):
nucleotides = ['A','U','C','G']
start_codon = 0
current_length = 0
amino_sequence = ''
while length > current_length:
current_length = current_length+1
selected_acid = amino_acids[random.choice(nucleotides)+random.choice(nucleotides)+random.choice(nucleotides)]
if selected_acid == 'M':
start_codon = 1
if start_codon == 1:
amino_sequence = amino_sequence+selected_acid
return amino_sequence
random_amino_acids(100)
```
## Baby names
#### Use the pd.read_csv command to import the "StateNames.csv" file into a data frame and name it "state"
```python
states = pd.read_csv("data/StateNames.csv",sep=',',index_col=0,
dtype= {"Name": str, "Year": "object", "Gender": object, "State": str,"Count":int})
```
---
```
state=pd.read_csv('data/StateNames.csv', sep=',',index_col=0,
dtype={"Name":str, "Year": object, "Gender": object,"State":str,"Count":int})
state.shape
```
## STATS I Notebook
#### Assume that we are going to enter the colors alphabetical order So
````
Tube_0 = [5,14,5,12,7,3]
Tube_1 = [9,6,7,10,6,5]
Tube_2 = []
Tube_3 = [10, 8, 3, 9, 4, 9]
Tube_4 = [6, 10, 15, 8, 5, 4]
Tube_5 = [10, 7, 7, 11, 2, 8]
Tube_6 = []
Tube_7 = [9,11,7,9,6,5]
````
# How would you make a plot for all of the tubes in the class?
# Hint - to give a title to a plot use the plot.title() function
```python =
Tube_0 = [22, 13, 21, 18, 8, 17]
Tube_1 = [9, 6, 7, 10, 6, 5]
Tube_3 = [10, 8, 3, 9, 4, 9]
Tube_4 = [6, 10, 15, 8, 5, 4]
Tube_5 = [10, 7, 7, 11, 2, 8]
Tube_7 = [9, 11, 7, 9, 6, 5]
def plot_tube(tube_name_string, tube_name):
observations = tube_name #sets observation as the list of inputs (could be a list or a name like Tube_7)
n = len(observations)
index = np.arange(n) #6 bars to represent 6 observations in the list
colors = ['blue','brown','green', 'orange', 'red', 'yellow']
#x axis setting, things to plot, colors should be same as list, labelbars as colors and center the bars
plot_1 = plot.bar(index, observations, color = colors, tick_label = colors, align = 'center')
plot.title(f"Plot of tube {tube_name_string}") #sets the name of the tube data using user input
plot.show(plot_1)
#calls the function to display all of the tubes
plot_tube("Tube_0", Tube_0)
plot_tube("Tube_1", Tube_1)
plot_tube("Tube_3", Tube_3)
plot_tube("Tube_4", Tube_4)
plot_tube("Tube_5", Tube_5)
plot_tube("Tube_7", Tube_7)
plot_tube("Random tube", [10, 4, 6, 8, 7, 11]) #must be a list of 6 ints to work
```
```python=
tube_list = {'tube_0':[5,14,5,12,7,3],'tube_1':[9,6,7,10,6,5],'tube_2':[],'tube_3':[10,8,3,9,4,9],
'tube_4':[6,10,15,8,5,4],'tube_5':[10, 7, 7, 11, 2, 8],'tube_6':[],'tube_7':[9,11,7,9,6,5]}
x = 0
for tube in tube_list:
observations = tube_list['tube_''%x'%x]
if observations == []:
print('no data for tube''%x'%x)
else:
n = len(observations)
index = np.arange(n)
colors = ['blue',
'brown',
'green',
'orange',
'red',
'yellow']
plot_1 = plot.bar(index,
observations,
color=colors,
tick_label=colors,
align='center')
plot.title('tube_''%x'%x)
plot.show(plot_1)
x = x+1
```
```python
def make_plot(pool,pool_name):
t = plot.title(pool_name)
observations = pool
n = len(observations)
index = np.arange(n)
colors = ['blue',
'brown',
'green',
'orange',
'red',
'yellow']
plot_1 = plot.bar(index,observations,color=colors,tick_label=colors,align='center')
plot.show(plot_1)
make_plot(Tube_0,"Tube_0")
make_plot(Tube_1,"Tube_1")
make_plot(Tube_3,"Tube_3")
make_plot(Tube_4,"Tube_4")
make_plot(Tube_5,"Tube_5")
make_plot(Tube_7,"Tube_7")
```
```python=
def plot_points(tube_ID, plot_name):
observations = tube_ID
n = len(tube_ID)
index = np.arange(n)
colors = ['blue',
'brown',
'green',
'orange',
'red',
'yellow']
plot_1 = plot.bar(index,
observations,
color=colors,
tick_label=colors,
align='center')
plot.title(plot_name)
plot.xlabel('Colors')
plot.ylabel("Amount of MnMs")
plot.show(plot_1)
plot_points(Tube_0, 'Tube 0')
plot_points(Tube_1, 'Tube 1')
plot_points(Tube_3, 'Tube 3')
plot_points(Tube_4, 'Tube 4')
plot_points(Tube_5, 'Tube 5')
plot_points(Tube_7, 'Tube 7')
```
import numpy as np
import matplotlib.pyplot as plt
mm_data = {
1: [5, 14, 5, 12, 7, 3],
2: [9, 6, 7, 10, 6, 5],
3: [10, 8, 3, 9, 4, 9],
4: [6, 10, 15, 8, 5, 4],
5: [10, 7, 7, 11, 2, 8],
6: [9, 11, 7, 9, 6, 5]
}
```
mm_number = 1
color = ['blue', 'brown', 'green', 'orange', 'red', 'yellow']
def mm_count(observation_count):
h = len(observation_count)
index = np.arange(h)
plot.bar(index, observation_count, color=color, tick_label=color, align='center')
plot.show()
while mm_number < 7:
mm_count(observation_count=mm_data[mm_number])
mm_number += 1
```