本文整理汇总了Python中Bio.SwissProt类的典型用法代码示例。如果您正苦于以下问题:Python SwissProt类的具体用法?Python SwissProt怎么用?Python SwissProt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SwissProt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: features
def features(files):
ft=['ZN_FING', 'REGION','METAL','SITE','SIGNAL','REPEAT', 'NP_REGION', 'BINDING','MOTIF','MOD_RES', 'LIPID','DOMAIN','DNA_BIND','DISULFID','CROSSLNK', 'CARBOHYD','CA_BIND', 'ACT_SITE']
for record in SwissProt.parse(open(files)):
for l in record.features:
if l[0] in ft:
print l[0]+','+str(l[1])+'-'+str(l[2])+','+l[3]
示例2: gen_uniprot_features_for_pdb
def gen_uniprot_features_for_pdb(infile):
for line in open(infile,'r'):
(pdb_dom, count, uniprot_ids) = line.replace('\n','').split('\t')
uniprot_ids = uniprot_ids.split('|')
for uniprot_id in uniprot_ids:
data = SwissProt.read(ExPASy.get_sprot_raw(uniprot_id)).__dict__
keep = False
go = []; interpro = ''; evo_trace = ''
for xref in data['cross_references']:
if xref[0] == 'GO':
go.append(xref[1])
if xref[0] == 'InterPro':
interpro = xref[1]
if xref[0] == 'EvolutionaryTrace':
evo_trace = xref[1]
if xref[0] == 'PDB' and xref[1].lower() == pdb_dom.lower():
keep = True
if keep == False:
continue
organism = data['organism']
loc = ''
for comment in data['comments']:
if comment.startswith('SUBCELLULAR LOCATION'):
loc = comment
print '%s\t%s\t%s\t%s\t%s\t%s\t%s' %(pdb_dom,uniprot_id,'|'.join(go),interpro,evo_trace,organism,loc)
示例3: get_genes
def get_genes (self,gene_name=""):
if gene_name != "":
print "Finding \"{}\" gene in Uniprot database...".format(gene_name)
upper_name = gene_name.upper() # Rho --> RHO
output_handle = open(self.fasta_file, "w")
for record in SwissProt.parse (self.fd):
match = record.gene_name[5:5+len(upper_name)+1].upper()
# Name=Rhodop; --> RHOD (Length of the queried name (rho)+1)
# For matching the two possibilities
# 1) Name=Rho;
# 2) Name=rho {ECO.....}
# So, it fill compare the queried gene name and match one e.g.
# in 1st case "RHO " == "RHO;" or "RHO;" == "RHO;"
# in 2nd case "RHO " == "RHO " or "RHO;" == "RHO "
# We do not consider gene names differ to "Name=...;" in swisprot file
if (upper_name+" ") == match or (upper_name+";") == match:
print "Add protein to fasta file: " + record.entry_name + ", ...." + record.gene_name
output = ">"+record.entry_name+"\n"+record.sequence.format("fasta")+"\n"
#print output
output_handle.write(output)
output_handle.write("")
output_handle.close()
示例4: get_SwissProt
def get_SwissProt(dict,accession):
try:
handle = ExPASy.get_sprot_raw(accession)
record = SwissProt.read(handle)
dict[accession] = record
except urllib2.HTTPError, error:
print accession + ": protein not found on UniProt . "
示例5: _parse_features
def _parse_features( self ):
print( 'uniprot flat files, to get features...' )
with open( path + files[16], 'wt' ) as outf:
for j in [11,12,13,14]:
print( files[j] + '...' )
with open(path + files[j], 'rt') as handle:
for record in SwissProt.parse(handle):
if record.taxonomy_id[0] in ['9606', '10090', '10116']:
accs = record.accessions
acc = accs.pop(0)
feats = record.features
for f in feats:
f = list(f)
f.insert(3, '')
if re.search(r'^[^\.]+\.\s*$', f[4]):
m = re.match(r'^(.+)\.\s*$', f[4])
if m:
f[3] = m.group(1)
f[4] = ''
elif re.search(r'.+\.\s+\{', f[4]):
m = re.match(r'^(.+)\.\s*\{(.+)\}\.$', f[4])
if m:
f[3] = m.group(1)
f[4] = m.group(2)
elif re.search(r'.+\.\s+\/', f[4]):
m = re.match(r'^(.+)\.\s*\/(.+)\.$', f[4])
if m:
f[3] = m.group(1)
f[4] = m.group(2)
else :
f[4] = re.sub(r'[\{\}\.\/]', '', f[4])
#print(f)
outf.write( acc + "\t" + '\t'.join(map(str, f)) + '\n')
示例6: load_uniprot
def load_uniprot(self):
self.uniprot = None
if not self.exists('uniprot.txt'):
return
with self.open('uniprot.txt') as fp:
self.uniprot = []
for record in SwissProt.parse(fp):
self.uniprot.append(record)
示例7: main
def main(argv):
# input() reads stdin
handle = ExPASy.get_sprot_raw(input().strip()) #you can give several IDs separated by commas
record = SwissProt.read(handle) # use SwissProt.parse for multiple proteins
# there ought to be a better way to pull GO information from the record! maybe there is...
for p in filter(lambda x:x[0]=='GO' and x[2].startswith('P:'),record.cross_references):
print(p[2][2:])
示例8: main
def main():
with open("dbpr") as f:
handle = ExPASy.get_sprot_raw(f.readline().strip())
record = SwissProt.read(handle)
record = [x[2] for x in record.cross_references if x[0] == 'GO']
record = [x[2:] for x in record if x[0] == 'P']
sys.stdout = open("dbpr.out","w")
print "\n".join(record)
示例9: _parse_flat_files
def _parse_flat_files( self ):
print( 'uniprot flat files...' )
with open( path + files[15], 'wt' ) as outf:
for j in [11,12,13,14]:
print( files[j] + '...' )
with open(path + files[j], 'rt') as handle:
for record in SwissProt.parse(handle):
if record.taxonomy_id[0] in ['9606', '10090', '10116']:
accs = record.accessions
acc = accs.pop(0)
rev = record.data_class
gname = re.sub(r'.*Name=([^;{]+)[{;].*', r'\1', record.gene_name).strip()
uid = record.entry_name
taxid = record.taxonomy_id[0]
seq = record.sequence
sinfo = str(record.seqinfo[0])
srcdb = 'sp'
if re.search(r'trembl', files[j]):
srcdb = 'tr'
rname = ''
fname = ''
sname = ''
flags = ''
if 'RecName' in record.description:
rname = re.sub(r'.*RecName: *Full=([^;{]+)[{;].*', r'\1', record.description, re.IGNORECASE).strip()
elif 'SubName' in record.description:
rname = re.sub(r'.*SubName: *Full=([^;{]+) *[;{].*', r'\1', record.description, re.IGNORECASE).strip()
if 'AltName' in record.description:
if re.search(r'AltName:[^:]*Full=', record.description, re.IGNORECASE):
fname = re.sub(r'.*AltName:[^:]*Full=([^;{]+)[{;].*', r'\1', record.description, re.IGNORECASE).strip()
if re.search(r'AltName:[^:]*Short=', record.description, re.IGNORECASE):
sname = re.sub(r'.*AltName:[^:]*Short=([^;{]+)[{;].*', r'\1', record.description, re.IGNORECASE).strip()
if 'Flags:' in record.description:
flags = re.sub(r'.*Flags: *([^;]+);.*', r'\1', record.description, re.IGNORECASE).strip()
refs = list()
eids = list()
mgis = list()
hgnc = list()
dids = list()
dnms = list()
ddbs = list()
for i in range(0, len(record.cross_references)):
if record.cross_references[i][0] == 'GeneID':
eids.append(record.cross_references[i][1])
if record.cross_references[i][0] == 'RefSeq':
refs.append(re.sub(r'\.\d+$', r'', record.cross_references[i][1]))
if record.cross_references[i][0] == 'MGI':
mgis.append(record.cross_references[i][1])
if record.cross_references[i][0] == 'HGNC':
hgnc.append(record.cross_references[i][1])
if record.cross_references[i][0] in xdoms:
dids.append(record.cross_references[i][1])
ddbs.append(record.cross_references[i][0])
dnms.append(record.cross_references[i][2])
outf.write( '\t'.join([ acc, uid, srcdb, taxid, rev, gname, rname, fname, sname, flags, '|'.join(accs), '|'.join(eids), '|'.join(refs), '|'.join(hgnc), '|'.join(mgis), '|'.join(ddbs), '|'.join(dids), '|'.join(dnms), sinfo, seq ]) + '\n' )
示例10: acession
def acession(self):
self.rec=[]
for ide in self.ids:
if ide!='ND':
results=ExPASy.get_sprot_raw(ide)
rec=SwissProt.read(results)
self.rec.append(rec)
else:
self.rec.append('ND')
return self.rec
示例11: get_keywords
def get_keywords(lookup):
try:
handle = ExPASy.get_sprot_raw(lookup)
except:
print("Error in ExPASy")
sys.exit(1)
try:
record = SwissProt.read(handle)
except ValueError, error:
print(error)
sys.exit(1)
示例12: fetch
def fetch(acc) :
'''Downloads data from UniProt.
Input:
acc: accession code of the record
database: database name
Return: the Entrez record
'''
base_url = 'http://www.uniprot.org/uniprot/'
handle = urllib.request.urlopen(base_url + acc + '.txt')
record = SwissProt.read(handle)
return record
示例13: BiologicalProcesses
def BiologicalProcesses(UniProtID):
Handle = ExPASy.get_sprot_raw(UniProtID)
Record = SwissProt.read(Handle)
Processes = []
for i in Record.cross_references:
if "GO" in i:
for j in i:
if re.match("P:.*", j):
Processes.append(j[j.rfind(':')+1:])
return "\n".join(Processes)
示例14: __init__
def __init__(self, sprot_cache='', trembl_cache='', organism='homo sapien'):
self.records = {}
self.organism = organism.strip().lower()
if sprot_cache:
# Load the swissprot records if file can be found
try:
with open(sprot_cache) as fp:
for record in SwissProt.parse(fp):
for accession in record.accessions:
self.records[accession] = record
except IOError, e:
print(e); print("SwissProt cache not loaded")
示例15: main
def main(protein_id):
handle = ExPASy.get_sprot_raw(protein_id) #you can give several IDs separated by commas
record = SwissProt.read(handle) # use SwissProt.parse for multiple proteins
answer = ""
for r in record.cross_references:
print r
if r[0] == "GO":
if r[2].split(":")[0] == 'P':
answer += r[2].split(":")[1] + "\n"
return answer.strip()