In [72]:
import os
import sys
# import webbrowser
import shutil
import pandas as pd
# import pdb
In [73]:
%matplotlib inline
In [74]:
from matplotlib import pyplot
In [75]:
#LIBPATH = os.path.abspath("../..")
scriptdir = os.path.abspath(".")
examples_dir = os.path.dirname(scriptdir)
LIBPATH = os.path.dirname(examples_dir)
print("LIBDIR:", LIBDIR)
print("Scriptdir:", scriptdir)
#sys.path.insert(0, LIBPATH)
In [76]:
from nascent.stat_analysis.processing import get_datafile
In [77]:
structure = "circfb_1"
structure = "fourway_junction_1"
runidxs = [-1] #
# runidxs = [-2] #
statsfiles, statsfolders = zip(*[
get_datafile(statsfile="monitored_strands_stats.tsv", runidx=runidx,
basedir=scriptdir, structure=structure)
for runidx in runidxs])
In [78]:
print(statsfiles)
stats = [pd.read_table(statsfile) for statsfile in statsfiles] # http://pandas.pydata.org/pandas-docs/stable/io.html
runstats = stats[0]
In [79]:
runstats['system_time_end'] = runstats['system_time'].shift(-1).dropna()
data_by_strand = runstats.groupby(['strand_uid'], sort=False)
strand, s_trace = next(iter(data_by_strand))
s_state_traces = s_trace.groupby(['complex_state'], sort=False)
In [80]:
for cstate, s_state in s_state_traces:
# s_state['s_state_time_cum'] = s_state['tau'].cumsum()
# s_state['s_state_partition'] = s_state['s_state_time_cum']/s_state['system_time_end']
# Edit: Avoid using chained indexing:
# s_state may be a copy
# s_state.loc[:,'s_state_time_cum'] = s_state.loc[:'tau'].cumsum()
# TypeError: cannot do slice indexing on <class 'pandas.core.index.Int64Index'> with these indexers [tau] of <class 'str'>
# s_state.loc[:,'s_state_time_cum'] = s_state['tau'].cumsum() # Still get SettingWithCopyWarning
s_state_time_cum = s_state['tau'].cumsum() # You can just use the copy as-is and make a column..
# s_state['s_state_partition'] = s_state['s_state_time_cum']/s_state['system_time_end']
In [96]:
c_state_sums = s_state_traces.sum()
# c_state_sums.sort_values(['tau']) # Multiple columns OK
sums_view = c_state_sums.sort_values('tau', ascending=False)
#print(sums_view.head(10)) # Single column string also OK
sums_view[['tau']].head() # pretty table view
print(sums_view[['tau']].head()) # prints a 'tau' header
# print(sums_view['tau'].head()) # no column headers
In [ ]:
In [ ]:
In [ ]: