Commit 5c26855d by rebelCoder

### Lesson 3: GC Content, GC Content Subset.

parent 82f69023
 ... ... @@ -37,6 +37,20 @@ def reverse_complement(seq): """ return ''.join([DNA_ReverseComplement[nuc] for nuc in seq])[::-1] # More Pythonic solution. A little bit faster solution. # Pythonic approach. A little bit faster solution. # mapping = str.maketrans('ATCG', 'TAGC') # return seq.translate(mapping)[::-1] def gc_content(seq): """GC Content in a DNA/RNA sequence""" return round((seq.count('C') + seq.count('G')) / len(seq) * 100) def gc_content_subsec(seq, k=20): """GC Content in a DNA/RNA sub-sequence length k. k=20 by default""" res = [] for i in range(0, len(seq) - k + 1, k): subseq = seq[i:i + k] res.append(gc_content(subseq)) return res
 # DNA Toolset/Code testing file from dna_toolkit import * from utilities import colored import random # Creating a random DNA sequence for testing: randDNAStr = ''.join([random.choice(DNA_Nucleotides) for nuc in range(60)]) for nuc in range(50)]) DNAStr = validate_seq(randDNAStr) ... ... @@ -18,4 +17,8 @@ print(f'[3] + DNA/RNA Transcription: {transcription(DNAStr)}\n') print(f"[4] + DNA String + Complement + Reverse Complement:\n5' {DNAStr} 3'") print(f" {''.join(['|' for c in range(len(DNAStr))])}") print(f"3' {reverse_complement(DNAStr)[::-1]} 5' [Complement]") print(f"5' {reverse_complement(DNAStr)} 3' [Rev. Complement ]\n") print(f"5' {reverse_complement(DNAStr)} 3' [Rev. Complement]\n") print(f'[5] + GC Content: {gc_content(DNAStr)}%\n') print( f'[6] + GC Content in Subsection k=5: {gc_content_subsec(DNAStr, k=5)}\n')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!