SpectraMax M5e OD600

This notebook imports 3x3 OD600 readings from a SpectraMax M5e file and creates an 8x12 matrix of readings. This notebook does not compare space and ground data (see SpaceGrowthWinners.ipynb).

Single time point


In [1]:
import numpy

blob = open( 'Spaceplate1_48.txt').read()
block = blob.split('End')[0]  # different versions of the plate reader software put End tokens in different places

#stupid_delimeter = '\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\n'

stupid_delimeter = '\t\t\n\t\t\n'

ttimes = []
ttemps = []
frames = []

stop_at = 273 # in case the run was not completed, stop here

for tn,tpoint in enumerate(block.split(stupid_delimeter)[:stop_at]) :
    if tn == 0 : # skip header stuff
        tpoint = tpoint.split('12\t\t\n')[1]
    if tn == 9 : break # stop after nine frames
    frame = numpy.zeros((8,12))
    for rn,row in enumerate(tpoint.split('\n')) :
        for cn,col in enumerate(row.split('\t')) :
            if rn != 0 and cn == 0 : continue
            if rn != 0 and cn == 1 : continue
            if cn == 14 : continue
            if cn == 15 : continue
            if rn == 0 and cn == 0 : ttimes.append(col); continue
            if rn == 0 and cn == 1 : ttemps.append(col); continue
            #print tn,rn,cn-2,col
            frame[rn,cn-2] = float(col)
    frames.append(frame)
    
frames = numpy.array(frames)
times = arange( 0, len(frames) / 96.0, 1/96.0 ) # not actual times here...

rownames = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' ]
n = 0

fig, ax = plt.subplots( 8, 12, figsize=(16,7))
fig.suptitle('Space Plate 1, T=48', fontsize=12, x=0.05,y=1 )
for i in range(8) :
    for j in range(12) :
        subplot(8,12,n+1)
        title( rownames[i] + str(j+1) )
        #ylim( (0,max_val) )
        ylim( ( 0, 1.85 ) )
        #xlim( ( 0, 45 ) )
        xlim( 0, 10 )
        xticks( [] )
        yticks( linspace( 0.5, 1.5, 3 ) )
        n = n+1
        bar( arange(0.5,9.5,1), frames[:,i,j], width=0.6, color='black', alpha=0.4, lw=0)

fig.tight_layout()

savefig( 'Spaceplate1_48.png', format='png', dpi=100 )
savefig( 'Spaceplate1_48.pdf', format='pdf', dpi=100 )


Time serise plot


In [109]:
import numpy
import csv

# import species metadata and plate map
spacebugs = []
with open('spacebugs.tsv', 'rb') as csvfile :
    csvreader = csv.reader(csvfile, delimiter='\t', quotechar='|')
    for row in csvreader:
        spacebugs.append( { 'source' : row[1], 'species' : row[2], 'name' : row[3], 'data' : [] } )

platemap = zeros((8,12),dtype=numpy.int)
with open('platemap.tsv', 'rb') as csvfile :
    csvreader = csv.reader(csvfile, delimiter='\t', quotechar='|')
    for i,row in enumerate(csvreader) :
        for j,n in enumerate(map(int,row)) :
            platemap[i,j] = n

# import plate data
plateN = '3'
expN = 'S'
name = 'Space Plate 3'
prefix = 'Spaceplate3_timeseries'

files = [ ( 0,  'Spaceplate3_0.txt'),
          ( 24, 'Spaceplate3_24.txt'), 
          ( 48, 'Spaceplate3_48.txt'),
          ( 72, 'Spaceplate3_72.txt'),
          ( 96, 'Spaceplate3_96.txt') ]

#stupid_delimeter = '\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t\n'

stupid_delimeter = '\t\t\n\t\t\n'

stop_at = 273 # in case the run was not completed, stop here

data = []
for TT,file in files :

    blob = open( file ).read()
    block = blob.split('End')[0]  # different versions of the plate reader software put End tokens in different places

    ttimes = []
    ttemps = []
    frames = []

    for tn,tpoint in enumerate(block.split(stupid_delimeter)[:stop_at]) :
        if tn == 0 : # skip header stuff
            tpoint = tpoint.split('12\t\t\n')[1]
        if tn == 9 : break # stop after nine frames
        frame = numpy.zeros((8,12))
        for rn,row in enumerate(tpoint.split('\n')) :
            for cn,col in enumerate(row.split('\t')) :
                if rn != 0 and cn == 0 : continue
                if rn != 0 and cn == 1 : continue
                if cn == 14 : continue
                if cn == 15 : continue
                if rn == 0 and cn == 0 : ttimes.append(col); continue
                if rn == 0 and cn == 1 : ttemps.append(col); continue
                #print tn,rn,cn-2,col
                frame[rn,cn-2] = float(col)
        frames.append(frame)
    
    frames = numpy.array(frames)
    times = arange( 0, len(frames) / 96.0, 1/96.0 ) # not actual times here...

    data.append(frames)

