當前位置: 首頁>>代碼示例>>Python>>正文


Python PassingData.row_index2no_of_NAs方法代碼示例

本文整理匯總了Python中pymodule.PassingData.row_index2no_of_NAs方法的典型用法代碼示例。如果您正苦於以下問題:Python PassingData.row_index2no_of_NAs方法的具體用法?Python PassingData.row_index2no_of_NAs怎麽用?Python PassingData.row_index2no_of_NAs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pymodule.PassingData的用法示例。


在下文中一共展示了PassingData.row_index2no_of_NAs方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: remove_rows_with_too_many_NAs

# 需要導入模塊: from pymodule import PassingData [as 別名]
# 或者: from pymodule.PassingData import row_index2no_of_NAs [as 別名]
    def remove_rows_with_too_many_NAs(
        cls, data_matrix, row_cutoff, cols_with_too_many_NAs_set=None, NA_set=Set([0, -2]), debug=0, is_cutoff_max=0
    ):
        """
		2008-05-19
			if is_cutoff_max=1, anything > row_cutoff is deemed as having too many NAs
			if is_cutoff_max=0 (cutoff is minimum), anything >= row_cutoff is deemed as having too many NAs
		2008-05-12
			made more robust
			add cols_with_too_many_NAs_set
			add NA_set
		2008-05-08
			become classmethod
		"""
        sys.stderr.write("Removing rows with NA rate >= %s ..." % (row_cutoff))
        no_of_rows, no_of_cols = data_matrix.shape
        rows_with_too_many_NAs_set = Set()
        total_cols_set = Set(range(no_of_cols))
        if cols_with_too_many_NAs_set:
            cols_to_be_checked = total_cols_set - cols_with_too_many_NAs_set
        else:
            cols_to_be_checked = total_cols_set
        row_index2no_of_NAs = {}
        for i in range(no_of_rows):
            no_of_NAs = 0.0
            for j in cols_to_be_checked:
                if data_matrix[i][j] in NA_set:
                    no_of_NAs += 1
            if no_of_cols != 0:
                NA_ratio = no_of_NAs / no_of_cols
            else:
                NA_ratio = 0.0
            row_index2no_of_NAs[i] = NA_ratio
            if is_cutoff_max:
                if NA_ratio > row_cutoff:
                    rows_with_too_many_NAs_set.add(i)
            else:
                if NA_ratio >= row_cutoff:
                    rows_with_too_many_NAs_set.add(i)
        if debug:
            print
            print "rows_with_too_many_NAs_set"
            print rows_with_too_many_NAs_set
        passingdata = PassingData(rows_with_too_many_NAs_set=rows_with_too_many_NAs_set)
        passingdata.row_index2no_of_NAs = row_index2no_of_NAs
        sys.stderr.write("%s strains removed, done.\n" % len(rows_with_too_many_NAs_set))
        return passingdata
開發者ID:,項目名稱:,代碼行數:49,代碼來源:


注:本文中的pymodule.PassingData.row_index2no_of_NAs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。