当前位置: 首页>>代码示例>>Python>>正文


Python Stats.doPearsonChiSquaredTest方法代码示例

本文整理汇总了Python中CGAT.Stats.doPearsonChiSquaredTest方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.doPearsonChiSquaredTest方法的具体用法?Python Stats.doPearsonChiSquaredTest怎么用?Python Stats.doPearsonChiSquaredTest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CGAT.Stats的用法示例。


在下文中一共展示了Stats.doPearsonChiSquaredTest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from CGAT import Stats [as 别名]
# 或者: from CGAT.Stats import doPearsonChiSquaredTest [as 别名]

#.........这里部分代码省略.........
        if len(options.parameters) == 0:
            raise "out of parameters - please supply probability or filename with probabilities."

        param = options.parameters[0]
        del options.parameters[0]

        if options.write_separators:
            probabilities = IOTools.ReadMap(
               IOTools.openFile(param, "r"), map_functions=(str, float))
        else:
            probability = float(param)

    for x in range(len(chunks) - 1):
        ninput += 1
        matrix, row_headers, col_headers = MatlabTools.readMatrix(
            StringIO("".join(lines[chunks[x] + 1:chunks[x + 1]])),
            format=options.input_format,
            headers=options.headers)
        nrows, ncols = matrix.shape

        if options.loglevel >= 2:
            options.stdlog.write("# read matrix: %i x %i, %i row titles, %i colum titles.\n" %
                                 (nrows, ncols, len(row_headers), len(col_headers)))

        if options.write_separators:
            options.stdout.write(lines[chunks[x]][1:-1] + "\t")

        pairs = []
        if options.iteration == "pairwise":
            pairs = []
            for row1 in range(0, len(row_headers)):
                for row2 in range(row1 + 1, len(row_headers)):
                    pairs.append((row1, row2))
        elif options.iteration == "all-vs-all":
            pairs = []
            for row1 in range(0, len(row_headers)):
                for row2 in range(0, len(row_headers)):
                    if row1 == row2:
                        continue
                    pairs.append((row1, row2))

        if options.method == "chi-squared":

            for row1, row2 in pairs:
                row_header1 = row_headers[row1]
                row_header2 = row_headers[row2]
                try:
                    result = Stats.doChiSquaredTest(
                        numpy.vstack((matrix[row1], matrix[row2])))
                except ValueError:
                    nskipped += 1
                    continue

                noutput += 1
                options.stdout.write("\t".join((
                    "%s" % row_header1,
                    "%s" % row_header2,
                    "%i" % result.mSampleSize,
                    "%i" % min(matrix.flat),
                    "%i" % max(matrix.flat),
                    options.value_format % result.mChiSquaredValue,
                    "%i" % result.mDegreesFreedom,
                    options.pvalue_format % result.mProbability,
                    "%s" % result.mSignificance,
                    options.value_format % result.mPhi)) + "\n")

        elif options.method == "pearson-chi-squared":

            if nrows != 2:
                raise ValueError("only implemented for 2xn table")

            if options.write_separators:
                id = re.match("(\S+)", lines[chunks[x]][1:-1]).groups()[0]
                probability = probabilities[id]

            for col in range(ncols):
                options.stdout.write("%s\t" % col_headers[col])
                result = Stats.doPearsonChiSquaredTest(
                    probability, sum(matrix[:, col]), matrix[0, col])
                options.stdout.write("\t".join((
                    "%i" % result.mSampleSize,
                    "%f" % probability,
                    "%i" % result.mObserved,
                    "%f" % result.mExpected,
                    options.value_format % result.mChiSquaredValue,
                    "%i" % result.mDegreesFreedom,
                    options.pvalue_format % result.mProbability,
                    "%s" % result.mSignificance,
                    options.value_format % result.mPhi)))
                if col < ncols - 1:
                    options.stdout.write("\n")
                    if options.write_separators:
                        options.stdout.write(lines[chunks[x]][1:-1] + "\t")

            options.stdout.write("\n")

    E.info("# ninput=%i, noutput=%i, nskipped=%i\n" %
           (ninput, noutput, nskipped))

    E.Stop()
开发者ID:CGATOxford,项目名称:cgat,代码行数:104,代码来源:matrix2stats.py

示例2: range

# 需要导入模块: from CGAT import Stats [as 别名]
# 或者: from CGAT.Stats import doPearsonChiSquaredTest [as 别名]
                                                   "%s" % result.mSignificance,
                                                   options.value_format % result.mPhi ) ) + "\n" )
            

        elif options.method == "pearson-chi-squared":

            if nrows != 2:
                raise "only implemented for 2xn table"
            
            if options.write_separators:
                id = re.match( "(\S+)", lines[chunks[x]][1:-1] ).groups()[0]
                probability = probabilities[id]
                
            for col in range(ncols):
                options.stdout.write( "%s\t" % col_headers[col] )
                result = Stats.doPearsonChiSquaredTest( probability , sum(matrix[:,col]), matrix[0,col] )
                options.stdout.write( "\t".join( ( "%i" % result.mSampleSize,
                                                   "%f" % probability,
                                                   "%i" % result.mObserved,
                                                   "%f" % result.mExpected,
                                                   options.value_format % result.mChiSquaredValue,
                                                   "%i" % result.mDegreesFreedom,
                                                   options.pvalue_format % result.mProbability,
                                                   "%s" % result.mSignificance,
                                                   options.value_format % result.mPhi ) )  )
                if col < ncols - 1:
                    options.stdout.write("\n")
                    if options.write_separators:
                        options.stdout.write( lines[chunks[x]][1:-1] + "\t" )

            options.stdout.write( "\n" )
开发者ID:siping,项目名称:cgat,代码行数:33,代码来源:matrix2stats.py


注:本文中的CGAT.Stats.doPearsonChiSquaredTest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。