當前位置: 首頁>>代碼示例>>Python>>正文


Python CodonTable.TranslationError方法代碼示例

本文整理匯總了Python中Bio.Data.CodonTable.TranslationError方法的典型用法代碼示例。如果您正苦於以下問題:Python CodonTable.TranslationError方法的具體用法?Python CodonTable.TranslationError怎麽用?Python CodonTable.TranslationError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bio.Data.CodonTable的用法示例。


在下文中一共展示了CodonTable.TranslationError方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read_cds

# 需要導入模塊: from Bio.Data import CodonTable [as 別名]
# 或者: from Bio.Data.CodonTable import TranslationError [as 別名]
def read_cds(self, to_stop=True, cds=True):
        for i, seq in enumerate(SeqIO.parse(self.cds_fasta, 'fasta')):
            gid = "{0}_{1:0>5}".format(self.prefix, i)
            try:
                aa_seq = seq.translate(to_stop=to_stop, cds=cds, id=seq.id)
            except TranslationError as e:
                logging.error("Translation error ({}) in seq {}".format(
                    e, seq.id))
                continue
            self.cds_seqs[gid] = seq
            self.pro_seqs[gid] = aa_seq
        return 
開發者ID:arzwa,項目名稱:wgd,代碼行數:14,代碼來源:diamond.py

示例2: _ensure_valid_translation

# 需要導入模塊: from Bio.Data import CodonTable [as 別名]
# 或者: from Bio.Data.CodonTable import TranslationError [as 別名]
def _ensure_valid_translation(translation: str, location: Location, transl_table: int,
                              record: Optional[Any]) -> str:
    """ Ensures that a given translation is valid for the matching location
        and record (if given). If a record is given and a translation contains
        invalid characters, an attempt will be made to generate a valid translation.

        Arguments:
            translation: the existing translation, if any
            location: the location of the feature owning the translation
            record: the Record the feature belongs to, or None to skip those checks and regeneration

        Returns:
            a valid translation
    """
    # ensure translation is valid if it exists
    if translation:
        invalid = set(translation) - _VALID_TRANSLATION_CHARS
        if invalid:
            logging.warning("Regenerating translation for CDS at %s containing invalid characters: %s",
                            location, invalid)
            translation = ""
    # ensure that the translation fits
    if not _is_valid_translation_length(translation, location):
        raise ValueError("translation longer than location allows: %s > %s" % (
                         len(translation) * 3, len(location)))
    # if an arbitrary section of a record is used, the record can be too short for a given translation
    if record and not _translation_fits_in_record(len(translation)*3, location, len(record.seq)):
        raise ValueError("feature translation extends out of record")
    # finally, generate the translation if it doesn't exist
    if not translation:
        if not record:
            raise ValueError("no translation in CDS and no record to generate it with")
        if location.end > len(record.seq):
            raise ValueError("feature missing translation and sequence too short")
        if len(location) < 3:
            raise ValueError("CDS too short to generate translation")
        try:
            translation = record.get_aa_translation_from_location(location, transl_table)
        except CodonTable.TranslationError as err:
            raise ValueError("invalid codon: %s" % err)

    assert _is_valid_translation_length(translation, location)
    return translation 
開發者ID:antismash,項目名稱:antismash,代碼行數:45,代碼來源:cds_feature.py

示例3: check_cds

# 需要導入模塊: from Bio.Data import CodonTable [as 別名]
# 或者: from Bio.Data.CodonTable import TranslationError [as 別名]
def check_cds(cdsfile, out1, out2, rename=False, prefix=None):
    """
    Check a file of CDS sequences whether they are proper CDS.

    :param cdsfile: CDS file name
    :param out1: output filename for proper CDS sequences
    :param out2: output filename for dubitable CDS sequences
    :param rename: should the gene IDs be renamed?
    :param prefix: prefix in case rename=True (defaults to the filename)
    :return: nada
    """
    if not prefix:
        prefix = cdsfile
    x = 0
    y = 0
    d = {}
    with open(out2, "w") as f2:
        with open(out1, "w") as f1:
            for i, seq_record in enumerate(SeqIO.parse(cdsfile, 'fasta')):
                if rename:
                    gid = "{0}_{1:0>5}".format(prefix, i)
                    d[seq_record.id] = gid
                else:
                    gid = seq_record.id
                try:
                    aa_seq = seq_record.seq.translate(to_stop=True, cds=True)
                except TranslationError as e:
                    logging.error("Translation error ({}) in sequence "
                                  "{}".format(e, seq_record.id))
                    f2.write(">{}\n{}\n".format(gid, seq_record.seq))
                    y += 1
                    continue
                f1.write(">{}\n{}\n".format(gid, seq_record.seq))
                x += 1
    t = x + y
    logging.info("{}/{} ({:.2f}%) sequences are perfect CDS (in {})".format(
        x, t, 100*x/t, out1))
    logging.info("{}/{} ({:.2f}%) sequences are not perfect CDS (in {})".format(
        y, t, 100*y/t, out2))
    if rename:
        with open(cdsfile + ".ids.csv", "w") as f:
            f.write("{},{}\n".format(cdsfile, out1))
            for k,v in d.items():
                f.write("{},{}\n".format(k, v)) 
開發者ID:arzwa,項目名稱:wgd,代碼行數:46,代碼來源:pre.py


注:本文中的Bio.Data.CodonTable.TranslationError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。