This repository has been archived on 2024-07-04. You can view files and clone it, but cannot push or open issues or pull requests.
laydi/fluents/lib/blmplots.py

159 lines
5.5 KiB
Python

"""Specialised plots for functions defined in blmfuncs.py.
fixme:
-- Im normalsing all color mapping input vectors to [0,1]. This will
destroy informative numerical values in colorbar (but we
are not showing these anyway). A better fix would be to let the
colorbar listen to the scalarmappable instance and corect itself, but
I did not get that to work ...
fixme2:
-- If scatterplot is not inited with a colorvector there will be no
colorbar, but when adding colors the colorbar shoud be created.
"""
from fluents import plots
from scipy import dot,sum,diag,arange,log,mean,newaxis
from matplotlib import cm
class PcaScorePlot(plots.ScatterPlot):
"""PCA Score plot"""
def __init__(self, model, absi=0, ordi=1):
self._T = model.model['T']
dataset_1 = model.as_dataset('T')
dataset_2 = dataset_1
id_dim = dataset_1.get_dim_name(0)
sel_dim = dataset_1.get_dim_name(1)
id_1, = dataset_1.get_identifiers(sel_dim, [absi])
id_2, = dataset_1.get_identifiers(sel_dim, [ordi])
plots.ScatterPlot.__init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2 ,c='b' ,s=40 , name='pca-scores')
def set_absicca(self,n):
self.xaxis_data = self._T[:,n]
def set_ordinate(self,n):
self.yaxis_data = self._T[:,n]
class PcaLoadingPlot(plots.ScatterPlot):
"""PCA Loading plot"""
def __init__(self, model, absi=0, ordi=1):
self._P = model.model['P']
dataset_1 = model.as_dataset('P')
dataset_2 = dataset_1
id_dim = dataset_1.get_dim_name(0)
sel_dim = dataset_1.get_dim_name(1)
id_1, = dataset_1.get_identifiers(sel_dim, [absi])
id_2, = dataset_1.get_identifiers(sel_dim, [ordi])
if model.model.has_key('p_tsq'):
col = model.model['p_tsq'].ravel()
col = normalise(col)
else:
col = 'g'
plots.ScatterPlot.__init__(self, dataset_1, dataset_2, id_dim, sel_dim, id_1, id_2,c=col,s=20, name='pls-loadings')
def set_absicca(self,n):
self.xaxis_data = self._P[:,n]
def set_ordinate(self,n):
self.yaxis_data = self._P[:,n]
class PlsScorePlot(plots.ScatterPlot):
"""PLS Score plot"""
def __init__(self,model, absi=0, ordi=1):
self._T = model.model['T']
dataset_1 = model.as_dataset('T')
dataset_2 = dataset_1
id_dim = dataset_1.get_dim_name(0)
sel_dim = dataset_1.get_dim_name(1)
id_1, = dataset_1.get_identifiers(sel_dim, [absi])
id_2, = dataset_1.get_identifiers(sel_dim, [ordi])
plots.ScatterPlot.__init__(self, dataset_1, dataset_2,
id_dim, sel_dim, id_1, id_2 ,
c='b' ,s=40 , name='pls-scores')
def set_absicca(self,n):
self.xaxis_data = self._T[:,n]
def set_ordinate(self,n):
self.yaxis_data = self._T[:,n]
class PlsLoadingPlot(plots.ScatterPlot):
"""PLS Loading plot"""
def __init__(self,model,absi=0,ordi=1):
self._P = model.model['P']
dataset_1 = model.as_dataset('P')
dataset_2 = dataset_1
id_dim = dataset_1.get_dim_name(0)
sel_dim = dataset_1.get_dim_name(1)
id_1, = dataset_1.get_identifiers(sel_dim, [absi])
id_2, = dataset_1.get_identifiers(sel_dim, [ordi])
if model.model.has_key('w_tsq'):
col = model.model['w_tsq'].ravel()
col = normalise(col)
else:
col = 'g'
plots.ScatterPlot.__init__(self, dataset_1, dataset_2,
id_dim, sel_dim, id_1, id_2,
c=col, s=20, name='loadings')
def set_absicca(self,n):
self.xaxis_data = self._P[:,n]
def set_ordinate(self,n):
self.yaxis_data = self._T[:,n]
class LineViewXc(plots.LineViewPlot):
"""A line view of centered raw data
"""
def __init__(self, func_class, name='Profiles'):
# copy, center, plot
x = func_class._dataset['X'].copy()
x._array = x._array - mean(x._array,0)[newaxis]
plots.LineViewPlot.__init__(self, x, 1, None, name)
class ParalellCoordinates(plots.Plot):
"""Parallell coordinates for score loads with many comp.
"""
def __init__(self,model, p = 'loads'):
pass
class PlsQvalScatter(plots.ScatterPlot):
"""A vulcano like plot of loads vs qvals
"""
def __init__(self, func_class, pc=0):
model = func_class.model
if not model.has_key('w_tsq'):
return
self._W = model['P']
dataset_1 = func_class.as_dataset('P')
dataset_2 = func_class.as_dataset('w_tsq')
id_dim = dataset_1.get_dim_name(0) #genes
sel_dim = dataset_1.get_dim_name(1) #_comp
sel_dim_2 = dataset_2.get_dim_name(1) #_zero_dim
id_1, = dataset_1.get_identifiers(sel_dim, [0])
id_2, = dataset_2.get_identifiers(sel_dim_2, [0])
if model.has_key('w_tsq'):
col = model['w_tsq'].ravel()
col = normalise(col)
else:
col = 'g'
plots.ScatterPlot.__init__(self, dataset_1, dataset_2,
id_dim, sel_dim, id_1, id_2,
c=col, s=20, sel_dim_2=sel_dim_2,
name='Load Volcano')
class InfluencePlot(plots.ScatterPlot):
"""
"""
pass
def normalise(x):
"""Scale vector x to [0,1]
"""
x = x - x.min()
x = x/x.max()
return x