<jupyter_start><jupyter_text>During this vignette we will repeat the PBMC inter-dataset experiment. We use three datasets to construct a classification tree and use this tree to predict the labels of a fourth dataset. The aligned datasets and labels can be downloaded from https://doi.org/10.5281/zenodo.4557712  Read the dataWe start with reading the different datasets, corresponding labels and them to a list.In the datasets, the rows represent different cells and columns represent the genes<jupyter_code>data0 = 'Data_EQTL.csv'
labels0 = 'Labels_EQTL.csv'

data1 = 'Data_10Xv2.csv'
labels1 = 'Labels_10Xv2.csv'

data2 = 'Data_FACS.csv'
labels2 = 'Labels_FACS.csv'

data = []
labels = []

data.append((pd.read_csv(data0, index_col=0, sep=',')))
labels.append(pd.read_csv(labels0, header=0, index_col=None, sep=','))

data.append((pd.read_csv(data1, index_col=0, sep=',')))
labels.append(pd.read_csv(labels1, header=0, index_col=None, sep=','))

data.append((pd.read_csv(data2, index_col=0, sep=',')))
labels.append(pd.read_csv(labels2, header=0, index_col=None, sep=','))<jupyter_output><empty_output><jupyter_text>Construct and train the classification treeNext, we use hierarchical progressive learning to construct and train a classification tree. After each iteration, an updated tree will be printed. If two labels have a perfect match, one of the labels will not be visible in the tree. Therefore, we will also indicate these perfect matches using a print statementDuring this experiment, we used the linear SVM, didn't apply dimensionality reduction and used the default threshold of 0.25. In you want to use a one-class SVM instead of a linear, the following can be used: classifier = 'svm_occ'<jupyter_code>start = tm.time()

classifier = 'svm'
dimred = False
threshold = 0.25
tree = progressive_learning.learn_tree(data, labels, 
                                       classifier = classifier, 
                                       dimred = dimred, 
                                       threshold = threshold)

training_time = tm.time()-start
print('Time to train scHPL on a normal desktop:', training_time)<jupyter_output>Iteration  1 

Perfect match:  B cell - B-10Xv2 is now: B cell - eQTL
Perfect match:  Megakaryocyte - B-10Xv2 is now: Megakaryocyte - eQTL
Perfect match:  CD4+ T cell - B-10Xv2 is now: CD4+ T cell - eQTL
Perfect match:  CD8+ T cell - B-10Xv2 is now: CD8+ T cell - eQTL

Updated tree:
root
	B cell - eQTL
	CD4+ T cell - eQTL
	CD8+ T cell - eQTL
	Megakaryocyte - eQTL
	pDC - eQTL
	Monocyte - B-10Xv2
		CD14+ Monocyte - eQTL
		CD16+ Monocyte - eQTL
		mDC - eQTL
	NK cell - B-10Xv2
		CD56+ bright NK cell - eQTL
		CD56+ dim NK cell - eQTL
Iteration  2 

Perfect match:  B cell - FACS is now: B cell - eQTL
Perfect match:  CD14+ Monocyte - FACS is now: Monocyte - B-10Xv2
Perfect match:  CD34+ cell - FACS is now: pDC - eQTL

Updated tree:
root
	B cell - eQTL
	CD4+ T cell - eQTL
		CD4+/CD25 T Reg - FACS
		CD4+/CD45RA+/CD25- Naive T - FACS
		CD4+/CD45RO+ Memory - FACS
		CD8+/CD45RA+ Naive Cytotoxic - FACS
	Megakaryocyte - eQTL
	pDC - eQTL
	Monocyte - B-10Xv2
		CD14+ Monocyte - eQTL
		CD16+ Monocyte - [...]<jupyter_text>Predict the labels of the fourth datasetIn this last step, we use the learned tree to predict the labels of another dataset<jupyter_code>data3 = 'Data_10Xv3.csv'
data_test = pd.read_csv(data3, index_col=0, sep=',')

start = tm.time()
pred_test = predict.predict_labels(data_test, tree)
pred_time = tm.time()-start
print('Time to make predictions with scHPL on a normal desktop:', pred_time)<jupyter_output>Time to make predictions with scHPL on a normal desktop: 4.310481309890747<jupyter_text>We compare these true and predicted labels by constructing a confusion matrix<jupyter_code>labels3 = 'Labels_10Xv3.csv'
y_true = pd.read_csv(labels3, header=0, index_col=None, sep=',')
y_pred = pd.DataFrame(data = pred_test)

confmatrix = evaluate.confusion_matrix(y_true, y_pred)
confmatrix = confmatrix / np.sum(confmatrix.values, axis = 1, keepdims=True) #Normalize<jupyter_output><empty_output><jupyter_text>This confusion matrix can be visualized using a heatmap.In this heatmap, we notice that the predictions of the CD16+ Monocytes and mDC are switched, which is caused by the mislabeling of the cells in the eQTL dataset.<jupyter_code>import seaborn as sns
import matplotlib.pyplot as plt

plt.figure(figsize=(12,4.5))
sns.heatmap(round(confmatrix,2), vmin = 0, vmax = 1, annot=True)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09384752563530985, 'fraction_numerical': 0.03209986625055729, 'mean_word_length': 4.11630558722919, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '409582', 'license': 'MIT', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1518, 'n_words': 509, 'path': 'vignettes/pbmc inter-dataset.ipynb', 'repo_name': 'lcmmichielsen/scHPL', 'size': '4486'}