Exemplo n.º 1
0
def test_conversion_highlevel(path):
    """
    Test whether the high-level GFF3 interface can properly read
    the features from a GFF3 file and write these properties to a file
    without data changing.
    The 'phase' is tested additionally, since it is not part of a
    `Feature` object.
    """
    gff_file = gff.GFFFile.read(join(data_dir("sequence"), path))
    ref_annot = gff.get_annotation(gff_file)
    ref_phases = []
    for _, _, type, _, _, _, _, phase, _ in gff_file:
        if type == "CDS":
            ref_phases.append(phase)

    gff_file = gff.GFFFile()
    gff.set_annotation(gff_file, ref_annot)
    temp = TemporaryFile("w+")
    gff_file.write(temp)

    temp.seek(0)
    gff_file = gff.GFFFile.read(temp)
    temp.close()
    test_annot = gff.get_annotation(gff_file)
    test_phases = []
    for _, _, type, _, _, _, _, phase, _ in gff_file:
        if type == "CDS":
            test_phases.append(phase)
    
    assert ref_annot == test_annot
    assert test_phases == ref_phases
Exemplo n.º 2
0
def test_conversion_highlevel(path):
    """
    Test whether the high-level GFF3 interface can properly read
    the features from a GFF3 file and write these properties to a file
    without data changing.
    The 'phase' is tested additionally, since it is not part of a
    `Feature` object.
    """
    file = gff.GFFFile()
    file.read(join(data_dir, path))
    ref_annot = gff.get_annotation(file)
    ref_phases = []
    for _, _, type, _, _, _, _, phase, _ in file:
        if type == "CDS":
            ref_phases.append(phase)

    file = gff.GFFFile()
    gff.set_annotation(file, ref_annot)
    temp_file_name = biotite.temp_file("gff3")
    file.write(temp_file_name)

    file = gff.GFFFile()
    file.read(temp_file_name)
    test_annot = gff.get_annotation(file)
    test_phases = []
    for _, _, type, _, _, _, _, phase, _ in file:
        if type == "CDS":
            test_phases.append(phase)
    
    assert ref_annot == test_annot
    assert test_phases == ref_phases
Exemplo n.º 3
0
def test_genbank_consistency(path):
    """
    Test whether the same annotation (if reasonable) can be read from a
    GFF3 file and a GenBank file.
    """
    gb_file = gb.GenBankFile.read(join(data_dir("sequence"), path))
    ref_annot = gb.get_annotation(gb_file)

    gff_file = gff.GFFFile.read(join(data_dir("sequence"), path[:-3] + ".gff3"))
    test_annot = gff.get_annotation(gff_file)
    
    # Remove qualifiers, since they will be different
    # in GFF3 and GenBank
    ref_annot = seq.Annotation(
        [seq.Feature(feature.key, feature.locs) for feature in ref_annot]
    )
    test_annot = seq.Annotation(
        [seq.Feature(feature.key, feature.locs) for feature in test_annot]
    )
    for feature in test_annot:
        # Only CDS, gene, intron and exon should be equal
        # in GenBank and GFF3
        if feature.key in ["CDS", "gene", "intron", "exon"]:
            try:
                assert feature in test_annot
            except AssertionError:
                print(feature.key)
                for loc in feature.locs:
                    print(loc)
                raise