#!/usr/bin/python3 import cgi import cgitb; cgitb.enable() # for troubleshooting import os import gzip rootdir=os.path.dirname(os.path.abspath(__file__)) html_header="" html_footer="" if os.path.isfile(rootdir+"/index.html"): fp=open(rootdir+"/index.html") txt=fp.read() fp.close() html_header=txt.split('')[0] html_footer=txt.split('')[-1] form = cgi.FieldStorage() print("Content-type: text/html\n") if len(html_header): print(html_header) else: print(''' BioLiP

[Back to Home]

''') lig3=form.getfirst("code",'') if not lig3: lig3=form.getfirst("lig3",'') if lig3 in ["peptide","rna","dna","metal","regular"]: print('''
LigandExplanation
peptideShort amino acid chain with <30 residues. Old BioLiP ID: III
rnaRNA chain. Old BioLiP ID: NUC
dnaDNA chain. Old BioLiP ID: NUC
metalMetal ion
regularSmall molecule other than a metal ion.
''') elif lig3: txt_table=''' ''' freq_dict=dict() fp=open(rootdir+"/download/lig_frequency.txt",'r') for line in fp.read().splitlines()[4:]: items=line.split('\t') if len(items)==3 and items[1]==lig3: freq_dict[items[1]]=items[2] fp.close() filename="%s/data/smiles.tsv.gz"%rootdir smiles_dict=dict() if os.path.isfile(filename): fp=gzip.open(filename,'rt') for line in fp.read().splitlines(): items=line.split('\t') if len(items)>=3 and items[0]==lig3: if not items[1] in smiles_dict: smiles_dict[items[1]]=[items[2]] else: smiles_dict[items[1]].append(items[2]) fp.close() fp=gzip.open(rootdir+"/data/ligand.tsv.gz",'rt') for line in fp.read().splitlines(): items=line.split('\t') if lig3!=items[0]: continue freq="0" if lig3 in freq_dict and freq_dict[lig3]!='0': freq='%s'%(lig3,freq_dict[lig3]) SMILES=items[4] if len(smiles_dict): smiles_list=SMILES.split(';') SMILES="
" for key in smiles_list: key=key.strip() if key in smiles_dict: SMILES+="" else: SMILES+="" SMILES+="
SoftwareSMILES
"+'
'.join(smiles_dict[key])+"
"+key+"
"+key+"
" else: SMILES=SMILES.replace(";",";
") txt_table+=''' PDB CCD ID: $ccd Number of entries in BioLiP: $freq Chemical formula: $formula InChI: $InChI InChIKey: $InChIKey SMILES: $SMILES Name:$name '''.replace("$ccd",lig3 ).replace("$freq",freq ).replace("$formula",items[1] ).replace("$InChIKey",items[3] ).replace("$InChI",items[2] ).replace("$SMILES",SMILES ).replace("$name",items[5].replace(';',';
')) BGCOLOR="" if items[6]: txt_table+='''ChEMBL: $ChEMBL '''.replace("$ChEMBL",items[6]) BGCOLOR='BGCOLOR="#DEDEDE"' if items[7]: txt_table+='''DrugBank: $DrugBank '''.replace("$DrugBank",items[7] ).replace("$BGCOLOR", BGCOLOR) if BGCOLOR: BGCOLOR="" else: BGCOLOR='BGCOLOR="#DEDEDE"' if items[8]: txt_table+='''ZINC: $ZINC '''.replace("$ZINC",items[8] ).replace("$BGCOLOR", BGCOLOR) svg="https://cdn.rcsb.org/images/ccd/labeled/%s/%s.svg"%(lig3[0],lig3) print("

"%( lig3,lig3,lig3)) fp.close() print(txt_table+"") else: fp=gzip.open(rootdir+"/data/ligand.tsv.gz",'rt') ligand_list=[] for line in fp.read().splitlines()[1:]: ligand_list.append(line.split('\t')[0]) fp.close() import random lig3=random.choice(ligand_list) print('''No ligand code provided. You may [browse a random ligand]
This page will be redicted in 3 seconds. '''%(os.path.basename(__file__),lig3, os.path.basename(__file__),lig3)) if len(html_footer): print(html_footer) else: print(" ")