Created
November 29, 2012 01:04
-
-
Save radaniba/4166002 to your computer and use it in GitHub Desktop.
A typical task in bioinformatics analysis is the usage of online tools. Regardless of the task to be done, there is a general approach to display results in tables so that the user can sort the results or filter them or just view them and try to understan
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
from BeautifulSoup import BeautifulSoup | |
import urllib | |
import xlwt | |
wb = xlwt.Workbook() | |
ws = wb.add_sheet('a test sheet') | |
f = urllib.urlopen("http://www.ebi.ac.uk/Tools/services/web/blastresult.ebi?tool=ncbiblast&jobId=ncbiblast-I20120714-161017-0108-80986175-pg&context=nucleotide") | |
html = f.read() | |
soup = BeautifulSoup(html) | |
#print soup.prettify() | |
#print soup | |
table = soup.find("table",id="alignmentTable") | |
rows = table.findAll("tr") | |
x = 0 | |
for tr in rows: | |
cols = tr.findAll("td") | |
if not cols: | |
# when we hit an empty row, we should not print anything to the workbook | |
continue | |
y = 0 | |
for td in cols: | |
texte_bu = td.text | |
texte_bu = texte_bu.encode('utf-8') | |
texte_bu = texte_bu.strip() | |
ws.write(x, y, td.text) | |
print(x, y, td.text) | |
y = y + 1 | |
# update the row pointer AFTER a row has been printed | |
# this avoids the blank row at the top of your table | |
x = x + 1 | |
wb.save('BlastResults.xls') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment