Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Build a Translator
- def translate(phrase):
- translation = ""
- for letter in phrase:
- if letter in "AEIOUaeiou":
- if letter.isupper():
- translation = translation + "K"
- else:
- translation = translation + "k"
- else:
- translation = translation + letter
- return translation
- print(translate(input("enter a phrase")))
- # Guessing game
- secret_word = "giraffe"
- guess = ""
- guess_count = 0
- guess_limit = 3
- out_of_guesses = False
- while guess != secret_word and not (out_of_guesses):
- if guess_count < guess_limit:
- guess = input ("Enter guess:")
- guess_count += 1
- else:
- out_of_guesses = True
- if out_of_guesses:
- print("You lose")
- else:
- print("You win")
- # Caculator
- num1 = float(input("Enter first number:"))
- op = input("Enter operator:")
- num2 = float(input("Enter second number:"))
- if op == "+":
- print(num1 + num2)
- elif op == "-":
- print (num1 - num2)
- elif op == "/":
- print (num1 / num2)
- elif op == "*":
- print (num1 * num2)
- else:
- print ("Invalid operator")
- # Lengte van de uitgeschreven input (voorbeeld primer sequentie)
- Seq_primer = input("Enter primer sequence:")
- print("length nucleotide primer sequence is:", len(Seq_primer), "nucleotides long")
- # code die nummers in succesie verteld en een eindantwoord heeft
- Leeftijd = 0
- while Leeftijd <= 26:
- print(Leeftijd)
- Leeftijd += 1
- if Leeftijd == 27:
- print("Jeetje wat oud")
- # DNA to RNA
- def DNA_to_RNA(DNA):
- DNA = DNA.upper()
- RNA = DNA.replace("T","U")
- return RNA
- print(DNA_to_RNA(input("DNA sequence:")))
- # RNA to DNA
- def RNA_to_DNA(RNA):
- RNA = RNA.upper()
- DNA = RNA.replace("U","T")
- return DNA
- print(RNA_to_DNA(input("RNA sequence:")))
- # Reverse complement DNA
- DNA = input("Please enter your DNA sequence")
- DNA_upper = DNA.upper()
- DNA_upper_reversed = DNA_upper[::-1]
- for i in DNA_upper_reversed:
- if(i == "A"):print ("T", end ="")
- elif (i == "T"):print ("A", end ="")
- elif (i == "C"):print("G", end ="")
- elif (i == "G"):print("C", end ="")
- # Nucleotide counter
- DNA = input("Enter DNA sequence:")
- Upper_DNA = DNA.upper()
- A = Upper_DNA.count("A")
- T = Upper_DNA.count("T")
- C = Upper_DNA.count("C")
- G = Upper_DNA.count("G")
- print("The number of A in your DNA sequence is:", A)
- print("The number of T in your DNA sequence is:", T)
- print("The number of C in your DNA sequence is:", C)
- print("The number of G in your DNA sequence is:", G)
- print("The GC ratio of your DNA sequence is:",(G+C)/(G+C+T+A)*100, "procent!")
- # Digestion enzym code
- DNA0 = input("Enter DNA sequence:")
- seq = DNA0.upper()
- enz0 = input("Enter the enzyme name:")
- enz = enz0.upper()
- y= seq[0]
- y_minus = 0
- restriction_site = ""
- restriction_site = 0
- fragment = ""
- enz = ""
- def digestion (seq,enz):
- if (enz == "XBAI"): recognition_site = "TCTAGA"
- elif (enz == "ECORI"): recognition_site = "GAATTC"
- else:
- print("Enzym niet herkend")
- fragment = (seq.split(recognition_site))
- print("Upon digesting your DNA with "+ enz +", the following DNA fragments")
- for No_fr, i in enumerate(fragment):
- print(No_fr,i, end= "\n")
- str_regDNA0 = "(_^_)".join(map(str,fragment))
- str_regDNA1 = str(str_regDNA0[0:-1])
- print("\nThe map of your DNA sequence after this digestion would look like this")
- return(str_regDNA1)
- digestion(DNA0, enz0)
- # Module DNA naar AMINOZUUR
- userDNA= str(input("Enter your DNA sequence:"))
- Codon_triplet_data = ([userDNA[start : start+3]for start in range(0,len(userDNA),3)])
- AA_dictionary = {
- 'ATA': 'I', 'ATC': 'I', 'ATT': 'I', 'ATG': 'M',
- 'ACA': 'T', 'ACC': 'T', 'ACG': 'T', 'ACT': 'T',
- 'AAC': 'N', 'AAT': 'N', 'AAA': 'K', 'AAG': 'K',
- 'AGC': 'S', 'AGT': 'S', 'AGA': 'R', 'AGG': 'R',
- 'CTA': 'L', 'CTC': 'L', 'CTG': 'L', 'CTT': 'L',
- 'CCA': 'P', 'CCC': 'P', 'CCG': 'P', 'CCT': 'P',
- 'CAC': 'H', 'CAT': 'H', 'CAA': 'Q', 'CAG': 'Q',
- 'CGA': 'R', 'CGC': 'R', 'CGG': 'R', 'CGT': 'R',
- 'GTA': 'V', 'GTC': 'V', 'GTG': 'V', 'GTT': 'V',
- 'GCA': 'A', 'GCC': 'A', 'GCG': 'A', 'GCT': 'A',
- 'GAC': 'D', 'GAT': 'D', 'GAA': 'E', 'GAG': 'E',
- 'GGA': 'G', 'GGC': 'G', 'GGG': 'G', 'GGT': 'G',
- 'TCA': 'S', 'TCC': 'S', 'TCG': 'S', 'TCT': 'S',
- 'TTC': 'F', 'TTT': 'F', 'TTA': 'L', 'TTG': 'L',
- 'TAC': 'Y', 'TAT': 'Y', 'TAA': '*', 'TAG': '*',
- 'TGC': 'C', 'TGT': 'C', 'TGA': '*', 'TGG': 'W', }
- for codon in Codon_triplet_data:
- for item in AA_dictionary:
- if codon == item:
- print (AA_dictionary[item],end = "")
- # Working with strings
- phrase = "Giraffe Academy"
- print(phrase.lower())
- print(phrase + " is cool")
- print (phrase.isupper())
- print(phrase.upper().isupper())
- print(len(phrase))
- print(phrase[0])
- print(phrase.index("Acad"))
- print(phrase.replace("Giraffe", "Elephant"))
- #Working with numbers
- print(3 + 4.5)
- print(3*(4+5))
- print(10 % 3)
- from math import *
- my_num = -4
- print(my_num)
- print(max(4,6))
- print(min(4,6))
- print(round(5.768))
- print(floor(4.7))
- print(ceil(3.2))
- print(sqrt(36))
- #If statements
- Is_male = True
- Is_tall = False
- if Is_male and Is_tall:
- print("you are a tall male")
- elif Is_male and not Is_tall:
- print("you are a short male")
- elif not Is_male and Is_tall:
- print("you are not a male but are tall")
- else:
- print("you are either not male and not tall")
- # Dictionary
- Monthconversions = {
- "Jan":"January",
- "Feb":"February",
- "Mar": "March",
- }
- print(Monthconversions["Feb"])
- #For loop
- friends = ["jim","KAREN","kevin"]
- for friend in friends:
- if friend.isupper():
- print ("Big Friend")
- else:
- print ("Small friend")
- for index in range(5): # range means numbers
- if index == 0:
- print ("first")
- elif index == 1:
- print ("second")
- elif index == 2:
- print ("third")
- elif index == 3:
- print ("fourth")
- else:
- print ("last")
- #Exponent Function
- def raise_to_power(base_num, pow_num):
- result = 1
- for index in range(pow_num):
- result = result * base_num
- return result
- print(raise_to_power(3,6))
- # Biopython modules Chapter 3
- # GC Counting with Biopython
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- from Bio.SeqUtils import GC
- my_seq = Seq(input("ENTER DNA SEQUENCE:"), IUPAC.unambiguous_dna)
- print(GC(my_seq))
- # counting elements in Sequence
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- my_seq = Seq(input("ENTER DNA SEQUENCE"), IUPAC.unambiguous_dna)
- for index, letter in enumerate(my_seq):
- print("%i %s" % (index, letter))
- print(len(my_seq)) # print de totale lengte van de sequentie
- print(my_seq[0]) # print een exacte aangegeven element uit
- # Sequence slicing
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- my_seq = Seq("GATCGATGGGCCTATATAGGATCGAAAATCGC", IUPAC.unambiguous_dna)
- print(my_seq[2:12])
- # Adding sequences
- from Bio.Seq import Seq
- from Bio.Alphabet import generic_nucleotide
- from Bio.Alphabet import IUPAC
- nuc_seq = Seq(input("Enter first sequence"), generic_nucleotide)
- dna_seq = Seq(input("Enter second sequence"), IUPAC.unambiguous_dna)
- print(nuc_seq + dna_seq)
- from Bio.Seq import Seq
- from Bio.Alphabet import generic_dna
- list_of_seqs = [Seq("ACGT", generic_dna), Seq("AACC", generic_dna), Seq("GGTT", generic_dna)]
- sum(list_of_seqs, Seq("", generic_dna))
- # changing case
- from Bio.Seq import Seq
- from Bio.Alphabet import generic_dna
- dna_seq = Seq("acgtACGT", generic_dna)
- print(dna_seq.upper())
- print(dna_seq.lower())
- # Sequences in (reverse) complements
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- my_seq = Seq("GAAAAAC", IUPAC.unambiguous_dna)
- print(my_seq.complement())
- print(my_seq.reverse_complement())
- # TRANSCRIPTION
- # DNA TO mRNA
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- coding_dna = Seq("", IUPAC.unambiguous_dna)
- template_dna = coding_dna.reverse_complement()
- print(template_dna.reverse_complement().transcribe())
- # mRNA to DNA
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- messenger_rna = Seq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG", IUPAC.unambiguous_rna)
- print(messenger_rna.back_transcribe())
- # TRANSLATION
- # mRNA to Protein
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- messenger_rna = Seq("AUGGCCAUUGUAAUGGGCCGCUGAAAGGGUGCCCGAUAG", IUPAC.unambiguous_rna)
- print(messenger_rna.translate())
- # DNA to protein
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- coding_dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG", IUPAC.unambiguous_dna)
- print(coding_dna.translate())
- # Gene translation
- from Bio.Seq import Seq
- from Bio.Alphabet import generic_dna
- gene = Seq("GTGAAAAAGATGCAATCTATCGTACTCGCACTTTCCCTGGTTCTGGTCGCTCCCATGGCA" + \
- "GCACAGGCTGCGGAAATTACGTTAGTCCCGTCAGTAAAATTACAGATAGGCGATCGTGAT" + \
- "AATCGTGGCTATTACTGGGATGGAGGTCACTGGCGCGACCACGGCTGGTGGAAACAACAT" + \
- "TATGAATGGCGAGGCAATCGCTGGCACCTACACGGACCGCCGCCACCGCCGCGCCACCAT" + \
- "AAGAAAGCTCCTCATGATCATCACGGCGGTCATGGTCCAGGCAAACATCACCGCTAA", generic_dna)
- print(gene.translate(table="Bacterial"))
- # Translation tables
- from Bio.Data import CodonTable
- standard_table = CodonTable.unambiguous_dna_by_name["Standard"]
- mito_table = CodonTable.unambiguous_dna_by_name["Vertebrate Mitochondrial"]
- print(standard_table)
- print(standard_table.start_codons)
- # Comparing objects
- from Bio.Seq import Seq
- from Bio.Alphabet import IUPAC
- seq1 = Seq(input("Enter DNA sequence 1"), IUPAC.unambiguous_dna)
- seq2 = Seq(input("Enter DNA sequence 2"), IUPAC.ambiguous_dna)
- print(str(seq1) == str(seq2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement