<jupyter_start><jupyter_text>We here reduce the dimension of data through principal component analysis (PCA)to apply the data to quantum machine learning.<jupyter_code>import pandas as pd
import numpy as np
import os
from tqdm import tqdm
import random
from sklearn.decomposition import PCA
import matplotlib.pyplot as plt
import math
from ..utils import load_data<jupyter_output><empty_output><jupyter_text>We got information about some genes related to COVID-19 from the Kyoto Encyclopedia of Genes and Genomes (KEGG) database.We also selected the same number of genes that are not related to COVID-19.To analyze the gene expression levels, we will use the $\log_{2}$ fold change method.Hence, in this process, we exclude genes if there are zeros in their data.<jupyter_code>df = pd.read_csv('./GSE147507_Series6,16.csv', index_col=0)
df_covrelated = pd.read_csv('./GSE147507_Series6,16_covrelated.csv', index_col=0)

cov_related_genes = df_covrelated.index

drop_genes = []
for gene in cov_related_genes:
    if 0 in list(df.loc[gene, :]):
        drop_genes.append(gene)
cov_related_genes2 = [gene for gene in cov_related_genes if gene not in drop_genes]

not_related_genes = [x for x in df.index if x not in cov_related_genes2]
drop_genes = []
for gene in not_related_genes:
    if 0 in list(df.loc[gene, :]):
        drop_genes.append(gene)

n_related_genes = [x for x in not_related_genes if x not in drop_genes]


not_related_genes2 = random.sample([x for x in not_related_genes if x not in drop_genes], len(cov_related_genes2))

df_sample = df.loc[cov_related_genes2+not_related_genes2,:]
df_sample.to_csv('./GSE147507_sample.csv', index=True)<jupyter_output><empty_output><jupyter_text>As mentioned earlier, we use the $\log_{2}$ fold change method.We divide the number of genes infected with SARS-CoV-2by the number of uninfected genes and apply the log function.<jupyter_code>new_dict = {}
for gene in df_sample.index:
    Series6_1 = math.log(df_sample.loc[gene, 'Series6_A549-ACE2_SARS-CoV-2_1']/df_sample.loc[gene, 'Series6_A549-ACE2_Mock_1'], 2)
    Series6_2 = math.log(df_sample.loc[gene, 'Series6_A549-ACE2_SARS-CoV-2_2']/df_sample.loc[gene, 'Series6_A549-ACE2_Mock_2'], 2)
    Series6_3 = math.log(df_sample.loc[gene, 'Series6_A549-ACE2_SARS-CoV-2_3']/df_sample.loc[gene, 'Series6_A549-ACE2_Mock_3'], 2)
    Series16_1 = math.log(df_sample.loc[gene, 'Series16_A549-ACE2_SARS-CoV-2_1']/df_sample.loc[gene, 'Series16_A549-ACE2_Mock_1'], 2)
    Series16_2 = math.log(df_sample.loc[gene, 'Series16_A549-ACE2_SARS-CoV-2_2']/df_sample.loc[gene, 'Series16_A549-ACE2_Mock_2'], 2)
    Series16_3 = math.log(df_sample.loc[gene, 'Series16_A549-ACE2_SARS-CoV-2_3']/df_sample.loc[gene, 'Series16_A549-ACE2_Mock_3'], 2)
    
    if gene in cov_related_genes2:
        new_dict[gene] = [Series6_1, Series6_2, Series6_3, Series16_1, Series16_2, Series16_3, 1]
    else:
        new_dict[gene] = [Series6_1, Series6_2, Series6_3, Series16_1, Series16_2, Series16_3, 0]
df_div = pd.DataFrame.from_dict(new_dict).T
df_div.columns = ['Series6_1', 'Series6_2', 'Series6_3', 'Series16_1', 'Series16_2', 'Series16_3', 'Target']
df_div.to_csv('./GSE147507_sample_div.csv', index=True)<jupyter_output><empty_output><jupyter_text>Below we plot a graph for the reduced-dimensional data.We use PCA and set the number of components to two.<jupyter_code>x = df_div.drop(['Target'], axis=1).values
y = df_div['Target'].values
pca = PCA(n_components=2)
principalComponents = pca.fit_transform(x)
principaldf = pd.DataFrame(data=principalComponents, columns = ['pc1', 'pc2'])
principaldf['target'] = y
principaldf.index = df_div.index

fig = plt.figure(figsize = (8, 8))
ax = fig.add_subplot(111)
ax.set_xlabel('Principal Component 1', fontsize = 15)
ax.set_ylabel('Principal Component 2', fontsize = 15)
ax.set_title('2 component PCA', fontsize=20)

targets= [0, 1]
colors = ['r', 'b']
for target, color in zip(targets,colors):
    indicesToKeep = principaldf['target'] == target
    ax.scatter(principaldf.loc[indicesToKeep, 'pc1'],
               principaldf.loc[indicesToKeep, 'pc2'],
               c = color,
               s = 50)
for i, gene in enumerate(principaldf.index.tolist()):
    ax.annotate(gene, (principaldf.loc[gene, 'pc1'], principaldf.loc[gene, 'pc2']))
ax.legend(targets)
ax.grid()<jupyter_output><empty_output><jupyter_text>Most genes are distributed near $(0,0)$.Below we set the number of components to three.We can distinguish several genes related to COVID-19 (blue dots).<jupyter_code>TrainData, TrainLabels, TestData, TestLabels = load_data(0.0001, 3, seed=30)

fig = plt.figure()
ax = fig.add_subplot(projection='3d')
colors = ['tab:blue', 'tab:red']
for dp, l in zip(TrainData, TrainLabels):
    ax.scatter(dp[0], dp[1], dp[2], c = colors[int(l)])
ax.set_xlabel('pc1')
ax.set_ylabel('pc2')
ax.set_zlabel('pc3')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12492282362626055, 'fraction_numerical': 0.05042189750977567, 'mean_word_length': 5.5675675675675675, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '364813', 'license': 'MIT', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1772, 'n_words': 413, 'path': 'Qunova Computing/covid19_data/dim_reduc.ipynb', 'repo_name': 'ushnishray/Hackathon2021', 'size': '4859'}