fixed MPRT

This commit is contained in:
Fizzizist 2025-02-18 21:00:05 -05:00
parent 8d4cc2b83c
commit 43de339fc5
2 changed files with 42 additions and 31 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.venv
*.txt

View File

@ -3,8 +3,10 @@
# Problem can be found at http://rosalind.info/problems/mprt/
# Author: Peter Vlasveld
import urllib2
import re
from time import sleep
import requests
# declare motif
motif = "N[^P][ST][^P]"
@ -19,14 +21,19 @@ f1 = open("output.txt", "w+")
# loop through each accession ID
for i in content:
# get fasta from url
url = "http://www.uniprot.org/uniprot/" + i + ".fasta"
response = urllib2.urlopen(url)
fasta = response.read().splitlines()
url = "http://www.uniprot.org/uniprot/" + i.split("_")[0] + ".fasta"
response = requests.get(url)
if response.status_code != 200:
print(f"uniprot request failed for {i}")
print(f"detail: {response.text}")
fasta = response.text.splitlines()
# format protein string
protStr = ""
for j in fasta:
if not j.startswith('>'):
if not j.startswith(">"):
protStr += j
# construct output strings
outStr = ""
@ -36,9 +43,11 @@ for i in content:
# output
if not outStr == "":
print i
print(i)
f1.write(i + "\n")
print outStr
print(outStr)
f1.write(outStr + "\n")
sleep(1)
# close output file
f1.close()