[Biopython] Cookbook suggestion
Justin Gibbons
jgibbons1 at mail.usf.edu
Mon Apr 15 19:40:15 UTC 2013
It looks like there is already an example of this in the tutorial under
18.1.5, but I was planning on making it a self contained cookbook example
so that it is easier to find.
If this is the fastest way to do it though:
with open(new_file_path, "w") as handle:
for seq_id in seq_ids:
handle.write(indexed_fasta.
get_raw(seq_id))
Is there any advantage to using SeqIO.write() other then it being shorter?
I do not have a GitHub account so I cannot comment on whether it would be
easier to use Github.
Thanks,
Justin
On Mon, Apr 15, 2013 at 6:46 AM, Peter Cock <p.j.a.cock at googlemail.com>wrote:
> On Sun, Apr 14, 2013 at 6:58 PM, Justin Gibbons <jgibbons1 at mail.usf.edu>
> wrote:
> > Sorry I accidentally sent the last email.
> >
> > You need the indexed fasta to get a copy of the sequence records that
> match
> > your criteria:
> >
> > indexed_fasta=SeqIO.index(file_path, 'fasta')
> > SeqIO.write( (indexed_fasta[seq_id] for seq_id in seq_ids),
> > new_file_path,'fasta')
>
> With a simple sequential file format like FASTA where there are no complex
> file headers/footers to worry about, this might be the faster route:
>
> with open(new_file_path, "w") as handle:
> for seq_id in seq_ids:
> handle.write(indexed_fasta.get_raw(seq_id))
>
> The idea here is never to parse the records into SeqRecord objects, just
> keep them as raw strings in FASTA format. The same idea works well on
> GenBank or SwissProt files which are slower to parse, there are examples
> of this in the main Tutorial,
> http://biopython.org/DIST/docs/tutorial/Tutorial.html
> http://biopython.org/DIST/docs/tutorial/Tutorial.pdf
>
> Were you intending this to be a self contained cookbook example for:
> http://biopython.org/wiki/Category:Cookbook ?
>
> > As for editing the wiki when I click on "Login with OpenID" I get sent
> to a
> > blank page. I also tried clicking on "Login" and tired to create a new
> > account and was told "The action you have requested is limited to users
> in
> > the group: Administrators<
> http://biopython.org/w/index.php?title=Biopython:Administrators&action=edit&redlink=1
> >
> > ."
>
> Thanks - I've passed that on to our volunteer SysAdmin team.
>
> (As an aside, do you have a GitHub account and would you think
> it would be easier to use the wiki hosted on GitHub instead of
> our own MediaWiki installation?)
>
> Thanks,
>
> Peter
>
More information about the Biopython
mailing list