Protein blast in webpage

html code for building a webpage:

<!DOCTYPE html>
<html>
<body>
<H2>This webpage is used for Blast in several fungi database</H2>
<p> Choose a protein in S288C Histidine synthesis pathway </p>
<form action = "http://10.122.210.253/cgi-bin/huarui_cgi_v3.py" method = "post" target = "_blank">
<input type = "radio" name = "Gene" value = "His1" checked='checked'/> His1
<input type = "radio" name = "Gene" value = "His2" /> His2
<input type = "radio" name = "Gene" value = "His3" /> His3
<input type = "radio" name = "Gene" value = "His4" /> His4
<input type = "radio" name = "Gene" value = "His5" /> His5
<input type = "radio" name = "Gene" value = "His6" /> His6
<input type = "radio" name = "Gene" value = "His7" /> His7
<input type = "radio" name = "Gene" value = "Mis1" /> Mis1
<input type = "radio" name = "Gene" value = "Others" /> Others
<br>
<br>
<label for="fname">Please input your gene name: </label>
<input type="text" name="fname"><br><br>

<p><label for="seqtext">Paste the sequence below</label></p>
<textarea id="w3review" name="seqtext" rows="4" cols="50"></textarea>
<br>
<br>
<p>Choose fungi database</p>
<input type="checkbox" name="Db1" value="Allprot">
<label for="Db1"> All database</label><br>
<input type="checkbox" name="Db2" value="Calbicans">
<label for="Db2"><i> C. albicans</i></label><br>
<input type="checkbox" name="Db3" value="Cglabrata">
<label for="Db3"><i> C. glabrata</i></label><br>
<input type="checkbox" name="Db4" value="Egossypii">
<label for="Db4"><i> E. gossypii</i></label><br>
<input type="checkbox" name="Db5" value="Klactis">
<label for="Db5"><i> K. lactis</i></label><br>
<br>
<br>
<input type = "submit" value = "Run Blast" />
</form>
<br>
</body>
</html>

The output webpage is like this:


This webpage is used for Blast in several fungi database

Choose a protein in S288C Histidine synthesis pathway

His1 His2 His3 His4 His5 His6 His7 Mis1 Others





Choose fungi database










We also need another cgi code for blasting in the server.

Cgi code for blastp:

#!/usr/bin/python3
#derf 9/22/2022

#THE IMPORT STUFF SECTION
import cgi, cgitb
import sys
import subprocess
import os

form = cgi.FieldStorage()

if form.getvalue('Gene'):
    gene_var = form.getvalue('Gene')

if form.getvalue('fname'):
    fname_var = form.getvalue('fname')

if form.getvalue('seqtext'):
    seq_var = form.getvalue('seqtext')

if form.getvalue('Db1'):
    Db1_var = form.getvalue('Db1')
else:
    Db1_var = "No"
if form.getvalue('Db2'):
    Db2_var = form.getvalue('Db2')
else:
    Db2_var = "No"

if form.getvalue('Db3'):
    Db3_var = form.getvalue('Db3')
else:
    Db3_var = "No"

if form.getvalue('Db4'):
    Db4_var = form.getvalue('Db4')
else:
    Db4_var = "No"

if form.getvalue('Db5'):
    Db5_var = form.getvalue('Db5')
else:
    Db5_var = "No"

