Some graphics

Taken from matplotlib.org gallery.

import matplotlib.pyplot as plt
import numpy as np


# Fixing random state for reproducibility
np.random.seed(19680801)

fig, axs = plt.subplots(2, 2)
cmaps = ['RdBu_r', 'viridis']
for col in range(2):
    for row in range(2):
        ax = axs[row, col]
        pcm = ax.pcolormesh(np.random.random((20, 20)) * (col + 1),
                            cmap=cmaps[col])
    fig.colorbar(pcm, ax=axs[:, col], shrink=0.6)
plt.show()

Rosalind problems

Just some solutions to some basic Project Rosalind problems.

Complementing a Strand of DNA

Sample Input

AAAACCCGGT

Sample Output

ACCGGGTTTT
def reverse_complement(nuc_sequence):
    """
    Returns the reverse complement of a nucleotide sequence.
    >>> reverse_complement('ACGT')
    'ACGT'
    >>> reverse_complement('ATCGTGCTGCTGTCGTCAAGAC')
    'GTCTTGACGACAGCAGCACGAT'
    >>> reverse_complement('TGCTAGCATCGAGTCGATCGATATATTTAGCATCAGCATT')
    'AATGCTGATGCTAAATATATCGATCGACTCGATGCTAGCA'
     """
    complements = {
        "A": "T",
        "C": "G",
        "G": "C",
        "T": "A"
    }
    rev_seq = "".join([complements[s] for s in nuc_sequence[::-1]])
    return rev_seq

import doctest
doctest.run_docstring_examples(reverse_complement, globals(), verbose=True)
Finding tests in NoName
Trying:
    reverse_complement('ACGT')
Expecting:
    'ACGT'
ok
Trying:
    reverse_complement('ATCGTGCTGCTGTCGTCAAGAC')
Expecting:
    'GTCTTGACGACAGCAGCACGAT'
ok
Trying:
    reverse_complement('TGCTAGCATCGAGTCGATCGATATATTTAGCATCAGCATT')
Expecting:
    'AATGCTGATGCTAAATATATCGATCGACTCGATGCTAGCA'
ok
"Good!" if reverse_complement('AAAACCCGGT') ==  'ACCGGGTTTT' else "Not good!"

‘Good!’