In [7]:
%matplotlib inline
from pylab import *
import matplotlib.pyplot as plt
from IPython.core.display import Image

In [13]:
data = []
for y in range(10):
    data.append([y+x for x in range(10)])
# print(data)
Image(data=data)


Out[13]:

Matplot Lib


In [4]:
alpha = 0.7
phi_ext = 2 * pi * 0.5

def flux_qubit_potential(phi_m, phi_p):
    return 2 + alpha - 2 * cos(phi_p)*cos(phi_m) - alpha * cos(phi_ext - 2*phi_p)
phi_m = linspace(0, 2*pi, 100)
phi_p = linspace(0, 2*pi, 100)
X,Y = meshgrid(phi_p, phi_m)
Z = flux_qubit_potential(X, Y).T

In [5]:
fig, ax = plt.subplots()

p = ax.pcolor(X/(2*pi), Y/(2*pi), Z, cmap=cm.RdBu, vmin=abs(Z).min(), vmax=abs(Z).max())
cb = fig.colorbar(p, ax=ax)



In [21]:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import random

bignum = 10
data = []
for i in range(bignum):
    data.append([random.random() for x in range(bignum)])
mat = np.array(data)  #random.random((bignum, bignum))
X, Y = np.mgrid[:bignum, :bignum]

fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='3d')
surf = ax.plot_surface(X,Y,mat)
plt.show()


Most simple Pixel Map


In [32]:
def basic_func(x, y):
    return x+y

X, Y = np.mgrid[:bignum, :bignum]
Z = basic_func(X, Y)

In [26]:
fig, ax = plt.subplots()
p = ax.pcolor(X, Y, Z, cmap=cm.RdBu, vmin=abs(Z).min(), vmax=abs(Z).max())
cb = fig.colorbar(p, ax=ax)


Basic Repeat Map