def blastp_outfmt7(seq, pro_db_name):
    cmdd = ("/usr/bin/blastp -query " +  seq + " -db " + pro_db_name + " -outfmt 7")
    pss = subprocess.Popen(cmdd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output = str(pss.communicate()[0], 'ascii').split('\n')
    return output
#end def blastp_outfmt7


def run_seqret(other_name, seq):
    cmdd = '/usr/bin/echo \">' + other_name + '\" >/lib/cgi-bin/tempfile1 ; /usr/bin/echo \"' 
        + seq + '\" >> /lib/cgi-bin/tempfile1'
    pss = subprocess.Popen(cmdd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    output = str(pss.communicate()[0], 'ascii').split('\n')
    return "/lib/cgi-bin/tempfile1"
#end def run_seqret


if gene_var == 'Others':
    file_name = run_seqret(fname_var, seq_var)
    gene_var = fname_var
else:
    file_name = "/home/huarui/Protein/" + gene_var

#THE CGI SECTION
print ("Content-type:text/html\n\n")
print ('<html>')
print ('<head>')
print ('<title>blastp</title>')
print('</head>')
print('<style>')
print('table,th,td{border:1px solid black}')
print('</style>')
print ('<body>')
print ('<h2>Protein blast in fungi protein database</h2>')
print ('<br>')
for k in [Db1_var, Db2_var, Db3_var, Db4_var, Db5_var]:
    if k == "No":
        continue
    print ('<p>Blast search of', gene_var , 'compared to protein database',k, ':</p><br><br>')
    prodata_name = "/home/huarui/Protein/fungi_db/" + k
    blastresult = blastp_outfmt7(file_name, prodata_name) #run blast
    print('<table>')
    for i in range(3):
        print('<tr><td colspan = "12">', blastresult[i],'</td></tr>')
    print('<tr>')
    print('<tr><td colspan = "12">', blastresult[4],'</td></tr>')
    print('<th>query acc.ver</th>')
    print('<th>subject acc.ver</th>')
    print('<th>% identity</th>')
    print('<th>alignment length</th>')
    print('<th>mismatches</th>')
    print('<th>gap opens</th>')
    print('<th>q.start</th>')
    print('<th>q.end</th>')
    print('<th>s.start</th>')
    print('<th>s.end</th>')
    print('<th>evalue</th>')
    print('<th>bit score</th>')
    print('</tr>')
    for i in range (5,len(blastresult)-2):
        print('<tr>')
        CURR_line = blastresult[i].split("\t")
        for j in range(12):
            print('<td>',CURR_line[j],'</td>')
        print ('</tr>')
    print('</table>')
    print('<br>')
    print('<br>')
print ('<br>')
print ('</body>')
print ('</html>')


Note: we need use code

sudo chmod a+w < foldername>
to change the mode of the file to make sure we can make new file in folder cgi-bin!

If we select His1 and database C. albicans, E. gossypii, then the results will be like this:



Protein blast in fungi protein database


Blast search of His1 compared to protein database Calbicans :



# BLASTP 2.12.0+
# Query: HIS1 YER055C SGDID:S000000857
# Database: /home/huarui/Protein/fungi_db/Calbicans
# 4 hits found
query acc.ver subject acc.ver % identity alignment length mismatches gap opens q.start q.end s.start s.end evalue bit score
HIS1 XP_721934.1 60.526 304 107 4 1 297 1 298 5.63e-131 372
HIS1 XP_712929.2 51.852 27 12 1 223 248 148 174 1.1 28.5
HIS1 XP_713344.1 39.535 43 24 1 199 239 355 397 1.5 28.5
HIS1 XP_722193.2 31.373 51 31 2 126 174 377 425 3.3 27.3


Blast search of His1 compared to protein database Egossypii :



# BLASTP 2.12.0+
# Query: HIS1 YER055C SGDID:S000000857
# Database: /home/huarui/Protein/fungi_db/Egossypii
# 5 hits found
query acc.ver subject acc.ver % identity alignment length mismatches gap opens q.start q.end s.start s.end evalue bit score
HIS1 NP_984015.1 73.064 297 80 0 1 297 1 297 2.12e-162 451
HIS1 NP_984602.1 27.273 99 62 4 161 249 52 150 0.44 29.3
HIS1 NP_984995.1 34.483 29 19 0 80 108 135 163 3.2 26.9
HIS1 NP_984930.1 33.333 45 26 1 115 159 605 645 4.1 26.6
HIS1 NP_982470.1 33.333 33 22 0 56 88 332 364 8.6 25.8