code: def moving_patterson_d(aca, acb, acc, acd, size, start=0, stop=None,
                         step=None):
      
  
      # calculate per-variant values
      num, den = patterson_d(aca, acb, acc, acd)
  
      # N.B., nans can occur if any of the populations have completely missing
      # genotype calls at a variant (i.e., allele number is zero). Here we
      # assume that is rare enough to be negligible.
  
      # compute the numerator and denominator within each window
      num_sum = moving_statistic(num, statistic=np.nansum, size=size,
                                 start=start, stop=stop, step=step)
      den_sum = moving_statistic(den, statistic=np.nansum, size=size,
                                 start=start, stop=stop, step=step)
  
      # calculate the statistic values in each block
      d = num_sum / den_sum
  
      return d
docs: Estimate D(A, B; C, D) in moving windows.
  
      Parameters
      ----------
      aca : array_like, int, shape (n_variants, 2),
          Allele counts for population A.
      acb : array_like, int, shape (n_variants, 2)
          Allele counts for population B.
      acc : array_like, int, shape (n_variants, 2)
          Allele counts for population C.
      acd : array_like, int, shape (n_variants, 2)
          Allele counts for population D.
      size : int
          The window size (number of variants).
      start : int, optional
          The index at which to start.
      stop : int, optional
          The index at which to stop.
      step : int, optional
          The number of variants between start positions of windows. If not
          given, defaults to the window size, i.e., non-overlapping windows.
  
      Returns
      -------
      d : ndarray, float, shape (n_windows,)
          Estimated value of the statistic in each window.