<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>Optimal tuning of weighted kNN- and diffusion-based methods for denoising single cell genomics data</title></titleStmt>
			<publicationStmt>
				<publisher></publisher>
				<date>01/07/2021</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10295907</idno>
					<idno type="doi">10.1371/journal.pcbi.1008569</idno>
					<title level='j'>PLOS Computational Biology</title>
<idno>1553-7358</idno>
<biblScope unit="volume">17</biblScope>
<biblScope unit="issue">1</biblScope>					

					<author>Andreas Tjärnberg</author><author>Omar Mahmood</author><author>Christopher A. Jackson</author><author>Giuseppe-Antonio Saldi</author><author>Kyunghyun Cho</author><author>Lionel A. Christiaen</author><author>Richard A. Bonneau</author><author>Qing Nie</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[The analysis of single-cell genomics data presents several statistical challenges, and extensive efforts have been made to produce methods for the analysis of this data that impute missing values, address sampling issues and quantify and correct for noise. In spite of such efforts, no consensus on best practices has been established and all current approaches vary substantially based on the available data and empirical tests. The k-Nearest Neighbor Graph (kNN-G) is often used to infer the identities of, and relationships between, cells and is the basis of many widely used dimensionality-reduction and projection methods. The kNN-G has also been the basis for imputation methods using,              e.g              ., neighbor averaging and graph diffusion. However, due to the lack of an agreed-upon optimal objective function for choosing hyperparameters, these methods tend to oversmooth data, thereby resulting in a loss of information with regard to cell identity and the specific gene-to-gene patterns underlying regulatory mechanisms. In this paper, we investigate the tuning of kNN- and diffusion-based denoising methods with a novel non-stochastic method for optimally preserving biologically relevant informative variance in single-cell data. The framework,              Denoising Expression data with a Weighted Affinity Kernel and Self-Supervision              (DEWÄKSS), uses a self-supervised technique to tune its parameters. We demonstrate that denoising with optimal parameters selected by our objective function (i) is robust to preprocessing methods using data from established benchmarks, (ii) disentangles cellular identity and maintains robust clusters over dimension-reduction methods, (iii) maintains variance along several expression dimensions, unlike previous heuristic-based methods that tend to oversmooth data variance, and (iv) rarely involves diffusion but rather uses a fixed weighted kNN graph for denoising. Together, these findings provide a new understanding of kNN- and diffusion-based denoising methods. Code and example data for DEWÄKSS is available at              https://gitlab.com/Xparx/dewakss/-/tree/Tjarnberg2020branch              .]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">Introduction</head><p>Single-cell RNA-seq (scRNA-seq) experimental methods measure gene expression in individual cells from heterogeneous samples. This allows identification of different cell subpopulations, and has been extensively used to map developmental trajectories. scRNA-seq experiments yield data with hundreds to hundreds of thousands of individual cell observations; however, the measured gene expression in each cell is noisy, due to undersampling caused by the extremely low quantities of RNA present in any individual cell <ref type="bibr">[1]</ref>. Many computational applications have been developed that leverage the advantages of scRNA-seq experiments <ref type="bibr">[2]</ref><ref type="bibr">[3]</ref><ref type="bibr">[4]</ref><ref type="bibr">[5]</ref>. Analysis has primarily focused on the interpretation of the cellular landscape; software suites incorporating customizable workflows have been developed to enable this analysis <ref type="bibr">[3,</ref><ref type="bibr">6,</ref><ref type="bibr">7]</ref>. Denoising computational approaches to mitigating the sparsity of singlecell data (having few counts per cell) have corrected structural and sampling zeros <ref type="bibr">[8]</ref>, imputed missing values <ref type="bibr">[9]</ref><ref type="bibr">[10]</ref><ref type="bibr">[11]</ref>, or corrected measured expression values <ref type="bibr">[12]</ref><ref type="bibr">[13]</ref><ref type="bibr">[14]</ref>. The modeling and motivational assumptions of these approaches vary and include cell-cell similarity, gene covariance, and temporal/trajectory stability.</p><p>In any individual cell, some genes will not be detected <ref type="bibr">[15]</ref>; genes that have been biologically silenced or repressed and genes that have low stochastic expression may have zero expressed transcripts. Other genes have expressed transcripts in the cell but are measured as zero due to the sampling depth. For some scRNA-seq experimental techniques, there is evidence of zero inflation in measured expression levels <ref type="bibr">[15]</ref>, but newer droplet-based scRNAseq methods do not appear to have more zero expression measurements than expected by chance <ref type="bibr">[16]</ref>. Single-cell gene expression measurements are a function of transcript sampling depth, which varies widely from technique to technique, stochastic noise in transcript abundance within individual cells, and technical noise which affects genes of all expression levels. Some single-cell denoising methods consider measured zeros to be sampling 'dropouts', and only function to impute non-zero values in place of zero values; these bias corrections to lowexpression genes, suppressing variance for these genes by over-correcting zeros and failing to denoise the data in a biologically relevant manner. Other methods are holistic, using the overall expression profile of all genes to guide denoising, including those which are highly expressed.</p><p>The results of these denoising methods for scRNA-seq data vary considerably based on the choice of hyperparameter values, and some methods require selection of an appropriate noise model. Empirical determination of hyperparameter values and noise models may not result in the most optimally denoised results. However, if we define an objective function that measures the performance of our algorithm, we can find an optimal model by choosing hyperparameters that maximize this objective. Self-supervision allows autoencoders to select model parameters to optimally denoise data by using an objective function based on the loss after reconstruction from a lower-dimensional manifold, and these methods have been applied to both genomics in general <ref type="bibr">[12]</ref> and single-cell data specifically <ref type="bibr">[9,</ref><ref type="bibr">17]</ref>. However, the self-supervision of an autoencoder does not optimise for the choice of model hyperparameters, such as the loss function or the numbers of units and layers, and there is no principled way to tune these hyperparameters for a given dataset.</p><p>One of the most fundamental components of the single cell analysis framework is the k-Nearest Neighbor Graph (kNN-G), which connects each cell to the k cells near it based on the distance between their gene expression profiles. It is used to drive neighbor embedding methods that show the global structure of the data in a low-dimensionality projection <ref type="bibr">[18]</ref>, to detect communities or clusters of related cells <ref type="bibr">[19,</ref><ref type="bibr">20]</ref>, and to establish trajectories through network connections that represent changes over time <ref type="bibr">[21]</ref><ref type="bibr">[22]</ref><ref type="bibr">[23]</ref>. kNN algorithms are an attractive choice for denoising due to their simplicity, in the simplest case only a single parameter needs to be chosen, but it is still difficult to select optimal model hyperparameters, especially with regard to the use of prior knowledge to tune these algorithms <ref type="bibr">[24]</ref>. Diffusion using a kNN-G is the process of averaging over an incrementally larger and larger number of neighbors derived through shared neighbor connections. Looking at a single cell, diffusing using one step means averaging over its neighbors, while a two-step diffusion means averaging over the cells' neighbors and their neighbors. One current method for denoising based on kNN-G is MAGIC <ref type="bibr">[14]</ref>, which diffuses on the kNN-G and maps back to gene expression of single genes. Another denoising approach smooths expression profiles by combining gene expression of kNN-G connected cells <ref type="bibr">[13,</ref><ref type="bibr">25]</ref>. These methods heuristically determine the number of neighbors used, which corresponds to the amount of smoothing applied; this is a drawback when compared to methods that use an objective function that minimizes a desired global objective function.</p><p>In this paper we propose using the noise2self self-supervision principle <ref type="bibr">[26]</ref>. A method that can be used to constructing an objective function which can be minimized and is self-supervised. With this principle in mind, we constructed an objective function to select kNN-G denoising hyperparameters. This does not depend on an explicit noise model but on an invariant and independent function of the features of the data. We apply this underlying principle to optimally set parameters for denoising single-cell data in a framework called Denoising Expression data with a Weighted Affinity Kernel and Self-Supervision (DEWA &#168;KSS), which incorporates a principled self-supervised objective function with weighted kNN-G averaging (Fig <ref type="figure">1</ref>). We evaluate DEWA &#168;KSS using previously established data and benchmark tests, and compare our self-supervised hyperparameter selection method to the state-of-the-art imputation methods MAGIC <ref type="bibr">[5]</ref>, DeepImpute <ref type="bibr">[27]</ref>, DrImpute <ref type="bibr">[11]</ref> and SAVER <ref type="bibr">[28]</ref>. We find that DEWA &#168;KSS performs at par with or better than other state-of-the-art methods, while providing a selfsupervised and hence easily searchable hyper-parameter space, greatly simplifying the application of optimal denoising. We also find that diffusion, although conceptually attractive and previously described as beneficial, is, in fact, not optimal for any method in any setting on any dataset.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">Results</head></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.1">Benchmarking the DEWA &#168;KSS algorithm</head><p>DEWA &#168;KSS takes a normalized expression matrix and calculates a smoothed output expression matrix which has denoised gene expression for each cell. The DEWA &#168;KSS expression matrix will have decreased stochastic sampling noise; expression values, including zeros that are likely the result of undersampling, will be weighted according to their sample-to-sample context. We will test the effectiveness of diffusion and kNN-based (diffusion with step size = 1) denoising methods that are tuned with DEWA &#168;KSS objective function using four separate cases. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.2">DEWA &#168;KSS optimally groups cells and performs robustly, independent of data normalization method</head><p>Before any denoising can occur, single-cell data generally must be normalized. Recent work has established a benchmark for single-cell analysis methods which is broadly applicable to normalization and denoising techniques <ref type="bibr">[29]</ref>. We have therefore compared the performance of DEWA &#168;KSS to several previously-described denoising methods using two benchmark datasets that are generated with different methods. These artificially constructed RNA mixture datasets have a known ground truth; RNAmix_CEL-seq2 is derived from the CEL-Seq2 method <ref type="bibr">[30]</ref> and RNAmix_Sort-seq is derived from the SORT-seq method <ref type="bibr">[31]</ref>. Within each dataset, 'cells' that belong to the same group are samples that have the same proportions of mRNA from three different cell lines. Any differences between 'cells' in the same group can hence be attributed to technical noise.</p><p>Using a computational pipeline <ref type="bibr">[32]</ref>, we test the effect of normalization methods on denoising techniques, with output scoring defined by a known ground truth (Fig <ref type="figure">2</ref>). Normalization methods are generally the same as previously tested <ref type="bibr">[29]</ref>, and include several bulk-RNA normalization methods (TMM, logCPM, DESeq2), several single-cell-specific methods (scone, Linnorm, scran), and a simple Freeman-Tukey transform (FTT). Overall, we find that DEWA &#168;KSS yields expression profiles with high within-group correlation (averaged over all cells in the dataset) independent of the normalization method used, outperforming other denoising methods in the majority of cases (Fig <ref type="figure">2A</ref>). This is not due to high correlation between cells in different groups (which could indicate oversmoothing), as cells of the same type are strongly correlated and cells of different types are weakly correlated when plotted as a heatmap (S1 Fig) . 
DEWA &#168;KSS has three essential input hyperparameters: the number of principal components (PCs) for initial data compression, the number of nearest neighbors to build the graph embedding with (k), and the connection mode for edge weights (either normalized distances or network density weighted connectivities). For this benchmark, the DEWA &#168;KSS algorithm has grid searched through a model hyperparameter space, testing connection mode {distances, connectivities}, number of neighbors {1, 2, . . ., 20, 30, 40, . . ., 150, 200}, and PCs {1, 2, . . ., 20, 30, 40, . . ., 150, 200}. Self-supervision selects optimal model hyperparameters by minimization of mean squared error (MSE); for the RNAmix_Sort-seq dataset that has been normalized by FTT, this is the normalized distance mode with 4 PCs and 80 neighbors (Fig <ref type="figure">2B</ref>). The optimal selection of hyperparameters varies from dataset to dataset and by normalization method (Table <ref type="table">1</ref>). In most cases, the optimal MSE is found for the parameters given by normalized distances with between 50-130 neighbors and 3-13 PCs, but data which has not been normalized has very different optimal model hyperparameters. In general, using normalized distances as edge weights between neighbors outperforms using connectivities. In all cases, the optimal number of diffusion iterations is 1 (no diffusion) given a specific set of PCs and k, indicating that diffusion is not optimal on this data. The small number of PCs and large value for optimal neighbors suggests that this dataset is simplistic with weak local structure, which is a reasonable expectation given the artificial construction of the RNAmix datasets. The MSE is scaled differently depending on the data normalization and should not be compared between methods.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.3">DEWA &#168;KSS maintains cluster homogeneity and deconvolves cluster structure comparably to state-of-the-art methods</head><p>To evaluate DEWA &#168;KSS on higher-complexity data, we adapt the benchmark used by DeepImpute <ref type="bibr">[27]</ref>, using a dataset which contains 33 annotated cell types in primary visual cortex cells from mice (GSE102827) <ref type="bibr">[33]</ref>. We evaluate performance after preprocessing and denoising the count data by defining experimental clusters using the Leiden algorithm <ref type="bibr">[19]</ref>, which tunes the number of clusters based on merging and partitioning the kNN-G to find an optimal partitioning given the resolution parameter r. Differences between annotated cell types and experimental clusters are quantified by the Fowlkes-Mallows score. The silhouette score estimates the relative within-cluster density of the annotated cell-type clusters compared to the closest annotated neighbor-cluster distances-and is, therefore, independent of the cluster algorithm choice-and evaluates the closeness of known cell identities through different data transformations. The silhouette score is separately calculated on two dimension-reduction projections, (i) using 2 UMAP <ref type="bibr">[18]</ref> components, and (ii) using PCA with the number of components used to compute the kNN-G used in the Leiden and UMAP algorithms. A) The average Pearson correlation coefficients between cells that are known to be in the same group, calculated as in Tian et al. <ref type="bibr">[29]</ref> for the RNAmix_CEL-seq2 and RNAmix_Sort-seq benchmark datasets. DEWA &#168;KSS yields highly correlated expression profiles for "cells" in the same group, robustly across different normalization methods. B) Self-supervised hyperparameter grid search results (RNAmix_Sort-seq normalized by FTT). Neighbors are on the x-axis and PCs are colored. The optimal configuration neighbors are shown by the dotted black line and PCs are shown by the solid black line. C) Optimization behavior using optimal PCs = 4 found in (B) for 5-200 neighbors. The lowest prediction error for each diffusion trajectory (line) is marked by a circle with a green outline if it corresponds to the number of iterations in the optimal configuration i = 1 or in black when the optimal number of iterations &gt; 1. The optimal value is marked by a diamond. The number of diffusion steps decreases as the number of neighbors increases. The number of diffusion steps is truncated to 9 steps. The prediction error decreases as the number of neighbours increases from 5-80, and then increases. We compare the results of DeepImpute, DEWA &#168;KSS, MAGIC, DrImpute and SAVER to count data that has been preprocessed but has otherwise not been denoised (pp). The preprocessing is detailed in section 4.4, and, in short, consists of filtering and median normalizing the data followed by a Freeman-Tukey transformation. DeepImpute <ref type="bibr">[27]</ref> takes as input the raw count data and needs to be preprocessed after, as above. MAGIC is run using the Seurat pipeline <ref type="bibr">[3]</ref>. For this dataset, DEWA &#168;KSS selects 100 PCs and 150 neighbors as optimal hyperparameters (Fig 3A )). After denoising we evaluate the performance metrics with a range of  clustering and dimensionality reduction parameters to estimate the sensitivity of the performance metrics (clustering and cell dispersion during projection) to the choices of these parameters (S2 Fig) . Overall performance (as determined by MSE) is poor when using few components (PCs) and a small number k of neighbors, which is similar to the default parameters in many processing pipelines (S2(A) Fig) . This underlines the importance of carefully considering the amount of variance to be used in the initial kNN-G construction.</p><p>Because the number of inferred clusters influences the Fowlkes-Mallows score, we also adjust, by applying a factor, doubling, quadrupling or halving, the resolution parameter r of the Leiden clustering algorithm to increase or decrease the number of clusters to be closer to the number of annotated clusters <ref type="bibr">(33)</ref>. To be able to run DrImpute and SAVER we down-sample the dataset to 10% of the annotated cells including all 33 clusters before denoising using 4800 cells. r is increased from 1 to 2 for DeepImpute and pp, increased from 1 to 4 for DrImpute and SAVER, and decreased from 1 to 0.5 for MAGIC. DEWA &#168;KSS is not adjusted as the number of clusters falls close to the number of annotated clusters by default.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.4">Optimal kNN denoising does not involve diffusion</head><p>On all test datasets, we observed that the optimal configuration was found to have a single iteration (no diffusion) but variable (dataset specific) optimal number of PCs and neighbors (Fig <ref type="figure">2C</ref>). This observation extended to all normalization methods if parameter spaces with sufficient numbers of neighbors were explored (Table <ref type="table">1</ref>). To determine if diffusion is improving denoising for real-world data, we applied DEWA &#168;KSS to seven published single-cell datasets. We tested on mouse bone marrow (BM) data <ref type="bibr">[34]</ref>, on human cell line epithelial-to-mesenchymal transition (EMT) data <ref type="bibr">[5]</ref>, on Saccharomyces cerevisiae data from rich media (YPD) and on Saccharomyces cerevisiae data after treatment with rapamycin (RAPA) <ref type="bibr">[35]</ref>, on mouse visual cortex tissue (VisualCortex) data <ref type="bibr">[33]</ref>, on human embryonic forebrain tissue (hgForeb-rainGlut) data and on mouse dentate gyrus granule neuron (DentateGyrus) data <ref type="bibr">[36]</ref>. The BM and EMT datasets are preprocessed following the vignette provided by the MAGIC package <ref type="bibr">[5]</ref> (section 4.5). The YPD, RAPA and VisualCortex datasets are preprocessed using the procedure in section 4.4. The hgForebrainGlut and DentateGyrus datasets are preprocessed with the velocyto <ref type="bibr">[36]</ref> and SCANPY <ref type="bibr">[4]</ref> python packages using the provided vignettes (section 4.6).</p><p>We run DEWA &#168;KSS on these datasets (searching for hyperparameters using &#65533;equidistant values in log space) to find the optimal configuration (S5 Fig) . For the BM dataset we let the algorithm run 20 diffusion steps to map out the objective function. For all other datasets we use run2best, which finds the first minimum MSE during diffusion and then stops the search (S6 Fig) . All six real-world datasets result in optimal MSE when there is no diffusion (number of iterations i = 1) (Table <ref type="table">2</ref>). </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.5">DEWA &#168;KSS preserves data variance for downstream analysis</head><p>The main goal of denoising scRNA-seq data is to reduce the influence of noise and to reveal biological variance. High dimensional biological data contains some variance which is due to random noise and should be removed, and some variance that is due to biological differences and should be retained. Removing noise is important for correct interpretation of patterns in the data, but attenuating biological variation eliminates biological signal and can result in biased analyses. Biological variance is not easily separable from technical noise, and denoising methods risk oversmoothing, retaining only the strongest patterns (e.g. the first few principal components of the data) while discarding informative minor variation. It is therefore critical when tuning model parameters to have an objective function that takes into account the total variance of the data structure.</p><p>We evaluate the effect that denoising has on data variance by comparing the singular value structure of the denoised data for different methods, which represents the relative variance of all dimensions. Although the optimal amount of variance and the number of components that capture that variance is not known, we reason that comparing the relative variance in all dimensions allow us to determine the extent to which a denoising method is smoothing the data. Denoised data that requires fewer components to capture most (&gt;90%) variance is more smoothed. When most variance is compressed into a handful of principal components, features within the data become collinear, more complex interactions between features disappear, and only the strongest sources of variance are preserved. Some downstream analyses are likely to be more sensitive to this oversmoothing than other analyses. For example, a clustering approach may still effectively separate groups based on variance in only a few dimensions, but regulatory inference may be substantially confounded or uninterpretable.</p><p>MAGIC <ref type="bibr">[5]</ref> is currently among the most popular algorithms for denoising single-cell RNAseq data. It uses a heuristic for determining optimal smoothing; as published, it used &#916;R 2 between diffusion steps, but the most recent implementation has switched to Procrustes analysis of the differences between diffusion steps. Neither approach has an objective way to determine optimal smoothing. In the absence of crossvalidation or some other external method that prevents overfitting, we expect R 2 to decrease until all data is averaged, i.e., to saturation, and a Procrustes analysis should behave similarly. MAGIC addresses this by hard-coding a stopping threshold which determines when the data is smoothed "enough"; because this threshold is not data-dependent, it can result in highly distorted outputs <ref type="bibr">[27,</ref><ref type="bibr">35,</ref><ref type="bibr">37]</ref>.</p><p>If this threshold is converted to a model hyperparameter, it is still necessary to tune with some external method as it has no lower bound for arbitrarily poor estimates.</p><p>We compare the effects of denoising using a heuristic as implemented in MAGIC <ref type="bibr">[5]</ref>, using DEWA &#168;KSS in its optimal configuration and using DEWA &#168;KSS in an oversmoothing (non-optimal) configuration for comparison. We also run this comparison for DeepImpute <ref type="bibr">[27]</ref>, DrImpute <ref type="bibr">[11]</ref> and SAVER <ref type="bibr">[28]</ref> with default configurations. This comparison is performed on the previously-described mouse BM, preprocessed using the approach described in <ref type="bibr">[5]</ref>. We run MAGIC with three sets of model parameters; the default parameters, default with early stopping (the diffusion parameter t = 1), and with the decay parameter d = 30. For DEWA &#168;KSS, we scan a log-equidistant parameter range for the optimal configuration (S5(A) and S6(A) Figs) and find that the optimal configuration uses normalized distances with number of neighbors k = 100 and with number of principal components PCs = 50 for i = 1, giving MSE = 0.3107. Diffusion iterations i increment until a minimum MSE is found. For the BM data, the MSE generally decreases as the number of PCs increases. Beyond a certain point, however, continuing to increase the number of PCs (to 500) increases the MSE. The optimal number of PCs, 50, is small compared to the size of the data and suggests that some compression of the data is optimal before running the kNN algorithm. To oversmooth the data we extended the number of iterations to run DEWA &#168;KSS to i = 4, beyond the optimal number of iterations (Fig <ref type="figure">4B</ref>). We also used the molecular cross-validation (MCV) application of noise2self <ref type="bibr">[38]</ref>, implemented as in S1 Section, to select the optimal number of PCs for denoising by DEWA &#168;KSS. We found that MCV selected fewer PCs for denoising compared to the DEWA &#168;KSS objective function (S8 Fig; <ref type="figure">13</ref> PCs compared to 50 PCs).</p><p>To investigate how the variance structure of the data changes based on denoising we compute the singular values (section 4.7) and determine the number of components needed to explain 90% and 99% of the variance for each dataset after denoising <ref type="bibr">(Fig 4A and S3 Fig)</ref>. We observe a striking difference between the oversmoothed data and the optimally denoised data. With optimal denoising, 90% of the variance is captured by 259 components. Utilizing the MCV method to select hyperparameters resulted in an intermediate amount of variance retained after denoising when compared to the DEWA &#168;KSS optimal and the DEWA &#168;KSS oversmoothed denoised data. Only 2 components are needed to capture 90% of the post-processing variance when oversmoothing the data, showing that a substantial portion of the original information content of the data is lost in this regime. DEWA &#168;KSS oversmoothing is comparable to the results of using MAGIC with default parameters, where 90% of the variance in the post processed data can be captured with only 3 components. When using only one iterative step and default parameters, MAGIC captures this amount of variance using 25 components. In most cases the MAGIC algorithm generates shallow variance structures with a few components needed to express nearly all of the variance. The variance structure can differ greatly depending on the hyperparameters chosen for DEWA &#168;KSS, and poor parameter selection results in shallow variance structures. However, the objective function automatically identifies an optimal configuration such that we expect to keep the relevant variance. For SAVER the first component capture almost all the variance while the 21 subsequent components capture the remaining variance implying that SAVER compress the data significantly. For DeepImpute and DrImpute the opposite is the case that the 99% of the variance are captured by over 80% of the components implying that these methods maintains a more flat distribution of the data over the components.</p><p>We can see the consequence of oversmoothing when plotting the expression of the erythroid marker Klf1, the myeloid marker Mpo, and the stem cell marker Ifitm1 (Fig <ref type="figure">4C</ref>). Very few individual cells express both Klf1 and Mpo in the optimally-denoised data, but the oversmoothed data implies that there is a smooth continuous transition from high Klf1 expression, through co-expression of Klf1, Mpo, and Ifitm1 markers, to high Mpo expression. Although the difference in MSE is not large (&#916; MSE &lt; 0.0175) between these two denoised datasets, the resulting biological interpretation differs a great deal, and likely highlights a spurious relationship in the oversmoothed case.</p><p>We run a similar analysis on the EMT data comparing DEWA &#168;KSS and MAGIC (S4 Fig) and find identical effects.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.6">DEWA &#168;KSS improves recovery of differentially expressed genes</head><p>Biological analysis of gene expression data often requires determining differentially expressed genes (DEGs) between groups of cells. We evaluate the effect of denoising on discovery of DEGs by comparing DEGs from a subset of cells with genetic perturbations <ref type="bibr">[35]</ref> to the equivalent bulk microarray data <ref type="bibr">[39]</ref>. Eleven different gene deletion strains are compared to a wildtype control. Five of these gene deletion strains have few DEGs versus six strains with lots of DEGs; gene deletion strains with more than 63 DEGs (1% of genes in the yeast genome) in the bulk data are considered to have lots of DEGs. DEGs from the single-cell data are determined by wilcoxon rank sum test with Benjamini/Hochberg correction &#945; = 0.01.</p><p>Most methods increase DEG recovery from single-cell data compared to preprocessing alone (Fig <ref type="figure">5</ref>), with SAVER performing the best and DEWA &#168;KSS in second. However, performance on test subsets with few DEGs is generally low for all methods (S9 Fig), although these results may be less reliable due to the large effect of single DEGs on performance metrics.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.7">DEWA &#168;KSS scales to large single-cell data sets</head><p>Single-cell data sets are continuing to grow in scale, and therefore denoising algorithm performance is an important consideration. We have benchmarked several denoising methods on a standard laptop (details in 4.9) in order to evaluate speed and scalability. The size of the datasets measured are detailed in S1 Table . We find that in our desktop-scale test, DEWA &#168;KSS is able to analyze the largest data set (64.8k cells x 18.1k genes) in a reasonable time (Fig <ref type="figure">6</ref>), although DeepImpute and MAGIC are faster. Other methods are not able to run to completion in the larger data sets with the computational resources provided for this test.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3">Discussion</head><p>In this paper we have introduced a novel objective function, based on noise2self <ref type="bibr">[26]</ref>, and applied it to self-supervised parameter tuning of weighted k-nearest neighbors (kNN) and diffusion-based denoising. The resulting algorithm, DEWA &#168;KSS, is specifically designed to denoise single-cell expression data. The objective function has a global objective that can be minimized, removing the need to use often unreliable heuristics to select model parameters, which is a drawback to many current single-cell denoising methods. We demonstrate that this framework accurately denoises data by benchmarking against previously established methods, and find that it is robust to choice of normalisation method (Section 2.2).</p><p>Due to the difficulty in establishing a ground truth for most real-world single-cell data, denoising algorithms are frequently tested on synthetic or artificial data. Maintaining biological variance is a crucial aspect of denoising; common downstream applications such as cell type identification, differential gene expression, marker identification, and regulatory network inference rely on biological variance to function. We therefore believe that it is necessary to extensively test on experimental data (a notable strength of Dijk et al. <ref type="bibr">[5]</ref> is testing on realworld data). On larger datasets with higher complexity, DEWA &#168;KSS performs well in terms of deconvolving cell types. We find that in general, the amount of variance included when clustering the data has a large impact on the performance of all methods tested, and that DEWA &#168;KSS outperforms other denoising algorithms in this area. While it is still an open question how much variance should be used to project and cluster single-cell data, it is clear that it is an essential component of accurate interpretation.</p><p>To investigate the properties of our method we run the algorithm on seven different published single-cell gene expression datasets. In all cases, the optimal denoising configuration (as determined by the objective function) uses the closest neighborhood, and is not improved by diffusion on the kNN graph. Diffusion causes a decrease in denoising performance, compressing almost all of the variance into a handful of dimensions. This may have some advantages for visualizing high-dimensional gene expression data, but most non-visualization analyses are impaired by the loss of variance. We also find that the number of neighbors k and the number of principal components to use tend to be large compared to the default parameters of other methods and conventions used in computational pipelines. In general, there is an advantage to the inclusion  of more principal components than called for by common rules of thumb, like using the knee in an explained variance vs number of components plot. However, including an arbitrary number of principal components is not ideal, as excess principal components do decrease performance. Comparing the use of a distance matrix versus the use of a connectivity matrix as a representation of the kNN-G shows that a distance matrix yields better results. The degree of similarity between the expression profile of one cell to that of another cell is relevant for denoising, not just whether cells are more or less similar than other cells' expression profiles in the experiment.</p><p>Overall, the DEWA &#168;KSS framework presented here has substantial advantages over heuristic parameter selection. Heuristic-based denoising methods set hyperparameters without a clear basis for effectiveness, often with opaque reasoning for choices. At best, this is likely to result in sub-optimal denoising performance; at worst, it may result in data that is dominated by oversmoothing effects, and which yields incorrect biological interpretations. Our objective function-based method provides a rigorous way of choosing an effective configuration. The difficulties of evaluating how to denoise single-cell data should not be underestimated. It is vital that the effectiveness of single-cell processing methods be quantifiable, so that the Computational performance of all tested method on selected datasets. Runtime (minutes) is plotted against the total number of values (cells &#65533; genes) in the dataset, to account for differing numbers of genes in each data set. Complete results table is available in S1 Table . 

<ref type="url">https://doi.org/10.1371/journal.pcbi.1008569.g006</ref> methods can be tuned for performance. We have chosen to use Euclidean distances for all analysis, but DEWA &#168;KSS can accept any graph derived with any distance metric to create the kNN matrix. By constructing a denoising function that uses a k-nearest neighbors graph and is consistent with the conditions laid out in noise2self, we have derived an easily-evaluated method that can denoise single-cell data in a self-supervised manner. The DEWA &#168;KSS objective may also have applications to other graph-based algorithms.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4">Methods</head><p>We begin by presenting a review of the mathematical constraints on our denoising function. We then present the core DEWA &#168;KSS method and objective function. We end with descriptions of our preparatory and preprocessing methods.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.1">Fundamental principle of noise2self</head><p>Batson and Royer <ref type="bibr">[26]</ref> present the approach noise2self and applied it for UMI counts as the method Molecular Cross Validation (MCV) <ref type="bibr">[38]</ref>, in which they partition observed features (in this case raw transcript counts) x i2J , J &#188; f1; . . . ; 2mg, into two groups {X J , X J c} = {{x 1 , . . ., x m }, {x m+1 , . . ., x 2m }} where the superscript c represents the complement set. The task is then to find an invariant function g&#240;x&#222; J : R 2m ! R 2m that operates only on X J c and yields an output x whose entries at indices J are predictors of x J . This function is independent of x J ; some of the features of each datapoint are predicted using another independent set of features of the same datapoint. MCV was implemented for reference (S1 Section) and for selecting a 'robust' set of PCs in section 2.5. MCV applied for PCA component selection optimally selects linearly separable components that are informative and the data is constrained to that sub-selection. S8 Fig . shows the recreated analysis done by <ref type="bibr">Batson and Royer [26]</ref>. This practical implementation of the original noise2self principle does not employ a kNN graph and is linear as oppose to the non-linearity of the graph appraoch.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.2">Denoising expression data with a weighted affinity kernel and selfsupervision</head><p>In DEWA &#168;KSS, as in other state-of-the-art methods, we start by computing a lower, d-dimensional representation of the data using PCA. We then compute a connectivity or distanceweighted kNN-G with u neighbors. Our approach is similar to that of MAGIC <ref type="bibr">[5]</ref> but differs in two key ways: (i) we use a self-supervised objective function for hyperparameter selection, and (ii) we denoise on the expression values directly to avoid a loss of information/variance that results from overreduction of dimensionality (reducing the data to a latent representation with low rank or low dimensionality such that key biological variation is lost). To calculate the kNN-G, we use the algorithm UMAP <ref type="bibr">[18]</ref> and its implementation <ref type="bibr">[40]</ref> and create a right-stochastic matrix M d,u from the connectivity/distance matrix. In practice, any graph can be provided as input to DEWA &#168;KSS for denoising. We use the UMAP neighbor algorithm due to its versatility and speed, but alternative methods could be used here. The UMAP implementation only uses the neighbour search algorithm if the number of cells is above 4096 by default and otherwise computes all distances and picks the k closest ones.</p><p>Denoising using a normalized kNN-G M can be carried out through simple matrix multiplication</p><p>and so on, where X is the expression matrix for z cells, with each column x&#65533; j containing the expression values of a single gene j for each cell k 2 K = {1, . . ., z}, &#65533; X is X after one step of denoising and &#65533; X 2 is X after two diffusion steps of denoising. For a given gene j in a single cell k, this equation calculates the weighted average influence of the expression value of the same gene in each neighboring cell. The expression value &#65533;</p><p>x kj is hence set to this weighted sum:</p><p>where m k k is the k k-th element of M and</p><p>In general, a Markov process can be forward-iterated as</p><p>for a two-step iteration, generalized to M n for an n-step forward process. Denoising is then carried out as follows:</p><p>In DEWA &#168;KSS we implement a self-supervised procedure by noting that the operation in Eq 4 is the application of an invariant function g(x) J on each entry of X if the diagonal elements of M at each step n are set to 0 (to enforce the independence noted in section 4.1). If diagonal elements are not forced to zero the second step of the diffusion becomes self referential and enforces overfitting of the objective function (S7 Fig) . Here J = {j}, so the expression value of a gene j in cell k is calculated using the expression values of j in all cells except cell k. Eq 2 reduces to:</p><p>That is, for each gene there is an invariant function over the expression values of the gene across all cells. The Markov property guarantees the independence of the neighborhood graph from past steps. At each step, we set diag M = 0 and renormalize to a right stochastic matrix. Let s be a function that removes the diagonal elements of a matrix and then normalizes the resulting matrix to a right stochastic matrix. Let m &#240;d;u;n&#222; </p><p>with the following notation:</p><p>Eq 4 can be rewritten and incorporated into the mean square error minimization objective as follows:</p><p>We use this equation to find n that denoises X &#65533; enough to best capture its underlying structure while attenuating variation due to noise. To make sure we keep the invariant sets independent we consider each step an independent Markov process and apply the function s(.) at each step.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.3">Converting kNN to a right stochastic transition matrix</head><p>To allow for the use of UMAP distance metrics, DEWA &#168;KSS uses the transformation on distances used in <ref type="bibr">[5]</ref>,</p><p>where D is the matrix of distances between the gene expression profiles of different cells and &#65533; d is the mean of the nonzero elements of D. A decay rate &#945; is also used, and the . in the equation indicates element-wise operation. This decay rate is applied on a connectivity matrix as C .&#945; , where C has elements c 2 [0, 1]. It should be noted that in <ref type="bibr">[5]</ref>, the decay rate is also applied during the construction of the kNN-G to estimate distance thresholds and there may not be a 1-to-1 correspondence in the algorithms. To stabilize the denoising procedure, the final step before normalizing to a right stochastic transition matrix is to symmetrize M so that</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.4">Preprocessing of scRNA-Seq expression data</head><p>We preprocess single cell RNA-seq datasets before applying denoising. Unless otherwise stated, all datasets are preprocessed using the same steps if no guidelines were provided from the dataset or publication source documents.</p><p>Preprocessing is carried out using the following steps: (i) Filtering cells by using only those that have greater than a certain number of expressed genes and greater than a certain total cell UMI count. This is done mainly by visual inspection, clipping 1 -2% of the data-in practice, removing the top and bottom 0.5 percentile of data points; (ii) Removing genes not expressed in more than n cells, with n &#65533; 10; (iii) Normalizing the counts of each cell so that each cell has the same count value as the median cell count over the cell population; and (iv) applying the Freeman-Tukey transform (FTT) <ref type="bibr">[41]</ref> with an adjustment term -1 to preserve sparsity,</p><p>The FTT stabilizes the variance of Poisson distributed data. Wagner et al. <ref type="bibr">[13]</ref> showed that the FTT is a good choice for single-cell data compared to the log-TPM and log-FPKM transforms as it does not underestimate the relative variance of highly expressed genes and thus balances the influence of lowly expressed gene variation. In other words, the relative variance of highly expressed genes versus more lowly expressed genes should be preserved after transformation. This is an essential property for inferring a relevant kNN-G. We process all data with the help of the SCANPY framework <ref type="bibr">[4]</ref>. DEWA &#168;KSS can accept the SCANPY AnnData object, a regular numpy array or a scipy sparse array as input.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.5">Preprocessing for comparison with MAGIC</head><p>The BM dataset is preprocessed using the same approach as used by <ref type="bibr">[5]</ref>, as detailed here: <ref type="url">https://nbviewer.jupyter.org/github/KrishnaswamyLab/MAGIC/blob/master/python/ tutorial_notebooks/bonemarrow_tutorial.ipynb</ref>) The EMT dataset is preprocessed as detailed here: <ref type="url">https://nbviewer.jupyter.org/github/KrishnaswamyLab/magic/blob/master/python/ tutorial_notebooks/emt_tutorial.ipynb</ref>).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.6">Preprocessing hgForebrainGlut and DentateGyrus data</head><p>The hgForebrainGlut and DentateGyrus datasets are preprocessed by replicating the process provided by velocyto <ref type="bibr">[36]</ref> here <ref type="url">https://github.com/velocyto-team/velocyto-notebooks/blob/ master/python/hgForebrainGlutamatergic.ipynb</ref> and here <ref type="url">https://github.com/velocyto-team/ velocyto-notebooks/blob/master/python/DentateGyrus.ipynb</ref>. The package SCANPY is used to carry out the computations <ref type="bibr">[4]</ref>.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.7">Preservation of variance and PCA computation</head><p>To estimate the variance structure of our expression matrix before and after denoising, we take the standard normalization of each variable j in the data so that each observation k in column j is</p><p>with E k denoting expected value with respect to k and &#963; indicating standard deviation.</p><p>Computing the singular value decomposition, we get</p><p>The singular values are invariant to the transpose, meaning that they explain the variance in the data independent of whether the data is projected onto cells or genes, and nonzero singular values are bounded by min {m, n}. To estimate the rank of &#65533; X and the nonzero singular values we use the cutoff from numpy <ref type="bibr">[42]</ref>:</p><p>with &#65533; being the machine precision of a numpy float 32 type.</p><p>The relative variance is then calculated as</p><p>The relative condition number of each singular value can be calculated as</p><p>with s representing the minimum nonzero singular value defined by Eq 16.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.8">Processing Tian et al. [29] benchmark data</head><p>In order to evaluate DEWA &#168;KSS and existing methods in accordance with the benchmark analysis of Tian et al. <ref type="bibr">[29]</ref>, we use the R code provided in Tian et al. <ref type="bibr">[43]</ref> to apply all normalization methods that we can successfully run on the RNAmix_CEL-seq2 and RNAmix_Sort-seq datasets. We also apply our FTT-based preprocessing method on the data in Python and combine the result with the other normalization results into a single data structure.</p><p>We then use the same codebase to run the denoising (imputation) methods in <ref type="bibr">[29]</ref> on the output of each of the normalization methods on each dataset. We transfer each of these outputs to Python, perform a hyperparameter search using DEWA &#168;KSS on it and record the best parameter configurations along with the corresponding mean squared error (MSE) in Table <ref type="table">1</ref>. We apply DEWA &#168;KSS on each normalized input using the optimal configuration for that input and transfer the results back to R, combining them with the other denoising results into a single data structure. Note that some normalization-imputation method combinations are not represented in our figures as we could not successfully run these using the provided pipeline. We use the postprocessing and plotting scripts in <ref type="bibr">[43]</ref> to generate plots for our analysis.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.9">Benchmarking computational performance</head><p>To benchmark the computational cost of DEWA &#168;KSS we select data sets with varying number of genes and cells from the previously used datasets adding <ref type="bibr">[44]</ref> using DEWA &#168;KSS default configurations and similar preprocessing for all datasets. Data sets are filtered for expressed genes; genes which are expressed in fewer than 30 cells are removed from the data set. Any gene which does not have a minimum of 30 counts in at least one cell is also removed. For SAVER and DeepImpute, data is provided directly as integer counts; for all other methods, the expression data is log(x+1) transformed. All methods are used with default configurations. The hardware used is Memory: 31.1GiB, Processor: Intel Core i9-8950HK CPU @ 2.90GHz &#215; 12, Graphics: GeForce GTX 1050 Ti with Max-Q Design/PCIe/SSE2, OS type: Ubuntu 18.04 64-bit, Swap disk: 64GB. If the method requires a parameter for the number of processors to use, it is set to 12, the maximum number of available cores.</p></div><note xmlns="http://www.tei-c.org/ns/1.0" place="foot" xml:id="foot_0"><p>PLOS Computational Biology | https://doi.org/10.1371/journal.pcbi.1008569 January 7, 2021</p></note>
		</body>
		</text>
</TEI>