# collect replicates into spacebugs vector
for i,bug in enumerate(spacebugs) :
    for j in range(len(data)) :
        spacebugs[i]['data'].append([])

for TT,run in enumerate(data) :
    for i in range(8) :
        for j in range(12) :
            n = platemap[i,j]-1
            spacebugs[n]['data'][TT] = spacebugs[n]['data'][TT] + list(run[:,i,j])

In [142]:
# build figure

rownames = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' ]
n = 0

fig, ax = plt.subplots( 8, 12, figsize=(16,9))
fig.suptitle( name, fontsize=12, x=0.05,y=1 )
for i in range(8) :
    for j in range(12) :
        subplot(8,12,n+1)
        #title( rownames[i] + str(j+1) )
        title( expN + plateN + ':' + spacebugs[ platemap[i,j] - 1 ]['name'])
        #ylim( (0,max_val) )
        ylim( ( 0, 2.5 ) )
        #xlim( ( 0, 45 ) )
        xlim( 0, 10 )
        xticks( [] )
        yticks( linspace( 0.5, 2.0, 3 ) )
        n = n+1
        timepoint_data = []
        for run in data :
            timepoint_data.append(run[:,i,j])
        boxplot(timepoint_data)
            

fig.tight_layout()

# save figure
savefig( prefix+'.png', format='png', dpi=100 )
savefig( prefix+'.pdf', format='pdf', dpi=100 )



In [111]:
from scipy import optimize

def N(n,a,x) :
    return n*(1-exp(-a*x))

def residuals( p, y, x ) :
    n, a = p
    err = y - N(n,a,x)
    return err

def Neval(x) :
    return N(N0,a,x)

fig, ax = plt.subplots( 4, 12, figsize=(16,5))
fig.suptitle( name, fontsize=12, x=0.05,y=1 )

best_huddle = ('',0,0)
best_tipoff = ('',0,0)
best_alpha  = ('',0,0)
best_Hsat   = ('',10000,0)
best_N0     = ('',0,0)
for n,bug in enumerate(spacebugs) :
    subplot(4,12,n+1)
    ylim((0,2.5))
    yticks( linspace( 0.5, 2.0, 3 ) )
    boxplot(bug['data'])
    medians = map( median, bug['data'] )
    bug['huddle'] = max(medians) - min(medians)
    bug['tipoff'] = medians[1] - medians[0]
    
    # least squares fit to exponential saturation model
    N0, a = optimize.leastsq(residuals, [1,1], args=(array(medians),array([1,2,3,4,5])))[0]
    Hsat = -log(e**(-a)/2.0)/a
    
    bug['alpha'] = a # time constant
    bug['N0'] = N0 # saturation value
    bug['Hsat'] = Hsat    

    if bug['Hsat'] > 1.6 and bug['alpha'] < 1.5 :
        title(bug['name'])
        bug['alive'] = True
    else :
        title(bug['name'], alpha=0.2)
        bug['alive'] = False

    if best_huddle[1] < bug['huddle'] and bug['alive'] : best_huddle = ( bug['name'], bug['huddle'], n )
    if best_tipoff[1] < bug['tipoff'] and bug['alive'] : best_tipoff = ( bug['name'], bug['tipoff'], n )
    if best_alpha[1]  < bug['alpha']  and bug['alive'] : best_alpha  = ( bug['name'], bug['alpha'], n )
    if best_N0[1]     < bug['N0']     and bug['alive'] : best_N0     = ( bug['name'], bug['N0'],    n )
    if best_Hsat[1]   > bug['Hsat']   and bug['alive'] : best_Hsat   = ( bug['name'], bug['Hsat'],  n )
        
    plot( [1,2,3,4,5], medians, 'green')
    
    plot(linspace(1,5),Neval(linspace(1,5)),'red')
    axvline(bug['Hsat'], color='black', linestyle=':')
    
subplot(4,12,best_huddle[2]+1)
title(best_huddle[0],color='red')

subplot(4,12,best_tipoff[2]+1)
title(best_tipoff[0],color='blue')

subplot(4,12,best_alpha[2]+1)
title(best_Hsat[0],color='green')

fig.tight_layout()

# save figure
savefig( prefix+'_names.png', format='png', dpi=100 )
savefig( prefix+'_names.pdf', format='pdf', dpi=100 )



In [92]:
for n,bug in enumerate(spacebugs) :
    print n, bug['name'], bug['alpha'], bug['Hsat']

spacebugs[43]


