Ref: Olsson, A. et al. Single-cell analysis of mixed-lineage states leading to a binary cell fate choice. Nature (2016).

In [1]:
%matplotlib inline

In [2]:
import stream as st
st.__version__

Out[2]:
'0.3.5'
In [3]:
adata=st.read(file_name='./data_Olsson.tsv.gz')

Using default working directory.
Saving results in: /Users/hardy/Desktop/tutorial/2/stream_result

In [4]:
st.add_cell_labels(adata,file_name='./cell_label.tsv.gz')

In [5]:
st.filter_genes(adata,min_num_cells = max(5,int(round(adata.shape[0]*0.001))),
min_pct_cells = None,expr_cutoff = 1)

Filter genes based on min_num_cells
After filtering out low-expressed genes:
382 cells, 12188 genes

In [6]:
st.select_variable_genes(adata)

610 variable genes are selected

In [7]:
st.dimension_reduction(adata,n_components=4)

4 cpus are being used ...

In [8]:
st.plot_dimension_reduction(adata)

In [9]:
st.seed_elastic_principal_graph(adata)

Seeding initial elastic principal graph...
Clustering...
Affinity propagation ...
The number of initial nodes is 16
Calculatng minimum spanning tree...
Number of initial branches: 5

In [10]:
st.elastic_principal_graph(adata)

Learning elastic principal graph...
[1]
"Constructing tree 1 of 1 / Subset 1 of 1"

[1]
"Computing EPG with 50 nodes on 382 points and 4 dimensions"

[1]
"Using a single core"

Nodes =
16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

BARCODE	ENERGY	NNODES	NEDGES	NRIBS	NSTARS	NRAYS	NRAYS2	MSE	MSEP	FVE	FVEP	UE	UR	URN	URN2	URSD

2||50

0.000868

50

49

44

2

0

0

0.0004798

0.0004605

0.9543

0.9561

0.0003388

4.937e-05

0.002469

0.1234

0

17.246 sec elapsed

[[1]]

Number of branches after learning elastic principal graph: 5

In [11]:
st.plot_branches(adata)

In [12]:
st.optimize_branching(adata)

Optimizing branching...
[1]
"Constructing tree 1 of 1 / Subset 1 of 1"

[1]
"Computing EPG with 80 nodes on 382 points and 4 dimensions"

[1]
"Using a single core"

Nodes =
50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

BARCODE	ENERGY	NNODES	NEDGES	NRIBS	NSTARS	NRAYS	NRAYS2	MSE	MSEP	FVE	FVEP	UE	UR	URN	URN2	URSD

2||80

0.0005297

80

79

74

2

0

0

0.0003183

0.0003067

0.9697

0.9708

0.0001684

4.307e-05

0.003446

0.2756

0

3.329 sec elapsed

Number of branches after optimizing branching: 5

In [13]:
st.shift_branching(adata)

Shifting branching point to denser area ...
[1]
"Moving the branching point at node 4"

[1]
"Moving the branching point at node 6"

[1]
"Constructing tree 1 of 1 / Subset 1 of 1"

[1]
"Computing EPG with 73 nodes on 382 points and 4 dimensions"

[1]
"Using a single core"

0.014 sec elapsed

Number of branches after shifting branching: 5

In [14]:
st.extend_elastic_principal_graph(adata)

Extending leaves with additional nodes ...
Number of branches after extending leaves: 5

In [15]:
st.plot_flat_tree(adata)

/Users/hardy/anaconda3/envs/stream/lib/python3.6/site-packages/networkx/drawing/nx_pylab.py:611: MatplotlibDeprecationWarning: isinstance(..., numbers.Number)
if cb.is_numlike(alpha):