diff options
author | Frederick Muriuki Muriithi | 2021-11-01 08:18:48 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2021-11-01 08:18:48 +0300 |
commit | 37cf87e94a44ba2ab26a8e458e0c5a90fe5ecc7a (patch) | |
tree | 74ab24ef436772c9abac569c816539c20fa7b5e7 /gn3/computations | |
parent | d4919b2b59facb79ccad155e1d2826a97119ec28 (diff) | |
download | genenetwork3-37cf87e94a44ba2ab26a8e458e0c5a90fe5ecc7a.tar.gz |
Retrieve indices of the selected samples
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi
* gn3/computations/partial_correlations.py: New
function (good_dataset_samples_indexes).
* tests/unit/computations/test_partial_correlations.py: Tests for new
function (good_dataset_samples_indexes)
Get the indices of the selected samples. This is a partial migration of the
`web.webqtl.correlation.PartialCorrDBPage.getPartialCorrelationsFast`
function in GN1.
Diffstat (limited to 'gn3/computations')
-rw-r--r-- | gn3/computations/partial_correlations.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index 151143a..ba4de9e 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -177,3 +177,18 @@ def correlations_of_all_tissue_traits( primary_trait_values = tuple(primary_trait_symbol_value_dict.values())[0] return batch_computed_tissue_correlation( primary_trait_values, symbol_value_dict, method) + +def good_dataset_samples_indexes( + samples: Tuple[str, ...], + samples_from_file: Tuple[str, ...]) -> Tuple[int, ...]: + """ + Return the indexes of the items in `samples_from_files` that are also found + in `samples`. + + This is a partial migration of the + `web.webqtl.correlation.PartialCorrDBPage.getPartialCorrelationsFast` + function in GeneNetwork1. + """ + return tuple(sorted( + samples_from_file.index(good) for good in + set(samples).intersection(set(samples_from_file)))) |