当前位置: 首页>>代码示例>>Python>>正文


Python SeqFeature.qualifiers[key]方法代码示例

本文整理汇总了Python中Bio.SeqFeature.SeqFeature.qualifiers[key]方法的典型用法代码示例。如果您正苦于以下问题:Python SeqFeature.qualifiers[key]方法的具体用法?Python SeqFeature.qualifiers[key]怎么用?Python SeqFeature.qualifiers[key]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bio.SeqFeature.SeqFeature的用法示例。


在下文中一共展示了SeqFeature.qualifiers[key]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_gff

# 需要导入模块: from Bio.SeqFeature import SeqFeature [as 别名]
# 或者: from Bio.SeqFeature.SeqFeature import qualifiers[key] [as 别名]
def parse_gff(handle):
    """Quick hack to parse Bacterial GFF files from Prokka etc.

    Does NOT support multi-line features (i.e. splicing and
    multiple exons). Will load EVERYTHING into memory!

    Iterator yielding SeqRecord objects, intended to fit into the
    Biopython SeqIO structure.
    """
    line = handle.readline()
    assert line.startswith("##gff-version 3"), line
    # print("Parsing GFF3")
    references = OrderedDict()
    for line in handle:
        # print(line)
        if line.startswith("##sequence-region "):
            _, name, start, end = line.split()
            assert start == "1"
            references[name] = SeqRecord(
                UnknownSeq(int(end)), id=name, name=name)
        elif line.strip() == "##FASTA":
            break
        elif line.startswith("#"):
            raise NotImplementedError(line)
        elif line.count("\t") == 8:
            seqid, source, ftype, start, end, score, strand, phase, attributes = line.split(
                "\t")
            assert seqid in references, "Reference %r not declared with ##sequence-region line:\n%r" % (
                seqid, line)
            start = int(start) - 1
            end = int(end)
            assert 0 <= start < end < len(references[seqid])
            if ftype in FEATURE_TYPE_TO_IGNORE:
                continue
            if FEATURE_TYPE_WANTED and ftype not in FEATURE_TYPE_WANTED:
                continue
            if strand == "+":
                loc = FeatureLocation(start, end, +1)
            elif strand == "-":
                loc = FeatureLocation(start, end, -1)
            elif strand == ".":
                # Unstranded - should use zero but +1 to match EMBL/GB
                loc = FeatureLocation(start, end, +1)
            elif strand == "?":
                # Stranded by missing - should use None but +1 to match EMBL/GB
                loc = FeatureLocation(start, end, +1)
            else:
                raise ValueError("Bad strand %r in line:\n%r" % (strand, line))
            f = SeqFeature(loc, type=ftype)
            for part in attributes.strip().split(";"):
                if not part:
                    assert ";;" in line, line
                    sys.stderr.write(
                        "Warning - missing key=value or double semi-colon in line:\n%r\n" % line)
                    continue
                if "=" not in part:
                    sys.exit("Bad key=value entry %r in line:\n%r" %
                             (part, line))
                key, value = part.split("=", 1)
                if key in MISSING_QUALIFIERS_TO_IGNORE:
                    continue
                if key == "eC_number":
                    key = "EC_number"
                value = value.replace("%2C", ",")
                try:
                    f.qualifiers[key].append(value)
                except KeyError:
                    f.qualifiers[key] = [value]
            references[seqid].features.append(f)
        else:
            raise NotImplementedError(line)
    # Deal with any FASTA block
    name = None
    seqs = []
    for line in handle:
        if line.startswith(">"):
            if name and seqs:
                seq = "".join(seqs)
                assert len(seq) == len(references[name]), \
                    "FASTA entry for %s was %i long, expected %i" % (
                        name, len(seq), len(references[name]))
                references[name].seq = Seq(seq)
            name = line[1:].split(None, 1)[0]
            seqs = []
        elif name:
            seqs.append(line.strip())
        elif line.strip():
            raise NotImplementedError(line)
    if name and seqs:
        seq = "".join(seqs)
        assert len(seq) == len(references[name]), \
            "FASTA entry for %s was %i long, expected %i" % (
                name, len(seq), len(references[name]))
        references[name].seq = Seq(seq)
    # Return results
    for name, record in references.items():
        # print("%s length %i with %i features" % (name, len(record), len(record.seq)))
        yield record
开发者ID:peterjc,项目名称:picobio,代码行数:100,代码来源:annotation_diff.py


注:本文中的Bio.SeqFeature.SeqFeature.qualifiers[key]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。