当前位置: 首页>>代码示例>>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;未经允许,请勿转载。