José Manuel Suárez Sierra wrote: > hello everyone, > Im trying to make a program that takes an archive from pdb (for instance > this link http://www.rcsb.org/pdb/files/fasta.txt?structureIdList=5HXY > > after reading it I want it to save in a list only this part of the > archive: > > MGSSHHHHHHSSGLVPRGSHMASMTGGQQ...IRFIQQILGHASVATTQIYTHLNDSALREMYTQHRPRY > > I have written this: > > import urllib2 > > > seq=raw_input("Introduce pdb code \n") > > > > seq = > urllib2.urlopen( > "http://www.rcsb.org/pdb/files/fasta.txt?structureIdList="+seq) > print seq.read() > > > seq.close() > > > My question is, how do I save this into a python list?
While you could cook up something yourself it's probably better to use an existing library like biopython. $ cat retrieve_fasta.py import urllib2 import Bio.SeqIO seq = raw_input("Introduce pdb code \n") seq = urllib2.urlopen( "http://www.rcsb.org/pdb/files/fasta.txt?structureIdList=" + seq ) for record in Bio.SeqIO.parse(seq, "fasta"): seq_list = list(record.seq.tostring()) break # stop after the first iteration print seq_list $ python retrieve_fasta.py Introduce pdb code 5HXY ['M', 'G', 'S', 'S', 'H', 'H', 'H', 'H', 'H', 'H', 'S', 'S', 'G', 'L', 'V', ... 'R', 'Y'] See <http://biopython.org/wiki/SeqIO>. -- https://mail.python.org/mailman/listinfo/python-list