<jupyter_start><jupyter_text>Exploratory Data Analysis  Data Collection<jupyter_code># Não consegui fazer funcionar o curl, arquivos estão salvos localmente<jupyter_output><empty_output><jupyter_text>Data Processing<jupyter_code># Como deu problema no meu anaconda e não consegui importar direto com o plpred ativado, tive que puxar as bibliotecas manualmente para a tarefa.
pip install pandas
pip install matplotlib
pip install biopython
from Bio import SeqIO
from Bio.SeqUtils import ProtParam
import pandas as pd

def compute_aa_composition(protein_sequence):
    analyzer = ProtParam.ProteinAnalysis(str(protein_sequence))
    return analyzer.get_amino_acids_percent()
#criando dataframe com campo membrane

df = pd.DataFrame()

handle = open('../data/raw/membrane.fasta')
parser = SeqIO.parse(handle, 'fasta')

for protein in parser:
    protein_data = compute_aa_composition(protein.seq)
    protein_data['membrane'] = 1
    df = df.append([protein_data], ignore_index=True)
    
handle = open('../data/raw/cytoplasm.fasta')
parser = SeqIO.parse(handle, 'fasta')

for protein in parser:
    protein_data = compute_aa_composition(protein.seq)
    protein_data['membrane'] = 0
    df = df.append([protein_data], ignore_index=True)
df<jupyter_output><empty_output><jupyter_text>Exploratory Data Analysis<jupyter_code>df_grouped = df.groupby('membrane').mean()
df_grouped
%pylab inline

pylab.rcParams['figure.figsize'] = (12, 6)
aminoacids = df_grouped.columns

cytoplasm_mean_composition = df_grouped.loc[0]
membrane_mean_composition = df_grouped.loc[1]

relative_difference = membrane_mean_composition / cytoplasm_mean_composition

plt.bar(aminoacids, relative_difference)
plt.show()
# Proteínas de membrana são mais hidrofóbicas
from sklearn.decomposition import PCA

pca = PCA(n_components=2)
pca.fit(df.drop(['membrane'], axis=1))

for group, df_group in df.groupby('membrane'):
    components = pca.transform(df_group.drop('membrane', axis=1))
    plt.scatter(
        components[:,0],
        components[:,1],
        s=0.5,
        label='Membrane' if group == 0 else 'Cytoplasm',
        color='red' if group == 0 else 'blue'
    )

plt.show()<jupyter_output><empty_output><jupyter_text>Model Training<jupyter_code>from sklearn.model_selection import train_test_split

X = df.drop(['membrane'], axis=1)
y = df['membrane']

X_train, X_test, y_train, y_test = train_test_split(X, y)
from sklearn.ensemble import RandomForestClassifier

model = RandomForestClassifier()
model.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Model Validation<jupyter_code>from sklearn.metrics import classification_report

y_pred = model.predict(X_test)
report = classification_report(y_test, y_pred)
print(report)<jupyter_output>precision    recall  f1-score   support

           0       0.96      0.95      0.95      2509
           1       0.95      0.96      0.95      2491

    accuracy                           0.95      5000
   macro avg       0.95      0.95      0.95      5000
weighted avg       0.95      0.95      0.95      5000
{'fraction_non_alphanumeric': 0.09839291571006888, 'fraction_numerical': 0.025910134470318136, 'mean_word_length': 4.267702936096718, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '68981', 'license': 'MIT', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1019, 'n_words': 228, 'path': 'notebooks/Exploratory Data Analysis.ipynb', 'repo_name': 'Christiankun/plpred', 'size': '3049'}