| import wget |
| import re |
| from Bio import SeqIO |
| import pandas as pd |
|
|
| def load_fasta_into_list(fasta_file): |
| """ |
| Load the FASTA file into a dictionary for quick lookup. |
| |
| :param fasta_file: Path to the FASTA file |
| :return: List of dictionaries with processed sequences as keys and (id, description) as values |
| """ |
| fasta_list = [] |
| scop_pattern = re.compile(r'\b[a-z]\.\d+\.\d+\.\d+\b') |
|
|
| for record in SeqIO.parse(fasta_file, "fasta"): |
| processed_sequence = str(record.seq) |
| fasta_list.append({ |
| "id": record.id, |
| "primary" : processed_sequence, |
| "class": ".".join(record.description.split(" ")[1].split(".")[:-3]), |
| "fold": ".".join(record.description.split(" ")[1].split(".")[:-2]), |
| "super_family": ".".join(record.description.split(" ")[1].split(".")[:-1]), |
| "family": record.description.split(" ")[1], |
| "description": record.description, |
| }) |
| return fasta_list |
|
|
| def should_exclude(record): |
| deets = record.description.split(" ")[1] |
| |
| fold = ".".join(deets.split(".")[:2]) |
| return fold in excluded_folds |
|
|
| |
| url = "https://scop.berkeley.edu/downloads/scopeseq-2.08/astral-scopedom-seqres-gd-sel-gs-bib-40-2.08.fa" |
|
|
| |
| file_name = wget.download(url) |
| print(f"\nDownloaded file: {file_name}") |
|
|
|
|
| excluded_folds = ['c.2', 'c.3', 'c.4', 'c.5', 'c.27', 'c.28', 'c.30', 'c.31', 'b.66', 'b.67', 'b.68', 'b.69', 'b.70'] |
|
|
| fasta_list = [item for item in load_fasta_into_list(file_name) if item['fold'] not in excluded_folds] |
|
|
| df = pd.DataFrame(fasta_list) |
|
|
| df.to_csv('full_data.csv', index=False) |
|
|
| print(len(df)) |