当前位置: 首页>>代码示例>>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;未经允许,请勿转载。