sgkit icon indicating copy to clipboard operation
sgkit copied to clipboard

Increase the usage of augmented assignment statements

Open elfring opened this issue 4 years ago • 4 comments

:eyes: Some source code analysis tools can help to find opportunities for improving software components. :thought_balloon: I propose to increase the usage of augmented assignment statements accordingly.

diff --git a/sgkit/io/vcf/vcf_reader.py b/sgkit/io/vcf/vcf_reader.py
index 9455c73..1e94069 100644
--- a/sgkit/io/vcf/vcf_reader.py
+++ b/sgkit/io/vcf/vcf_reader.py
@@ -428,7 +428,7 @@ def vcf_to_zarr_sequential(
                 if len(alleles) > n_allele:
                     alleles = alleles[:n_allele]
                 elif len(alleles) < n_allele:
-                    alleles = alleles + ([STR_FILL] * (n_allele - len(alleles)))
+                    alleles += [STR_FILL] * (n_allele - len(alleles))
                 variant_alleles.append(alleles)
                 max_variant_allele_length = max(
                     max_variant_allele_length, max(len(x) for x in alleles)
diff --git a/sgkit/stats/hwe.py b/sgkit/stats/hwe.py
index fcf1d18..e10e328 100644
--- a/sgkit/stats/hwe.py
+++ b/sgkit/stats/hwe.py
@@ -92,7 +92,7 @@ def hardy_weinberg_p_value(obs_hets: int, obs_hom1: int, obs_hom2: int) -> float
 
     if prob_sum <= 0:  # pragma: no cover
         return np.nan
-    het_probs = het_probs / prob_sum
+    het_probs /= prob_sum
     p = het_probs[het_probs <= het_probs[obs_hets]].sum()
     p = max(min(1.0, p), 0.0)
 
diff --git a/sgkit/stats/popgen.py b/sgkit/stats/popgen.py
index 3ce6fd7..c90ef6d 100644
--- a/sgkit/stats/popgen.py
+++ b/sgkit/stats/popgen.py
@@ -631,7 +631,7 @@ def _pbs(t: ArrayLike, out: ArrayLike) -> None:  # pragma: no cover
             for k in range(j + 1, n_cohorts):
                 ret = (t[i, j] + t[i, k] - t[j, k]) / 2
                 norm = 1 + (t[i, j] + t[i, k] + t[j, k]) / 2
-                ret = ret / norm
+                ret /= norm
                 out[i, j, k] = ret
 
 
@@ -657,7 +657,7 @@ def _pbs_cohorts(
         k = ct[n, 2]
         ret = (t[i, j] + t[i, k] - t[j, k]) / 2
         norm = 1 + (t[i, j] + t[i, k] + t[j, k]) / 2
-        ret = ret / norm
+        ret /= norm
         out[i, j, k] = ret
 
 
diff --git a/sgkit/stats/regenie.py b/sgkit/stats/regenie.py
index 3ad38fe..e2e471e 100644
--- a/sgkit/stats/regenie.py
+++ b/sgkit/stats/regenie.py
@@ -697,10 +697,10 @@ def regenie_transform(
     # it was precluded in glow by unit covariate regularization:
     # https://github.com/projectglow/glow/issues/266
     if orthogonalize:  # pragma: no cover
-        G = G - X @ da.linalg.lstsq(X, G)[0]
-        Y = Y - X @ da.linalg.lstsq(X, Y)[0]
-        G = G / G.std(axis=0)
-        Y = Y / Y.std(axis=0)
+        G -= X @ da.linalg.lstsq(X, G)[0]
+        Y -= X @ da.linalg.lstsq(X, Y)[0]
+        G /= G.std(axis=0)
+        Y /= Y.std(axis=0)
         X = da.zeros(shape=(n_sample, 0), dtype=G.dtype)
 
     # The output of _variant_block_indexes is better suited as a NumPy array,
diff --git a/sgkit/window.py b/sgkit/window.py
index cde9e75..038a916 100644
--- a/sgkit/window.py
+++ b/sgkit/window.py
@@ -362,7 +362,7 @@ def window_statistic(
     )
 
     # Add depth for map_overlap
-    rel_window_starts = rel_window_starts + depth
+    rel_window_starts += depth
     rel_window_stops = rel_window_starts + window_lengths
 
     chunk_offsets = _sizes_to_start_offsets(windows_per_chunk)

elfring avatar Nov 21 '21 16:11 elfring

Sorry I missed this originally. Would you like to submit a PR to make these improvements @elfring?

tomwhite avatar May 16 '22 08:05 tomwhite

:crystal_ball: Can the shown change suggestion eventually be integrated also by an other contributor?

elfring avatar May 16 '22 10:05 elfring

I personally find augmented assignment statements less readable. If others disagree that’s fine.

hammer avatar May 16 '22 16:05 hammer

I think all the examples above are improvements, but :shrug:

jeromekelleher avatar May 16 '22 16:05 jeromekelleher