In [33]:
raster_width = 11
seq = 'TCTCGTGAACCGTTCTTTCCCGCGGACGTGATGGATGTGGGTGCCTTTATTTGCGACGATATGGTCCGTAAATTAGGTCTCGTTGTTTGTACCCTCTCACTTGGCCGCTTCAACTTTTTTCCGATAATGTCTAATGCACCGACGGAATTATTGTACAGAGTAGCAAGCTCAGGTTGCACGGCAGACCTTGCCGCGTCGGGTCTGCGCACCACCCAAATCTGGGCGCGTCTGGGCCTCGCTGCTACACTGGTTAACCATGCTTCAGACTCTGTGACGATGAAATATCCAAACGACGTTGAATAAAAACGACGGGGAGCGGCGGTGATTTTTATCAATCGCGGTGAAGCAGTTATGCTCGACATCTATTAACAACAGGAGAAAGGCGCCACCGCTCCGGTGTATTATACACTGGGCCGTTTGACCGTCTCATCGACGGGCAACATGACCAAACCGCACATGCATTTCTCGGGCCGAATCGCCCGCGCCTACTGGAAAGCCGGCTCTGGCGATTATGCCGATTTTGAAAGTTTTCTTTCATCCAAAGCGTATATTATTCAGTTTCAAATATCGACCTTGCTGAAGAAAATCAAAGTGATCTTTTTATTTAAAGGCAATGATGGCGATGTACTTAATCGTGCGATCGCTTTGCGGCAGGGCCCCCGTTGGAATAGATTTGATATGCAGGAGCTGTATCCGATCTGGCATATTCTGTCCAATTAACAGCGCAATATCAACGCTGCGCTGTCTCTGCTGGTCGGCGAACACGGACTGATTCAGTCTCCTTTGGCAGGTTTCGTACAAGGTACCACGCTGAGCGCCCTGGGCCAACGGGACTTTGCACTGCGTAAGGACGCAGTGGAAGTGGGCTCCCTGAACCCTGAAGCCGGTGAAGACAAACGTACGACCATCATCTTTACCTATGTACTGCAGCAGCAAGGTTACAAATCCGGTAAATGTTGCGGCGAGGATAAATATGACGTTATTCTGAAAGAAGGGATTATCTACTATACCGTAGTTCTGATCATCCGGGGCTTCAAAGATTCAGACAAGGACGAAGATGACGGACTTAAACATGCGCTTGAAGGATTCGAAGGCGAACGTGGCGCTGCTCTGTCGACTGTAGCATCCGCGTCCGCATGGAGGAGTGGTCAACATAACGGCACCACCCCTTCGTCAAAGGTGGCGCAAGAACTCCGCCAGAAACGCTGCAATTCCAATACAAACATCACCTGCCCACACGTAAACCTTGAACTTAACAAGATATATCGGCTCTTCCCGCTCCAAAACTAAAAGATACCGGACGTGATCGCGATCAGAGGCAAATACTTGACTCATAAGCTGTCAACGGTTGATTTACTGGGTTTTTCTCCGCCAACCTGTCTGCGCTTGCATGATTATGAAGCCGTGTCAGATCCGATGAAAGTGGCGAATTTCCATAACCAGATGGGTTTCTTGGTAGGCGATGCCATCTTCGTTCAGGAACTCATCAAACAGACGGTCGCGCTGATCATTAACAAAGTAAAAAACCCTGGTGGCCTGAAACAGCGAGCCTCAGAAAAACCGAACTCTCAGCTAGTTTGAGGTGGGTCTAATCATGAGCCAGCACTGCGCGACCGTGGGTCTCGTATTCTGGGTGAGCGCGTGCGTGACGATATTCTGTATCTTGTTAACATGGGTTTTAAACATTCGTTCTTGGCTGACCGTGTCATCATGATCAAGATTGAAGAAGAGCTGCATTTTCATACCCAGAGCTACGAGGTCACCTCGCTCGGACAGGGGGTCAGTAATTACCTGGTCACAGCCGATGCGAAAGCCCCAAAACGTCGCCAACTGGCATATCATCTTGGTACTGGGTTCTCATCATTCTACGCTGGGGCGGATGATCAGGCGTCGCGCGTGGAAGTCAAACAGATGCAACGGATCCTGATTGCAGCCGCCCTGCCGGGCCTCCGAAAGAAATTGCGCCTGGATGCACACAATGAATTTATTGTCCCAATCATGACCGAGTTCGACCAGACCGGCCCCTTAACCTTAGGCTACGCATCAGAAAAACGCGCGCTCGATAACATCATGGTGAGTCAGGATTCTGTGCTGGGGAATCTCTTTATGAAATTTTTAGGTGTGCTGGTGGTCGGTATCAGCCGGACAGCGATAGCGGACCCAGATAAGTATATGGCTATTCTGCTGGGTGCGGTTTTCGACATGCTGGCGATGAAAATCATTGAAGTCTTAGATGTTACGTCCAACCGCAACTATTTGACCAATCGCCGTACGACGGAAATCGCAGCTGTGGCAGAAACCTGTGAGGACGGAGCGTTTGTGATGCTGCTGACCACGTGGCTGGGCAAGAAGTCGGATTCCCTGAAGTTCCCTAACTTAGTGATTGTCTATTATATAGTTATGGTCGGCGGCCCGTGCACCGGAGAGCAGCAGAAACGTGCTACAGCAGCCATGAGTAGCGAAATTGCGCTCCAGCCGTATTTCCGCTTCCGCCGGATTGAGCACACTGTCCGCGGCCGCGTCTTTTGACTGGAAAAAAGTTTCGGCGAAGACGCCGGCGATAATCTGGTCTCCAACAAAACCAAACGTCGCGGTAAAGGGCCGCAGTTTAAATATGTGGAACTGGCAGAACTGACCTTAATCAAGCTGTCGATTTGAGGCGGTGTAGCTAACATGGGAGGTAATGCACGTCATGGAATGAAAGGCATTCTGGGTCCGCTGCGCGTTGCCTCTTTAGCTTATCAGGCGAAAGGTGTCATCGGTTTATCTATGTTAAAAAACTGGGCTCCGGCCTAACAAAAAAATCTGCTGTCAGTTGCTGTACTGGTCCCGCTGAGCGCGAGCACAGGGAGCGCCCTGGAAATGGTGCGCGGTCTGAAAGAAGGCAACGCAGTCTTGGTGGCGAAGATGGGGATCGCCAAAGGAGCGACAGGTCGCTGGGCGGCTGTGGCAGATGGTAACGTCGCACCTCCGCTTCGCGAGCAATTAAACTTTCAGGCT'

In [106]:
seq = 'CTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTACTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTAGTTACTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGCCTTGC'

In [39]:
seq[1*x_size: 1*x_size + raster_width]


Out[39]:
'ACGTGATGGAT'

In [40]:
sum([True, False, True])


Out[40]:
2

In [116]:
x_size = 75 # frequency range
y_size = int(len(seq) / raster_width) # number of lines: (cut off the end)

In [109]:
def repeat_score(x, y):
    start_str =  seq[y*raster_width     : (y+1)*raster_width]
    target_str = seq[y*raster_width + x : (y+1)*raster_width + x]
    actual_width = min(len(start_str), len(target_str))
    return sum([start_str[i] == target_str[i] for i in range(actual_width)])

In [101]:
[[repeat_score(x,y) for x in range(1,x_size-1)] for y in range(y_size-10)]


