How to use pyfaidx - 10 common examples

To help you get started, we’ve selected a few pyfaidx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdshw5 / pyfaidx / tests / test_feature_spliced_seq.py View on Github external
def test_split_seq(self):
        """ Fetch sequence by blocks """
        fa = Fasta('data/chr17.hg19.part.fa')
        
        gene = Fasta("data/gene.bed12.fasta")
        expect = gene[list(gene.keys())[0]][:].seq
        
        bed = "data/gene.bed12"
        with open(bed) as fi:
            record = fi.readline().strip().split("\t")

        chrom = record[0]
        start = int(record[1])
        strand = record[5]

        # parse bed12 format
        starts = [int(x) for x in record[11].split(",")[:-1]] 
        sizes = [int(x) for x in record[10].split(",")[:-1]]
        starts = [start + x  for x in starts]
github mdshw5 / pyfaidx / tests / test_feature_read_ahead_buffer.py View on Github external
def test_buffer_value(self):
        Fasta(self.fasta, read_ahead = 0.5)
github mdshw5 / pyfaidx / tests / test_FastaRecord_iter.py View on Github external
def test_reverse_iter(self):
        expect = list(chain(*([line[::-1] for line in record][::-1] for record in Fasta('data/genes.fasta', as_raw=True))))
        result = list(chain(*([line for line in reversed(record)] for record in Fasta('data/genes.fasta', as_raw=True))))
        for a, b in zip(expect, result):
            print(a, b)
        assert expect == result
github mdshw5 / pyfaidx / tests / test_feature_split_char.py View on Github external
def test_key_function_by_fetch(self):
        faidx = Faidx('data/genes.fasta', split_char='|', duplicate_action="drop")
        expect = 'TTGAAGATTTTGCATGCAGCAGGTGCGCAAGGTGAAATGTTCACTGTTAAA'
        result = faidx.fetch('KF435150.1',
                             100, 150)
        assert str(result) == expect
github mdshw5 / pyfaidx / tests / test_feature_bounds_check.py View on Github external
def test_fetch_middle(self):
        faidx = Faidx('data/genes.fasta')
        expect = 'TTGAAGATTTTGCATGCAGCAGGTGCGCAAGGTGAAATGTTCACTGTTAAA'
        result = faidx.fetch('gi|557361099|gb|KF435150.1|',
                             100, 150)
        assert str(result) == expect
github mdshw5 / pyfaidx / tests / test_feature_indexing.py View on Github external
fasta = genes.readlines()
        n_lines = sum(1 for line in fasta)
        for n in range(n_lines):
            with NamedTemporaryFile(mode='w') as lines:
                for i, line in enumerate(fasta):
                    if i == n and line[0] != '>' and len(line) == 71:
                        line = line[:-3] + '\n'
                        full_line = True
                    elif i == n:
                        full_line = False
                    lines.write(line)
                    lines.flush()
                name = lines.name
                if full_line:
                    try:
                        Faidx(name)
                        indexed.append(True)
                    except FastaIndexingError:
                        indexed.append(False)
        assert not any(indexed)
github mdshw5 / pyfaidx / tests / test_feature_indexing.py View on Github external
def test_reindex_on_modification(self):
        """ This test ensures that the index is regenerated when the FASTA
        modification time is newer than the index modification time.
        mdshw5/pyfaidx#50 """
        faidx = Faidx('data/genes.fasta')
        index_mtime = getmtime(faidx.indexname)
        faidx.close()
        os.utime('data/genes.fasta', (index_mtime + 10, ) * 2)
        time.sleep(2)
        faidx = Faidx('data/genes.fasta')
        assert getmtime(faidx.indexname) > index_mtime
github mdshw5 / pyfaidx / tests / test_feature_default_seq.py View on Github external
def __init__(self):
        self.fasta = os.path.join(path, 'data/genes.fasta')
        self.faidx = Faidx(self.fasta, default_seq='N')
github kipoi / kipoiseq / tests / extractors / test_vcf_seq_extractor.py View on Github external
def test_interval_seq_builder_concat(interval_seq_builder):
    with pytest.raises(TypeError):
        interval_seq_builder.concat()

    sequence = Sequence(seq='CCCCATCGNN', start=10, end=20)
    interval_seq_builder.restore(sequence)
    assert interval_seq_builder.concat() == 'CCCCTAGCNN'
github kipoi / kipoiseq / tests / extractors / test_vcf_seq_extractor.py View on Github external
def test__split_overlapping(variant_seq_extractor):
    pair = (Sequence(seq='AAA', start=3, end=6),
            Sequence(seq='T', start=3, end=4))
    splited_pairs = list(variant_seq_extractor._split_overlapping([pair], 5))

    assert splited_pairs[0][0].seq == 'AA'
    assert splited_pairs[0][1].seq == 'T'
    assert splited_pairs[1][0].seq == 'A'
    assert splited_pairs[1][1].seq == ''

    pair = (Sequence(seq='TT', start=3, end=5),
            Sequence(seq='AAA', start=3, end=6))
    splited_pairs = list(variant_seq_extractor._split_overlapping([pair], 4))

    assert splited_pairs[0][0].seq == 'T'
    assert splited_pairs[0][1].seq == 'A'
    assert splited_pairs[1][0].seq == 'T'
    assert splited_pairs[1][1].seq == 'AA'