<jupyter_start><jupyter_text>Description It gets the PCA transformation of an input file.  Modules loading<jupyter_code>%load_ext autoreload
%autoreload 2
from pathlib import Path
from IPython.display import display

import numpy as np
import pandas as pd
import seaborn as sns

import conf
from utils import generate_result_set_name<jupyter_output><empty_output><jupyter_text>Settings<jupyter_code>np.random.seed(0)<jupyter_output><empty_output><jupyter_text>Input data<jupyter_code>INPUT_FILEPATH_STEM = "projection-smultixcan-efo_partial-mashr-zscores"
INPUT_FILEPATH = Path(
    conf.RESULTS["DATA_TRANSFORMATIONS_DIR"],
    "z_score_std",
    f"z_score_std-{INPUT_FILEPATH_STEM}.pkl",
).resolve()
display(INPUT_FILEPATH)

input_filepath_stem = INPUT_FILEPATH.stem
display(input_filepath_stem)<jupyter_output><empty_output><jupyter_text>Output folder<jupyter_code># output dir for this notebook
RESULTS_DIR = Path(conf.RESULTS["DATA_TRANSFORMATIONS_DIR"], "pca").resolve()
RESULTS_DIR.mkdir(parents=True, exist_ok=True)

display(RESULTS_DIR)<jupyter_output><empty_output><jupyter_text>PCA options<jupyter_code># parameters of the dimentionality reduction steps
DR_OPTIONS = {
    "n_components": 50,
    "svd_solver": "full",
    "random_state": 0,
}
# dictionary containing all options/settings (used to generate filenames)
ALL_OPTIONS = DR_OPTIONS.copy()

display(ALL_OPTIONS)<jupyter_output><empty_output><jupyter_text>Load input file<jupyter_code>data = pd.read_pickle(INPUT_FILEPATH)
display(data.shape)
display(data.head())<jupyter_output><empty_output><jupyter_text>PCA<jupyter_code>from data.dimreduction import get_pca_proj
dr_data = get_pca_proj(data, DR_OPTIONS)
display(dr_data.shape)
display(dr_data.head())<jupyter_output><empty_output><jupyter_text>Plot<jupyter_code>g = sns.pairplot(data=dr_data.iloc[:, :5])<jupyter_output>[2021-03-08 14:23:45,646 - numexpr.utils] INFO: NumExpr defaulting to 4 threads.<jupyter_text>Save<jupyter_code>output_file = Path(
    RESULTS_DIR,
    generate_result_set_name(
        ALL_OPTIONS, prefix=f"pca-{input_filepath_stem}-", suffix=".pkl"
    ),
).resolve()

display(output_file)
dr_data.to_pickle(output_file)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10969503868912153, 'fraction_numerical': 0.010923987255348202, 'mean_word_length': 8.8125, 'pattern_counts': {'":': 3, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '520813', 'license': 'BSD-2-Clause-Patent', 'n_tokens_mistral': 851, 'n_tokens_neox': 808, 'n_words': 122, 'path': 'nbs/10_data_transformations/00_01-phenomexcan_efo-pca.ipynb', 'repo_name': 'greenelab/phenoplier', 'size': '2197'}