Out[101]:
[[2, 3, 1, 1, 3, 1, 3, 3, 3, 4, 4, 3, 4, 1, 4, 3, 7, 3, 3, 1, 2, 1, 5],
 [5, 5, 4, 4, 2, 3, 1, 3, 0, 1, 2, 4, 2, 1, 3, 3, 1, 4, 3, 2, 3, 3, 2],
 [2, 1, 3, 6, 3, 4, 3, 2, 6, 4, 2, 2, 4, 2, 4, 3, 3, 5, 3, 2, 2, 3, 3],
 [3, 4, 3, 4, 2, 4, 1, 2, 3, 5, 1, 4, 3, 5, 3, 3, 1, 3, 2, 2, 4, 3, 4],
 [4, 4, 4, 3, 3, 1, 1, 2, 3, 4, 2, 5, 4, 3, 3, 1, 2, 2, 2, 0, 5, 6, 5],
 [2, 2, 2, 2, 4, 1, 1, 1, 4, 3, 3, 3, 6, 4, 3, 3, 0, 5, 4, 1, 3, 4, 2],
 [4, 1, 1, 3, 4, 2, 1, 2, 4, 2, 2, 3, 3, 5, 2, 2, 3, 1, 2, 1, 4, 1, 1],
 [3, 5, 5, 5, 2, 3, 4, 3, 3, 3, 3, 3, 4, 4, 5, 1, 5, 3, 5, 0, 4, 5, 3],
 [2, 5, 1, 4, 3, 3, 4, 3, 1, 2, 2, 5, 5, 5, 4, 2, 1, 4, 3, 4, 4, 4, 3],
 [4, 1, 3, 1, 3, 5, 3, 6, 4, 2, 2, 0, 2, 4, 4, 6, 3, 3, 3, 2, 2, 3, 3],
 [7, 4, 4, 2, 2, 1, 2, 3, 2, 5, 4, 4, 4, 4, 4, 3, 3, 2, 2, 3, 2, 2, 1],
 [1, 3, 3, 1, 2, 3, 5, 2, 3, 2, 1, 3, 1, 1, 3, 3, 2, 4, 3, 4, 5, 4, 4],
 [2, 1, 3, 5, 3, 1, 0, 4, 3, 0, 0, 3, 5, 2, 1, 3, 7, 0, 4, 1, 3, 3, 2],
 [4, 2, 4, 2, 3, 1, 3, 2, 4, 3, 1, 3, 3, 2, 4, 3, 1, 3, 4, 4, 3, 2, 4],
 [1, 3, 3, 4, 2, 3, 3, 3, 4, 2, 1, 3, 5, 4, 2, 3, 1, 4, 1, 2, 5, 2, 5]]

In [110]:
X, Y = np.mgrid[:x_size, :y_size]
Z = np.array([[repeat_score(x,y) for x in range(1,x_size+1)] for y in range(y_size)]).T

In [115]:
fig, ax = plt.subplots()
p = ax.pcolor(X, Y, Z, 
              cmap=cm.Greys_r, 
              vmin=0, vmax=raster_width)
cb = fig.colorbar(p, ax=ax)



In [48]:
x, y  = 20, 7
print( seq[y*x_size : y*x_size + raster_width])
print( seq[y*x_size + x : y*x_size + raster_width + x])
sum([start_str[i] == target_str[i] for i in range(raster_width)])


GCACGGCAGAC
TCGGGTCTGCG
Out[48]:
2

Notes

I most of the trouble that I had make this was because I am unfamiliar with NumPy arrays and matplotlib. The lines for Z and p = ax.pcolor(X, Y, Z, cmap=cm.Greys_r, vmin=0, vmax=raster_width) are very sensitive. The good and the bad of having a graphing platform is that I get scale axes for free. It will often squish the pixels. I prefer square pixels. I need to figure out how to generate a highly non-square graph since the Repeat Map is usually 25 wide x 200 high.

Finished Product


In [1]:
from Sequence_Utils import debugSequence, weighted_sequence


GTC
ACC
GAA
ATG
CCA
ACT
ATG
GCA
CTG
GAT

In [74]:
class RepeatMap():
    def __init__(self, sequence):
        self.seq = sequence
        self.raster_width = 11
        self.x_size = 25 # frequency range
        self.y_size = int(len(self.seq) / self.raster_width) # number of lines: (cut off the end)
    
    def repeat_score(self, x, y):
        start_str =  self.seq[y*self.raster_width     : (y+1)*self.raster_width]
        target_str = self.seq[y*self.raster_width + x : (y+1)*self.raster_width + x]
        actual_width = min(len(start_str), len(target_str))
        return sum([start_str[i] == target_str[i] for i in range(actual_width)])

    def render(self):
        X, Y = np.mgrid[:self.x_size, :self.y_size]
        Z = np.array([[self.repeat_score(x,y) for x in range(1,self.x_size+1)] for y in range(self.y_size)]).T
        fig, ax = plt.subplots()
        fig.set_size_inches(self.x_size /10, self.y_size /10)
        p = ax.pcolor(X, Y, Z, 
                      cmap=cm.Greys_r,
                      vmin=0, vmax=self.raster_width)
        cb = fig.colorbar(p, ax=ax)
        plt.gca().invert_yaxis()

In [75]:
rp = RepeatMap(debugSequence(25, 200, 5))

In [76]:
rp.render()



In [28]:
fig, ax = plt.subplots()
fig.figsize = (3,9)
fig.figsize


Out[28]:
(3, 9)

In [ ]: