aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility
diff options
context:
space:
mode:
authorLei Yan2013-06-19 23:04:21 +0000
committerLei Yan2013-06-19 23:04:21 +0000
commit615b861dfd05c04df2e1a753dd135b07c1d88a94 (patch)
tree318586811f2781069e6df0f5910e3b12975efee5 /wqflask/utility
parent82bd8b61b4aed0b0ae07477afae37a846fab35c2 (diff)
downloadgenenetwork2-615b861dfd05c04df2e1a753dd135b07c1d88a94.tar.gz
Moved the normalize_values function to separate file corr_result_helpers.py
Added docstring test to normalize_values Number of overlapping samples column now displays correctly in the correlation results page
Diffstat (limited to 'wqflask/utility')
-rw-r--r--wqflask/utility/corr_result_helpers.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/wqflask/utility/corr_result_helpers.py b/wqflask/utility/corr_result_helpers.py
new file mode 100644
index 00000000..edf32449
--- /dev/null
+++ b/wqflask/utility/corr_result_helpers.py
@@ -0,0 +1,30 @@
+def normalize_values(a_values, b_values):
+ """
+ Trim two lists of values to contain only the values they both share
+
+ Given two lists of sample values, trim each list so that it contains
+ only the samples that contain a value in both lists. Also returns
+ the number of such samples.
+
+ >>> normalize_values([2.3, None, None, 3.2, 4.1, 5], [3.4, 7.2, 1.3, None, 6.2, 4.1])
+ ([2.3, 4.1, 5], [3.4, 6.2, 4.1], 3)
+
+ """
+
+ min_length = min(len(a_values), len(b_values))
+ a_new = []
+ b_new = []
+ for counter in range(min_length):
+ if a_values[counter] and b_values[counter]:
+ a_new.append(a_values[counter])
+ b_new.append(b_values[counter])
+
+ num_overlap = len(a_new)
+ assert num_overlap == len(b_new), "Lengths should be the same"
+
+ return a_new, b_new, num_overlap
+
+
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod() \ No newline at end of file