File size: 1,697 Bytes
353eec8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
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]
# print(deets)
fold = ".".join(deets.split(".")[:2])
return fold in excluded_folds
# URL of the file to download
url = "https://scop.berkeley.edu/downloads/scopeseq-2.08/astral-scopedom-seqres-gd-sel-gs-bib-40-2.08.fa"
# Download the file
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)) |