Spaces:
Sleeping
Sleeping
Commit
·
ea67cd9
1
Parent(s):
a1e3c42
Delete code/add_annotations_alphafold.py
Browse files
code/add_annotations_alphafold.py
DELETED
|
@@ -1,95 +0,0 @@
|
|
| 1 |
-
import ssl
|
| 2 |
-
import requests as r
|
| 3 |
-
from decimal import *
|
| 4 |
-
import numpy as np
|
| 5 |
-
def add_annotations(dataframe):
|
| 6 |
-
print('Downloading UniProt sequence annotations...\n')
|
| 7 |
-
ssl._create_default_https_context = ssl._create_unverified_context
|
| 8 |
-
|
| 9 |
-
original_annot_name = ['DISULFID', 'INIT_MET', 'INTRAMEM', 'VARIANT', 'DNA_BIND', 'ACT_SITE', 'NP_BIND', 'LIPID',
|
| 10 |
-
'SITE',
|
| 11 |
-
'TRANSMEM', 'CROSSLNK', 'MUTAGEN', 'STRAND', 'HELIX', 'TURN', 'METAL', 'REPEAT', 'TOPO_DOM',
|
| 12 |
-
'CA_BIND', 'BINDING', 'REGION', 'SIGNAL', 'MOD_RES', 'ZN_FING', 'MOTIF', 'COILED', 'PEPTIDE',
|
| 13 |
-
'TRANSIT', 'CARBOHYD', 'PROPEP']
|
| 14 |
-
annotation_list = ['disulfide', 'intMet', 'intramembrane', 'naturalVariant', 'dnaBinding', 'activeSite',
|
| 15 |
-
'nucleotideBinding', 'lipidation', 'site', 'transmembrane', 'crosslink', 'mutagenesis', 'strand',
|
| 16 |
-
'helix', 'turn', 'metalBinding', 'repeat', 'topologicalDomain', 'caBinding', 'bindingSite',
|
| 17 |
-
'region',
|
| 18 |
-
'signalPeptide', 'modifiedResidue', 'zincFinger', 'motif', 'coiledCoil', 'peptide',
|
| 19 |
-
'transitPeptide', 'glycosylation', 'propeptide']
|
| 20 |
-
|
| 21 |
-
dataframe = dataframe.reset_index().drop(['index'], axis=1)
|
| 22 |
-
|
| 23 |
-
for annot in original_annot_name:
|
| 24 |
-
dataframe[annot] = ''
|
| 25 |
-
|
| 26 |
-
for protein in list(set(dataframe.uniprotID.to_list())):
|
| 27 |
-
print('Downloading annotations for ' + protein)
|
| 28 |
-
uniprot_entry = r.get("http://www.uniprot.org/uniprot/" + protein + ".txt")
|
| 29 |
-
uniprot_entry = uniprot_entry.text.split('\n')
|
| 30 |
-
|
| 31 |
-
annot_for_protein = []
|
| 32 |
-
for annotation in original_annot_name:
|
| 33 |
-
for line in uniprot_entry:
|
| 34 |
-
if annotation.strip() in line and line.startswith(
|
| 35 |
-
'FT') and 'evidence' not in line and 'ECO' not in line and 'note' not in line:
|
| 36 |
-
annot_for_protein.append(list(filter(None, line.split(' ')))[1:])
|
| 37 |
-
for select in annot_for_protein:
|
| 38 |
-
if select[0] not in dataframe.columns:
|
| 39 |
-
dataframe.loc[dataframe.uniprotID == protein, select[0]] = str((select[1] + '; '))
|
| 40 |
-
else:
|
| 41 |
-
dataframe.loc[dataframe.uniprotID == protein, select[0]] += str((select[1] + '; '))
|
| 42 |
-
for i in range(len(original_annot_name)):
|
| 43 |
-
dataframe = dataframe.rename(columns={original_annot_name[i]: annotation_list[i]})
|
| 44 |
-
|
| 45 |
-
# Fix annotation positions
|
| 46 |
-
print('Processing positions...\n')
|
| 47 |
-
for i in dataframe.index:
|
| 48 |
-
for annot in dataframe.columns[-30:]:
|
| 49 |
-
if annot != 'disulfide':
|
| 50 |
-
if dataframe.at[i, annot] != 'nan':
|
| 51 |
-
dataframe.at[i, annot] = ([x for x in [k.strip() for k in dataframe.at[i, annot].split(';')] if x])
|
| 52 |
-
if '..' not in str(dataframe.at[i, annot]):
|
| 53 |
-
pass
|
| 54 |
-
elif '..' in str(dataframe.at[i, annot]):
|
| 55 |
-
dataframe.at[i, annot] = str(dataframe.at[i, annot]).replace('..', '-')
|
| 56 |
-
else:
|
| 57 |
-
disulfide_annot = []
|
| 58 |
-
if dataframe.at[i, annot] != 'nan':
|
| 59 |
-
dataframe.at[i, annot]= dataframe.at[i, annot].split(';')
|
| 60 |
-
dataframe.at[i, annot] = [i.split('..') for i in dataframe.at[i, annot]]
|
| 61 |
-
dataframe.at[i, annot] =[e for v in dataframe.at[i, annot] for e in v]
|
| 62 |
-
dataframe.at[i, annot] = [i for i in dataframe.at[i, annot] if i != ' ']
|
| 63 |
-
|
| 64 |
-
# Add binary annotations
|
| 65 |
-
print('Adding binary annotations...\n')
|
| 66 |
-
dataframe = dataframe.astype('str')
|
| 67 |
-
for i in dataframe.index:
|
| 68 |
-
for k in annotation_list: # get the positions of each attribute as a list
|
| 69 |
-
txt = k + 'Binary'
|
| 70 |
-
dataframe.at[i, txt] = Decimal('nan')
|
| 71 |
-
try:
|
| 72 |
-
for positions in dataframe.at[i, k].split(','):
|
| 73 |
-
position = positions.strip('[').strip(']').replace("'", "")
|
| 74 |
-
if position != 'nan' and position != '' and '-' not in position and int(
|
| 75 |
-
dataframe.at[i, 'pos']) == int(position):
|
| 76 |
-
dataframe.at[i, txt] = '1'
|
| 77 |
-
break
|
| 78 |
-
elif position != 'nan' and position != '' and '-' not in position and int(
|
| 79 |
-
dataframe.at[i, 'pos']) != int(position):
|
| 80 |
-
dataframe.at[i, txt] = '0'
|
| 81 |
-
elif position != 'nan' and position != '' and '-' in position:
|
| 82 |
-
if int(position.split('-')[0]) < int(dataframe.at[i, 'pos']) < int(position.split('-')[1]):
|
| 83 |
-
dataframe.at[i, txt] = '1'
|
| 84 |
-
break
|
| 85 |
-
else:
|
| 86 |
-
dataframe.at[i, txt] = '0'
|
| 87 |
-
except:
|
| 88 |
-
ValueError
|
| 89 |
-
|
| 90 |
-
# Final corrections
|
| 91 |
-
|
| 92 |
-
dataframe = dataframe.replace({'[\'?\']': 'nan'})
|
| 93 |
-
dataframe = dataframe.replace({'[]': 'nan'})
|
| 94 |
-
return dataframe
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|