Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.SeqIO.PhdIO.PhdWriter Class Reference
Inheritance diagram for Bio.SeqIO.PhdIO.PhdWriter:
Inheritance graph
[legend]
Collaboration diagram for Bio.SeqIO.PhdIO.PhdWriter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def write_record
def write_header
def write_footer
def write_records
def write_file
def clean

Public Attributes

 handle

Detailed Description

Class to write Phd format files

Definition at line 92 of file PhdIO.py.


Constructor & Destructor Documentation

def Bio.SeqIO.PhdIO.PhdWriter.__init__ (   self,
  handle 
)
Creates the writer object.

Use the method write_file() to actually record your sequence records.

Reimplemented from Bio.SeqIO.Interfaces.SequentialSequenceWriter.

Definition at line 95 of file PhdIO.py.

00095 
00096     def __init__(self, handle):
00097         SequentialSequenceWriter.__init__(self, handle)


Member Function Documentation

def Bio.SeqIO.Interfaces.SequenceWriter.clean (   self,
  text 
) [inherited]
Use this to avoid getting newlines in the output.

Definition at line 166 of file Interfaces.py.

00166 
00167     def clean(self, text):
00168         """Use this to avoid getting newlines in the output."""
00169         return text.replace("\n", " ").replace("\r", " ").replace("  ", " ")
    

Here is the caller graph for this function:

def Bio.SeqIO.Interfaces.SequentialSequenceWriter.write_file (   self,
  records 
) [inherited]
Use this to write an entire file containing the given records.

records - A list or iterator returning SeqRecord objects

This method can only be called once.  Returns the number of records
written.

Reimplemented from Bio.SeqIO.Interfaces.SequenceWriter.

Definition at line 262 of file Interfaces.py.

00262 
00263     def write_file(self, records):
00264         """Use this to write an entire file containing the given records.
00265 
00266         records - A list or iterator returning SeqRecord objects
00267 
00268         This method can only be called once.  Returns the number of records
00269         written.
00270         """
00271         self.write_header()
00272         count = self.write_records(records)
00273         self.write_footer()
00274         return count

Here is the call graph for this function:

Definition at line 218 of file Interfaces.py.

00218 
00219     def write_footer(self):
00220         assert self._header_written, "You must call write_header() first"
00221         assert self._record_written, "You have not called write_record() or write_records() yet"
00222         assert not self._footer_written, "You have aleady called write_footer()"
00223         self._footer_written = True

Here is the caller graph for this function:

Definition at line 212 of file Interfaces.py.

00212 
00213     def write_header(self):
00214         assert not self._header_written, "You have aleady called write_header()"
00215         assert not self._record_written, "You have aleady called write_record() or write_records()"
00216         assert not self._footer_written, "You have aleady called write_footer()"
00217         self._header_written = True
        

Here is the caller graph for this function:

def Bio.SeqIO.PhdIO.PhdWriter.write_record (   self,
  record 
)
Write a single Phd record to the file.

Reimplemented from Bio.SeqIO.Interfaces.SequentialSequenceWriter.

Definition at line 98 of file PhdIO.py.

00098 
00099     def write_record(self, record):
00100         """Write a single Phd record to the file."""
00101         assert record.seq, "No sequence present in SeqRecord"
00102         # This method returns the 'phred_quality' scores or converted
00103         # 'solexa_quality' scores if present, else raises a value error
00104         phred_qualities = QualityIO._get_phred_quality(record)
00105         peak_locations = record.letter_annotations.get("peak_location", None)
00106         assert len(record.seq) == len(phred_qualities), "Number of " + \
00107                 "phd quality scores does not match length of sequence"
00108         if peak_locations:
00109             assert len(record.seq) == len(peak_locations), "Number " + \
00110                     "of peak location scores does not match length of sequence"
00111         if None in phred_qualities:
00112             raise ValueError("A quality value of None was found")
00113         if record.description.startswith("%s " % record.id):
00114             title = record.description
00115         else:
00116             title = "%s %s" % (record.id, record.description)
00117         self.handle.write("BEGIN_SEQUENCE %s\nBEGIN_COMMENT\n" \
00118                           % self.clean(title))
00119         for annot in [k.lower() for k in Phd.CKEYWORDS]:
00120             value = None
00121             if annot == "trim":
00122                 if record.annotations.get("trim", None):
00123                     value = "%s %s %.4f" % record.annotations["trim"]
00124             elif annot == "trace_peak_area_ratio":
00125                 if record.annotations.get("trace_peak_area_ratio", None):
00126                     value = "%.4f" % record.annotations["trace_peak_area_ratio"]
00127             else:
00128                 value = record.annotations.get(annot, None)
00129             if value or value == 0:
00130                 self.handle.write("%s: %s\n" % (annot.upper(), value))
00131 
00132         self.handle.write("END_COMMENT\nBEGIN_DNA\n")
00133         for i, site in enumerate(record.seq):
00134             if peak_locations:
00135                 self.handle.write("%s %i %i\n" % (
00136                         site,
00137                         round(phred_qualities[i]),
00138                         peak_locations[i])
00139                         )
00140             else:
00141                 self.handle.write("%s %i\n" % (
00142                         site,
00143                         round(phred_qualities[i]))
00144                         )
00145 
00146         self.handle.write("END_DNA\nEND_SEQUENCE\n")

Here is the call graph for this function:

def Bio.SeqIO.Interfaces.SequentialSequenceWriter.write_records (   self,
  records 
) [inherited]
Write multiple record to the output file.

records - A list or iterator returning SeqRecord objects

Once you have called write_header() you can call write_record()
and/or write_records() as many times as needed.  Then call
write_footer() and close().

Returns the number of records written.

Definition at line 240 of file Interfaces.py.

00240 
00241     def write_records(self, records):
00242         """Write multiple record to the output file.
00243 
00244         records - A list or iterator returning SeqRecord objects
00245 
00246         Once you have called write_header() you can call write_record()
00247         and/or write_records() as many times as needed.  Then call
00248         write_footer() and close().
00249 
00250         Returns the number of records written.
00251         """
00252         #Default implementation:
00253         assert self._header_written, "You must call write_header() first"
00254         assert not self._footer_written, "You have already called write_footer()"
00255         count = 0
00256         for record in records:
00257             self.write_record(record)
00258             count += 1
00259         #Mark as true, even if there where no records
00260         self._record_written = True
00261         return count

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from Bio.SeqIO.Interfaces.SequenceWriter.

Definition at line 207 of file Interfaces.py.


The documentation for this class was generated from the following file: