Skip to content

Instantly share code, notes, and snippets.

@stephensalt
stephensalt / [ROSALIND DNA] Counting DNA Nucleotides.py
Created January 19, 2018 05:54
[ROSALIND DNA] Counting DNA Nucleotides
"""
Rosalind DNA - Counting DNA Nucleotides (http://rosalind.info/problems/dna/)
Problem
A string is simply an ordered collection of symbols selected from some alphabet and formed into a word; the length of a string is the number of symbols that it contains.
An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G', and 'T') is "ATGCTTCAGAAAGGTCTTACG."
Given: A DNA string ss of length at most 1000 nt.
Return: Four integers (separated by spaces) counting the respective number of times that the symbols 'A', 'C', 'G', and 'T' occur in ss.
Sample Dataset
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC
@stephensalt
stephensalt / [ROSALIND DNA] Transcribing DNA into RNA.py
Last active January 26, 2018 14:14
[ROSALIND DNA] Transcribing DNA into RNA
"""
Problem
An RNA string is a string formed from the alphabet containing 'A', 'C', 'G', and 'U'.
Given a DNA string tt corresponding to a coding strand, its transcribed RNA string uu is formed by replacing all occurrences of 'T' in tt with 'U' in uu.
Given: A DNA string tt having length at most 1000 nt.
Return: The transcribed RNA string of tt.
@stephensalt
stephensalt / [ROSALIND DNA] Complementing a Strand of DNA.py
Created February 10, 2018 11:24
[ROSALIND DNA] Complementing a Strand of DNA.py
"""
Problem
In DNA strings, symbols 'A' and 'T' are complements of each other, as are 'C' and 'G'.
The reverse complement of a DNA string ss is the string scsc formed by reversing the symbols of ss, then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").
Given: A DNA string ss of length at most 1000 bp.
Return: The reverse complement scsc of ss.
@stephensalt
stephensalt / [ROSALIND DNA] Rabbits and Recurrence Relations (fibonacci).py
Last active February 10, 2018 15:24
[ROSALIND DNA] Rabbits and Recurrence Relations
"""
Problem
A sequence is an ordered collection of objects (usually numbers), which are allowed to repeat. Sequences can be finite or infinite. Two examples are the finite sequence (π,−2–√,0,π)(π,−2,0,π) and the infinite sequence of odd numbers (1,3,5,7,9,…)(1,3,5,7,9,…). We use the notation anan to represent the nn-th term of a sequence.
A recurrence relation is a way of defining the terms of a sequence with respect to the values of previous terms. In the case of Fibonacci's rabbits from the introduction, any given month will contain the rabbits that were alive the previous month, plus any new offspring. A key observation is that the number of offspring in any month is equal to the number of rabbits that were alive two months prior. As a result, if FnFn represents the number of rabbit pairs alive after the nn-th month, then we obtain the Fibonacci sequence having terms FnFn that are defined by the recurrence relation Fn=Fn−1+Fn−2Fn=Fn−1+Fn−2 (with F1=F2=1F1=F2=1 to initiate the sequence). Although the seque