def test_filter_both(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) QC_metaobj_50x40 = qc.metrics(filter_count_matrix=False) fdata1,genes1,bc1 = qc.filter_count_matrix(QC_metaobj_50x40,remove_cell_cycle=False,UMI_thresh = 1500,Features_thresh = 39,log10FeaturesPerUMI_thresh = 0.002,FeaturesPerUMI_thresh= 0.0001,mtRatio_thresh = 0.5) qc2=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata2, genes2, bc2 = qc2.filter_count_matrix(QC_metaobj=None,remove_cell_cycle=False,UMI_thresh = 1500,Features_thresh = 39,log10FeaturesPerUMI_thresh = 0.002,FeaturesPerUMI_thresh= 0.0001,mtRatio_thresh = 0.5) assert fdata1.shape == fdata2.shape assert np.all(bc1 == bc2) assert np.all(genes1 == genes2)
def test_filter_umi_threshold_error_2(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) with pytest.raises(ValueError,match=r"UMI threshold too high, all samples would be removed."): fdata,fbc,fgenes= qc.filter_count_matrix(remove_cell_cycle=True, UMI_thresh = 3000,Features_thresh = 39, log10FeaturesPerUMI_thresh = 0.002, FeaturesPerUMI_thresh = 0.0001,mtRatio_thresh = 0.5)
def test_filter_without_QC_Obj(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata, fgenes,fbc = qc.filter_count_matrix(QC_metaobj=None,remove_cell_cycle=False,UMI_thresh = 1500,Features_thresh = 39,log10FeaturesPerUMI_thresh = 0.002, FeaturesPerUMI_thresh= 0.0001,mtRatio_thresh = 0.5) assert isinstance(fdata,spsp.csc.csc_matrix) assert np.shape(fdata) == (32,40) assert fdata.sum() == 63358
def test_log10FeaturesPerUMI_thresh(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata1,fgenes1,fbc1 = qc.filter_count_matrix(log10FeaturesPerUMI_thresh=.48) qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata2,fgenes2,fbc2, QC_metaobj_50x40 = qc.metrics(filter_count_matrix=True,log10FeaturesPerUMI_thresh=.48) assert fdata1.shape == fdata2.shape
def test_filter_allFilters_compare(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) d0,b,a = qc.filter_count_matrix(UMI_thresh=1700) qc=QualityControl(d0,b,a) d1,b,a = qc.filter_count_matrix(Features_thresh=39) qc=QualityControl(d1,b,a) d2,b,a = qc.filter_count_matrix(FeaturesPerUMI_thresh=.02) qc=QualityControl(d2,b,a) d3,b,a = qc.filter_count_matrix(log10FeaturesPerUMI_thresh=.48) qc=QualityControl(d3,b,a) d4,fgenes4,fbc4 = qc.filter_count_matrix(mtRatio_thresh=.1) qc=QualityControl(d4,fgenes4,fbc4) qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) d_all,fgenes_all,fbc_all = qc.filter_count_matrix(UMI_thresh=1700,Features_thresh=39,FeaturesPerUMI_thresh=.02, log10FeaturesPerUMI_thresh=.48,mtRatio_thresh=.1) assert (d0.shape[0],d1.shape[0],d2.shape[0],d3.shape[0],d4.shape[0],d_all.shape[0]) == (45, 30, 17, 17, 14, 14) assert np.all(fgenes4 == fgenes_all) assert np.all(fbc4 == fbc_all) assert np.sum(d4) == np.sum(d_all)
def test_filter_with_QC_Obj_removeCC(self): '''test QC filter function with QC_metaobj (call metrics to get QC_metaobj and pass it to filter_count_matrix with mtx_df)''' qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) QC_metaobj_50x40 = qc.metrics(UMI_thresh = 1500,Features_thresh = 39,log10FeaturesPerUMI_thresh = 0.002, FeaturesPerUMI_thresh = 0.0001,mtRatio_thresh = 0.5,filter_count_matrix=False) fdata, fgenes, fbc = qc.filter_count_matrix(QC_metaobj_50x40,remove_cell_cycle=True,UMI_thresh = 1500,Features_thresh = 39,log10FeaturesPerUMI_thresh = 0.002, FeaturesPerUMI_thresh = 0.0001,mtRatio_thresh = 0.5)#,nUMI=500,nFeatures=500,FeaturesPerUMI=0.3,mtRatio=0.05) assert isinstance(fdata,spsp.csc.csc_matrix) assert isinstance(fbc,list) assert isinstance(fgenes,list) assert np.shape(fdata) == (32,38) assert fdata.sum() == 60257
def test_filter_umi_threshold_error(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata,fgenes,fbc = qc.filter_count_matrix(UMI_thresh=900,remove_cell_cycle=True,verbose=True)
def test_filter_mtRatio_threshold_error(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) with pytest.raises(ValueError,match=r"MT ratio threshold too low, all samples would be removed."): fdata,fgenes,fbc = qc.filter_count_matrix(mtRatio_thresh=.000001)
def test_filter_log10featuresPerUMI_threshold_error(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) with pytest.raises(ValueError,match=r"log10 Feature per UMI threshold too high, all samples would be removed."): fdata,fgenes,fbc = qc.filter_count_matrix(log10FeaturesPerUMI_thresh=.9)
def test_filter_mtRatio_threshold_wrong_type(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) with pytest.raises(ValueError,match=r"mtRatio threshold must be a float between 0 and 1."): fdata,fgenes, fbc = qc.filter_count_matrix(mtRatio_thresh=-1)
def test_filter_log10featuresPerUMI_threshold_wrong_type(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) with pytest.raises(ValueError,match=r"log10featurePerUMI threshold must be an integer or float."): fdata,fgenes,fbc = qc.filter_count_matrix(log10FeaturesPerUMI_thresh=list([1,2,3]))
def test_filter_allFilters(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata,fgenes,fbc = qc.filter_count_matrix(UMI_thresh=1700,Features_thresh=39,FeaturesPerUMI_thresh=.02, log10FeaturesPerUMI_thresh=.48,mtRatio_thresh=.1) assert fdata.shape == (14, 40)
def test_filter_mtRatio(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata,fgenes,fbc = qc.filter_count_matrix(mtRatio_thresh=.1) assert fdata.shape == (43,40)
def test_filter_log10featuresPerUMI(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata,fgenes,fbc = qc.filter_count_matrix(log10FeaturesPerUMI_thresh=.48) assert fdata.shape == (43, 40)
def test_filter_features(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata,fgenes,fbc = qc.filter_count_matrix(Features_thresh=39) assert fdata.shape == (32, 40)
def test_filter_umi(self): qc=QualityControl(self.mtx_df_50x40,self.genes,self.barcodes) fdata,fgenes,fbc = qc.filter_count_matrix(UMI_thresh=1700) assert fdata.shape == (45, 40)