0 OB179 0.538832783233 2.28638643032
1 MER TA 8-2 0.432335547835 2.60326205891
2 MER TA 21 0.272242600284 3.54606435523
3 273.1.3 0.332798382911 3.08278410038
4 MER TA 108 0.820989493911 1.84428264393
5 MER 157 0.653454527309 2.06074279325
6 InSight12-2 0.351334129214 2.97290021926
7 MER TA 28 0.686799176865 2.00924288192
8 SK5 0.50386403108 2.37566315078
9 THU 0.352196828901 2.96806763628
10 Spurs2 0.512341193644 2.3529015218
11 YNLA1 0.428109105917 2.6190900193
12 YNNY5 0.379388172716 2.82701315014
13 YNNC1 0.348724385991 2.98766478172
14 ORL2 0.163693579167 5.23441887023
15 ANS3A 0.35287547257 2.96428268452
16 CHF3A 0.294067042337 3.35710596825
17 DMNS8A 1.15969682467 1.59769688579
18 FI1B 0.405917039322 2.70760799231
19 Kit3 0.341696690028 3.02854520043
20 LB3A 0.407565859492 2.70069981186
21 Phillies10A 1.13055255957 1.61310478198
22 SN8 0.304183236429 3.27871591051
23 MI1C 0.587180555503 2.1804668497
24 PWS2AY 0.363083061541 2.9090595348
25 PWLB1C 0.593929316464 2.16705331989
26 Chit1C 0.365441867185 2.89673719078
27 FN1H 0.177940034372 4.89539758721
28 PM1B 0.179221683897 4.8675408326
29 PWA1C 0.143962847362 5.81476431773
30 PWCor2B 0.240712203554 3.87956809138
31 PW-PWB2A2 0.431428105245 2.60663427378
32 SMI9 0.544287209878 2.27349525761
33 FM1B 0.587771487727 2.1792800349
34 CH2B 0.352994796794 2.96361869029
35 D1B 0.875599923851 1.79162544637
36 G4B 0.612854011913 2.13101516362
37 RAID3B 0.328974505403 3.10699360946
38 DIS2A 0.460798279374 2.50423126905
39 MONT1D 1.03415405486 1.67025524612
40 WHYY3B 0.538983602764 2.28602647094
41 ATT5A 0.412590458014 2.67998839308
42 RED1C 0.17714828395 4.91280776254
43 TOD3A 0.252332719388 3.74695720096
44 STJO1A 0.491187328177 2.41116665842
45 PATS2B 0.540862084895 2.28155993906
46 TIT1C 0.418123789267 2.65775590472
47 COR2C 0.568432121753 2.21940184946
Out[92]:
{'Hsat': 3.7469572009561194,
 'N0': 2.5019973218415918,
 'alive': True,
 'alpha': 0.25233271938808693,
 'data': [[0.41210000000000002,
   0.30549999999999999,
   0.50729999999999997,
   0.37869999999999998,
   0.30409999999999998,
   0.36620000000000003,
   0.56269999999999998,
   0.4854,
   0.66010000000000002,
   0.81210000000000004,
   0.64070000000000005,
   0.61850000000000005,
   0.60009999999999997,
   0.55859999999999999,
   0.52500000000000002,
   0.67569999999999997,
   0.57640000000000002,
   0.61929999999999996],
  [0.63470000000000004,
   0.48209999999999997,
   0.79590000000000005,
   0.76219999999999999,
   0.5867,
   0.72219999999999995,
   1.0983000000000001,
   0.72999999999999998,
   1.0216000000000001,
   1.0919000000000001,
   0.995,
   1.3197000000000001,
   0.81100000000000005,
   0.78390000000000004,
   0.85870000000000002,
   0.93169999999999997,
   0.64019999999999999,
   0.91779999999999995],
  [1.5027999999999999,
   1.468,
   1.4398,
   1.5742,
   1.5125999999999999,
   1.5589,
   1.4829000000000001,
   1.4598,
   1.7386999999999999,
   1.5886,
   1.5774999999999999,
   1.6418999999999999,
   1.5855999999999999,
   1.5729,
   1.5515000000000001,
   1.5112000000000001,
   1.5531999999999999,
   1.5274000000000001],
  [1.5468999999999999,
   1.5349999999999999,
   1.4658,
   1.6698999999999999,
   1.5967,
   1.669,
   1.4934000000000001,
   1.5589999999999999,
   1.8230999999999999,
   1.6056999999999999,
   1.6119000000000001,
   1.6799999999999999,
   1.6086,
   1.5705,
   1.5294000000000001,
   1.5366,
   1.5966,
   1.5301],
  [1.7210000000000001,
   1.7084999999999999,
   1.6704000000000001,
   1.7656000000000001,
   1.7237,
   1.7816000000000001,
   1.6489,
   1.6899999999999999,
   1.8413999999999999,
   1.7431000000000001,
   1.7406999999999999,
   1.7829999999999999,
   1.7496,
   1.7323999999999999,
   1.7696000000000001,
   1.7271000000000001,
   1.7618,
   1.7116]],
 'huddle': 1.1758999999999999,
 'name': 'TOD3A',
 'source': 'Today Show',
 'species': 'Bacillus tequilensis',
 'tipoff': 0.24280000000000002}

In [ ]: