Skip to content
This repository has been archived by the owner on Feb 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #26 from ManuSetty/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ManuSetty authored Jul 20, 2016
2 parents ec1df6c + 940597a commit e5c3fe3
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 85 deletions.
Binary file modified docs/wishbone_tutorial.pptx
Binary file not shown.
11 changes: 9 additions & 2 deletions notebooks/Wishbone_for_single_cell_RNAseq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,14 @@
],
"source": [
"NO_CMPNTS = 5\n",
"scdata.run_tsne(n_components=NO_CMPNTS)"
"scdata.run_tsne(n_components=NO_CMPNTS, perplexity=30)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`perplexity` by default is set 30. This will be reduced automatically to 15 is the number of cells is less than 100. "
]
},
{
Expand Down Expand Up @@ -1010,7 +1017,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.2"
"version": "3.5.0"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


setup(name='wishbone',
version='0.3',
version='0.4',
description='Wishbone algorithm for identifying bifurcating trajectories from single-cell data',
author='Manu Setty',
author_email='manu.setty@columbia.edu',
Expand Down
2 changes: 1 addition & 1 deletion src/wishbone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from . import wishbone_gui
from . import autocomplete_entry

__version__ = "0.3"
__version__ = "0.4"
35 changes: 25 additions & 10 deletions src/wishbone/wb.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ def save(self, fout: str):# -> None:
with open(fout, 'wb') as f:
pickle.dump(vars(self), f)

def save_as_wishbone(self, fout: str):
"""
:param fout: str, name of archive to store pickled Wishbone data in. Should end
in '.p'.
:return: None
"""
wb = wishbone.wb.Wishbone(self, True)
wb.save(fout)


@classmethod
def load(cls, fin):
"""
Expand Down Expand Up @@ -151,7 +161,7 @@ def data(self):
def data(self, item):
if not (isinstance(item, pd.DataFrame)):
raise TypeError('SCData.data must be of type DataFrame')
self._reads = item
self._data = item

@property
def metadata(self):
Expand Down Expand Up @@ -259,6 +269,7 @@ def from_fcs(cls, fcs_file, cofactor=5,

# Parse the fcs file
text, data = fcsparser.parse( fcs_file )
data = data.astype(np.float64)

# Extract the S and N features (Indexing assumed to start from 1)
# Assumes channel names are in S
Expand All @@ -279,7 +290,7 @@ def from_fcs(cls, fcs_file, cofactor=5,
data = data[data_channels]

# Transform if necessary
if cofactor is not None:
if cofactor is not None or cofactor > 0:
data = np.arcsinh(np.divide( data, cofactor ))

# Create and return scdata object
Expand Down Expand Up @@ -381,7 +392,7 @@ def plot_pca_variance_explained(self, n_components=30,



def run_tsne(self, n_components=15):
def run_tsne(self, n_components=15, perplexity=30):
""" Run tSNE on the data. tSNE is run on the principal component projections
for single cell RNA-seq data and on the expression matrix for mass cytometry data
:param n_components: Number of components to use for running tSNE for single cell
Expand All @@ -399,8 +410,12 @@ def run_tsne(self, n_components=15):
data = pd.DataFrame(np.dot(data, self.pca['loadings'].iloc[:, 0:n_components]),
index=self.data.index)

print('If running in notebook, please look at the command line window for tSNE progress log')
self.tsne = pd.DataFrame(bh_sne(data),
# Reduce perplexity if necessary
perplexity_limit = 15
if data.shape[0] < 100 and perplexity > perplexity_limit:
print('Reducing perplexity to %d since there are <100 cells in the dataset. ' % perplexity_limit)
perplexity = perplexity_limit
self.tsne = pd.DataFrame(bh_sne(data, perplexity=perplexity),
index=self.data.index, columns=['x', 'y'])

def plot_tsne(self, fig=None, ax=None, title='tSNE projection'):
Expand Down Expand Up @@ -918,12 +933,12 @@ def plot_gene_expression(self, genes):

class Wishbone:

def __init__(self, scdata):
def __init__(self, scdata, ignore_dm_check=False):
"""
Container class for Wishbone
:param data: SCData object
"""
if scdata.diffusion_eigenvectors is None:
if not ignore_dm_check and scdata.diffusion_eigenvectors is None:
raise RuntimeError('Please use scdata with diffusion maps run for Wishbone')

self._scdata = scdata
Expand Down Expand Up @@ -958,11 +973,11 @@ def load(cls, fin):
"""
with open(fin, 'rb') as f:
data = pickle.load(f)
scdata = cls(data['_scdata'])
wb = cls(data['_scdata'], True)
del data['_scdata']
for k, v in data.items():
setattr(scdata, k[1:], v)
return scdata
setattr(wb, k[1:], v)
return wb

@property
def scdata(self):
Expand Down
Loading

0 comments on commit e5c3fe3

Please sign in to comment.