Python (E06E2B) kernel altijd negatieve test uitvoeren!!!
Bij Claude: comments schrijven → tonen dat je het snapt !!
geheel getal = integer - kommagetal = float - stuk tekst = string – een lijst = [..] - een dict = {tekst}
• String: niet vermenigvuldigen met elkaar
• String kan je wel x10 doen om x aantal keer achter elkaar te laten staan
→ afhankelijk van het type kan je verschillende dingen doen
Type(…) = achterhalen welk type het is
Print(…) = printen wat die variabele is
Hoofdletter maken: dna.capitalize()
Lengte bepalen: len(dna)
Opslagen in een variabele: dna_length = len(dna)
Functie maken: def + naam van de functie + naam die je aan de functie geeft
= stuk code dat we opnieuw kunnen gebruiken
Nucleotiden tellen: def count_nucleotides(dna):
"""
Count the occurrence of each nucleotide (A, C, G, T) in a DNA string.
Parameters
----------
dna : str
DNA sequence, e.g. "ACGTACGT".
Returns
-------
dict
Mapping of nucleotide to count.
"""
dna = dna.upper()
return {nucleotide: dna.count(nucleotide) for nucleotide in "ACGT"}
dna_sequence = "ACGTAGGCTTACG"
print(count_nucleotides(dna_sequence))
, Drukletters maken: dna = dna.upper()
%GC-content bepalen: Gewoon in een cel:
dna =
"AACATGTTGAGCTCTGGCATAGAAGAGGCTGGTGGCTATTTTGTCCTTGGGCTGCCTGTT"
count_a = dna.count('A')
count_g = dna.count('G')
count_c = dna.count('C')
count_t = dna.count('T')
100 * (count_c + count_g)/(count_c + count_g + count_t + count_a)
In een functie:
dna =
"AACATGTTGAGCTCTGGCATAGAAGAGGCTGGTGGCTATTTTGTCCTTGGGCTGCCTGTT"
def perc_gc(dna):
count_a = dna.count('A')
count_g = dna.count('G')
count_c = dna.count('C')
count_t = dna.count('T')
return 100 * (count_c + count_g)/(count_c + count_g + count_t + count_a)
perc_gc(dna)
Reverse complement: def reverse_complement(dna):
"""Return the reverse complement of a DNA string."""
pairs = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
comp = ''.join(pairs[base] for base in dna)
return comp[::-1]
print(reverse_complement('ACT'))
Bij Claude: comments schrijven → tonen dat je het snapt !!
geheel getal = integer - kommagetal = float - stuk tekst = string – een lijst = [..] - een dict = {tekst}
• String: niet vermenigvuldigen met elkaar
• String kan je wel x10 doen om x aantal keer achter elkaar te laten staan
→ afhankelijk van het type kan je verschillende dingen doen
Type(…) = achterhalen welk type het is
Print(…) = printen wat die variabele is
Hoofdletter maken: dna.capitalize()
Lengte bepalen: len(dna)
Opslagen in een variabele: dna_length = len(dna)
Functie maken: def + naam van de functie + naam die je aan de functie geeft
= stuk code dat we opnieuw kunnen gebruiken
Nucleotiden tellen: def count_nucleotides(dna):
"""
Count the occurrence of each nucleotide (A, C, G, T) in a DNA string.
Parameters
----------
dna : str
DNA sequence, e.g. "ACGTACGT".
Returns
-------
dict
Mapping of nucleotide to count.
"""
dna = dna.upper()
return {nucleotide: dna.count(nucleotide) for nucleotide in "ACGT"}
dna_sequence = "ACGTAGGCTTACG"
print(count_nucleotides(dna_sequence))
, Drukletters maken: dna = dna.upper()
%GC-content bepalen: Gewoon in een cel:
dna =
"AACATGTTGAGCTCTGGCATAGAAGAGGCTGGTGGCTATTTTGTCCTTGGGCTGCCTGTT"
count_a = dna.count('A')
count_g = dna.count('G')
count_c = dna.count('C')
count_t = dna.count('T')
100 * (count_c + count_g)/(count_c + count_g + count_t + count_a)
In een functie:
dna =
"AACATGTTGAGCTCTGGCATAGAAGAGGCTGGTGGCTATTTTGTCCTTGGGCTGCCTGTT"
def perc_gc(dna):
count_a = dna.count('A')
count_g = dna.count('G')
count_c = dna.count('C')
count_t = dna.count('T')
return 100 * (count_c + count_g)/(count_c + count_g + count_t + count_a)
perc_gc(dna)
Reverse complement: def reverse_complement(dna):
"""Return the reverse complement of a DNA string."""
pairs = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
comp = ''.join(pairs[base] for base in dna)
return comp[::-1]
print(reverse_complement('ACT'))