Logo Search packages:      
Sourcecode: python-biopython version File versions  Download package

def Bio::SeqIO::StockholmIO::StockholmWriter::write_record (   self,

Write a single Stockholm record to the file

Definition at line 336 of file StockholmIO.py.

00336                                   :
        """Write a single Stockholm record to the file"""
        assert self._header_written
        assert not self._footer_written
        self._record_written = True

        if self._length_of_sequences is None :
            self._length_of_sequences = len(record.seq)
        elif self._length_of_sequences <> len(record.seq) :
            raise ValueError("Sequences must all be the same length")

        if self._length_of_sequences == 0 :
            raise ValueError("Non-empty sequences are required")
        #For the case for stockholm to stockholm, try and use record.name
        seq_name = record.id
        if record.name is not None :
            if "accession" in record.annotations :
                if record.id == record.annotations["accession"] :
                    seq_name = record.name

        #In the Stockholm file format, spaces are not allowed in the id
        seq_name = seq_name.replace(" ","_")

        if "start" in record.annotations \
        and  "end" in record.annotations :
            suffix = "/%s-%s" % (str(record.annotations["start"]),
            if seq_name[-len(suffix):] <> suffix :
                seq_name = "%s/%s-%s" % (seq_name,

        if seq_name in self._ids_written :
            raise ValueError("Duplicate record identifier: %s" % seq_name)
        self.handle.write("%s %s\n" % (seq_name, record.seq.tostring()))

        #The recommended placement for GS lines (per sequence annotation)
        #is above the alignment (as a header block) or just below the
        #corresponding sequence.
        #The recommended placement for GR lines (per sequence per column
        #annotation such as secondary structure) is just below the
        #corresponding sequence.
        #We put both just below the corresponding sequence as this allows
        #us to write the file using a single pass through the records.

        #AC = Accession
        if "accession" in record.annotations :
            self.handle.write("#=GS %s AC %s\n" % (seq_name, self.clean(record.annotations["accession"])))
        elif record.id :
            self.handle.write("#=GS %s AC %s\n" % (seq_name, self.clean(record.id)))
        #DE = description
        if record.description :
            self.handle.write("#=GS %s DE %s\n" % (seq_name, self.clean(record.description)))

        #DE = database links
        for xref in record.dbxrefs :
            self.handle.write("#=GS %s DR %s\n" % (seq_name, self.clean(xref)))

        #GS/GR = other per sequence annotation
        for key in record.annotations :
            if key in self.pfam_gs_mapping :
                self.handle.write("#=GS %s %s %s\n" \
                                  % (seq_name,
            elif key in self.pfam_gr_mapping :
                if len(str(record.annotations[key]))==len(record.seq) :
                    self.handle.write("#=GR %s %s %s\n" \
                                      % (seq_name,
                else :
                    #Should we print a warning?
            else :
                #It doesn't follow the PFAM standards, but should we record this data anyway?

    def write_footer(self):

Generated by  Doxygen 1.6.0   Back to index