1 # Copyright 2008 by Peter Cock. All rights reserved.
3 # This code is part of the Biopython distribution and governed by its
4 # license. Please see the LICENSE file that should have been included
5 # as part of this package.
7 """Bio.SeqIO support for the "ace" file format.
9 You are expected to use this module via the Bio.SeqIO functions.
10 See also the Bio.Sequencing.Ace module which offers more than just accessing
11 the contig consensus sequences in an ACE file as SeqRecord objects."""
13 from Bio.Seq import Seq
14 from Bio.SeqRecord import SeqRecord
15 from Bio.Alphabet import generic_nucleotide, generic_dna, generic_rna, Gapped
16 from Bio.Sequencing import Ace
18 #This is a generator function!
19 def AceIterator(handle) :
20 """Returns SeqRecord objects from an ACE file.
22 This uses the Bio.Sequencing.Ace module to do the hard work. Note that
23 by iterating over the file in a single pass, we are forced to ignore any
24 WA, CT, RT or WR footer tags."""
26 for ace_contig in Ace.parse(handle) :
27 #Convert the ACE contig record into a SeqRecord...
28 consensus_seq_str = ace_contig.sequence
29 #Assume its DNA unless there is a U in it,
30 if "U" in consensus_seq_str :
31 if "T" in consensus_seq_str :
33 alpha = generic_ncleotide
39 if "*" in consensus_seq_str :
40 #For consistency with most other file formats, map
41 #any * gaps into 0 gaps.
42 assert "-" not in consensus_seq_str
43 consensus_seq = Seq(consensus_seq_str.replace("*","-"),
44 Gapped(alpha, gap_char="-"))
46 consensus_seq = Seq(consensus_seq_str, alpha)
48 #TODO - Consensus base quality (BQ lines). Note that any gaps
49 #(* character) in the consensus does not get a quality entry.
50 #This really needs Biopython support for per-letter-annotation.
52 #TODO? - Base segments (BS lines) which indicates which read
53 #phrap has chosen to be the consensus at a particular position.
54 #Perhaps as SeqFeature objects?
56 #TODO - Supporting reads (RD lines, plus perhaps QA and DS lines)
57 #Perhaps as SeqFeature objects?
59 seq_record = SeqRecord(consensus_seq,
61 name = ace_contig.name)