nodes: 0, module; 1, function_definition; 2, function_name:get_hypergeometric_stats; 3, parameters; 4, block; 5, identifier:N; 6, identifier:indices; 7, expression_statement; 8, assert_statement; 9, assert_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, while_statement; 19, return_statement; 20, comment:"""Calculates hypergeom. p-values and fold enrichments for all cutoffs.
  
      Parameters
      ----------
      N: int
          The length of the list
      indices:  `numpy.ndarray` with ``dtype=np.uint16``
          The (sorted) indices of the "1's" in the list.
      """; 21, call; 22, boolean_operator; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, comparison_operator:n < N; 32, block; 33, expression_list; 34, identifier:isinstance; 35, argument_list; 36, call; 37, line_continuation:\; 38, call; 39, identifier:K; 40, attribute; 41, identifier:pvals; 42, call; 43, identifier:folds; 44, call; 45, subscript; 46, float:1.0; 47, subscript; 48, float:1.0; 49, identifier:n; 50, integer:0; 51, identifier:k; 52, integer:0; 53, identifier:p; 54, float:1.0; 55, identifier:n; 56, identifier:N; 57, if_statement; 58, expression_statement; 59, comment:# calculate hypergeometric p-value; 60, expression_statement; 61, comment:# calculate fold enrichment; 62, expression_statement; 63, identifier:pvals; 64, identifier:folds; 65, identifier:N; 66, tuple; 67, identifier:isinstance; 68, argument_list; 69, attribute; 70, argument_list; 71, identifier:indices; 72, identifier:size; 73, attribute; 74, argument_list; 75, attribute; 76, argument_list; 77, identifier:pvals; 78, integer:0; 79, identifier:folds; 80, integer:0; 81, boolean_operator; 82, comment:# "add one"; 83, comment:# calculate f(k+1; N,K,n+1) from f(k; N,K,n); 84, block; 85, else_clause; 86, augmented_assignment; 87, assignment; 88, assignment; 89, identifier:int; 90, attribute; 91, identifier:indices; 92, attribute; 93, identifier:np; 94, identifier:issubdtype; 95, attribute; 96, attribute; 97, identifier:np; 98, identifier:empty; 99, binary_operator:N+1; 100, keyword_argument; 101, identifier:np; 102, identifier:empty; 103, binary_operator:N+1; 104, keyword_argument; 105, comparison_operator:k < K; 106, comparison_operator:indices[k] == n; 107, expression_statement; 108, expression_statement; 109, comment:# "add zero"; 110, comment:# calculate f(k; N,K,n+1) from f(k; N,K,n); 111, block; 112, identifier:n; 113, integer:1; 114, subscript; 115, call; 116, subscript; 117, binary_operator:k / (K*(n/float(N))); 118, identifier:np; 119, identifier:integer; 120, identifier:np; 121, identifier:ndarray; 122, identifier:indices; 123, identifier:dtype; 124, identifier:np; 125, identifier:uint16; 126, identifier:N; 127, integer:1; 128, identifier:dtype; 129, attribute; 130, identifier:N; 131, integer:1; 132, identifier:dtype; 133, attribute; 134, identifier:k; 135, identifier:K; 136, subscript; 137, identifier:n; 138, augmented_assignment; 139, augmented_assignment; 140, expression_statement; 141, identifier:pvals; 142, identifier:n; 143, identifier:get_hgp; 144, argument_list; 145, identifier:folds; 146, identifier:n; 147, identifier:k; 148, parenthesized_expression; 149, identifier:np; 150, identifier:float64; 151, identifier:np; 152, identifier:float64; 153, identifier:indices; 154, identifier:k; 155, identifier:p; 156, parenthesized_expression; 157, identifier:k; 158, integer:1; 159, augmented_assignment; 160, identifier:p; 161, identifier:k; 162, identifier:N; 163, identifier:K; 164, identifier:n; 165, binary_operator:K*(n/float(N)); 166, binary_operator:float((n+1) * (K-k)) / \
                    float((N-n) * (k+1)); 167, identifier:p; 168, parenthesized_expression; 169, identifier:K; 170, parenthesized_expression; 171, call; 172, line_continuation:\; 173, call; 174, binary_operator:float((n+1) * (N-K-n+k)) /
                    float((N-n) * (n-k+1)); 175, binary_operator:n/float(N); 176, identifier:float; 177, argument_list; 178, identifier:float; 179, argument_list; 180, call; 181, call; 182, identifier:n; 183, call; 184, binary_operator:(n+1) * (K-k); 185, binary_operator:(N-n) * (k+1); 186, identifier:float; 187, argument_list; 188, identifier:float; 189, argument_list; 190, identifier:float; 191, argument_list; 192, parenthesized_expression; 193, parenthesized_expression; 194, parenthesized_expression; 195, parenthesized_expression; 196, binary_operator:(n+1) * (N-K-n+k); 197, binary_operator:(N-n) * (n-k+1); 198, identifier:N; 199, binary_operator:n+1; 200, binary_operator:K-k; 201, binary_operator:N-n; 202, binary_operator:k+1; 203, parenthesized_expression; 204, parenthesized_expression; 205, parenthesized_expression; 206, parenthesized_expression; 207, identifier:n; 208, integer:1; 209, identifier:K; 210, identifier:k; 211, identifier:N; 212, identifier:n; 213, identifier:k; 214, integer:1; 215, binary_operator:n+1; 216, binary_operator:N-K-n+k; 217, binary_operator:N-n; 218, binary_operator:n-k+1; 219, identifier:n; 220, integer:1; 221, binary_operator:N-K-n; 222, identifier:k; 223, identifier:N; 224, identifier:n; 225, binary_operator:n-k; 226, integer:1; 227, binary_operator:N-K; 228, identifier:n; 229, identifier:n; 230, identifier:k; 231, identifier:N; 232, identifier:K
code: def get_hypergeometric_stats(N, indices):
      """Calculates hypergeom. p-values and fold enrichments for all cutoffs.
  
      Parameters
      ----------
      N: int
          The length of the list
      indices:  `numpy.ndarray` with ``dtype=np.uint16``
          The (sorted) indices of the "1's" in the list.
      """
      assert isinstance(N, (int, np.integer))
      assert isinstance(indices, np.ndarray) and \
              np.issubdtype(indices.dtype, np.uint16)
  
      K = indices.size
  
      pvals = np.empty(N+1, dtype=np.float64)
      folds = np.empty(N+1, dtype=np.float64)
      pvals[0] = 1.0
      folds[0] = 1.0
  
      n = 0
      k = 0
      p = 1.0
      while n < N:
          if k < K and indices[k] == n:
              # "add one"
              # calculate f(k+1; N,K,n+1) from f(k; N,K,n)
              p *= (float((n+1) * (K-k)) / \
                    float((N-n) * (k+1)))
              k += 1
          else:
              # "add zero"
              # calculate f(k; N,K,n+1) from f(k; N,K,n)
              p *= (float((n+1) * (N-K-n+k)) /
                    float((N-n) * (n-k+1)))
          n += 1
          # calculate hypergeometric p-value
          pvals[n] = get_hgp(p, k, N, K, n)
          # calculate fold enrichment
          folds[n] = k / (K*(n/float(N)))
  
      return pvals, folds