Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CSP_Rank/add_aligned_suffix_csv.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (27 sloc)
1.55 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import sys | |
import re | |
from os.path import exists, isdir | |
from paths import PDB_FILES, CSP_Rank_Scores | |
pdb_id = sys.argv[1].upper() | |
# Read the CSV file | |
dfs = [CSP_Rank_Scores + 'CSP_'+pdb_id.lower()+'_CSpred.csv'] | |
for csv_file in dfs: | |
if exists(csv_file): | |
df = pd.read_csv(csv_file) | |
aligned_directory = f'{PDB_FILES}{pdb_id}_aligned/' | |
alt_aligned_directory = f'{PDB_FILES}{pdb_id}_alt_aligned/' | |
if exists(aligned_directory) and isdir(aligned_directory): | |
#df['holo_model_path'] = df['holo_model_path'].apply(lambda x: x.replace(r'^\./' + pdb_id + '/', './' + pdb_id + '_aligned/', 1) if '_aligned' not in x else x) | |
#df['holo_model_path'] = df['holo_model_path'].apply(lambda x: re.sub(r'^\./' + pdb_id + '/', './' + pdb_id + '_aligned/', 1) if '_aligned' not in x and '_alt' not in x else x ) | |
df['holo_model_path'] = df['holo_model_path'].apply( | |
lambda x: re.sub('/' + pdb_id + '/', '/' + pdb_id + '_aligned/', x) | |
if isinstance(x, str) and '_aligned' not in x and '_alt' not in x else x | |
) | |
if exists(alt_aligned_directory) and isdir(alt_aligned_directory): | |
df['holo_model_path'] = df['holo_model_path'].apply(lambda x: re.sub('/' + pdb_id + '_alt/', '/' + pdb_id + '_alt_aligned/', str(x)) | |
if isinstance(x, str) and '_aligned' not in x and '_alt' in x else x | |
) | |
print(df['holo_model_path']) | |
# Save the modified DataFrame back to a new CSV file | |
df.to_csv(csv_file, index=False) |