[Biopython] Cookbook suggestion

Peter Cock p.j.a.cock at googlemail.com
Mon Apr 15 06:46:53 EDT 2013


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