From 11c20aca5133f0a02f11cb6e899bdc00a226b641 Mon Sep 17 00:00:00 2001 From: Matt Shirley Date: Mon, 12 Jan 2015 15:25:13 -0500 Subject: [PATCH] Remove bedmask script #38. Add tests to close #35. --- pyfaidx/bedmask.py | 29 ----------------------------- tests/test_feature_split_char.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 29 deletions(-) delete mode 100644 pyfaidx/bedmask.py create mode 100644 tests/test_feature_split_char.py diff --git a/pyfaidx/bedmask.py b/pyfaidx/bedmask.py deleted file mode 100644 index b1a4a6a..0000000 --- a/pyfaidx/bedmask.py +++ /dev/null @@ -1,29 +0,0 @@ -import argparse -from pyfaidx import Fasta, bed_split - - -def mask_sequence(args): - assert len(args.default_seq) == 1 - fasta = Fasta(args.fasta, mutable=True) - for line in args.bed: - rname, start, end = bed_split(line) - if args.action == 'replace': - fasta[rname][start:end] = (end - start) * args.default_seq - elif args.action == 'lowercase': - fasta[rname][start:end] = fasta[rname][start:end].lowercase() - - -def main(): - parser = argparse.ArgumentParser(description="Mask regions in BED file " - "from FASTA file") - parser.add_argument('fasta', type=str, help='FASTA file') - parser.add_argument('bed', type=argparse.FileType('r'), help="bed file of regions to mask") - parser.add_argument('--default_seq', type=str, default='N', - help='default base for missing positions. default: %(default)s') - parser.add_argument('-a', '--action', type=str, default='replace', choices=['replace', 'lowercase'], - help="masking action. default: %(default)s") - args = parser.parse_args() - mask_sequence(args) - -if __name__ == "__main__": - main() diff --git a/tests/test_feature_split_char.py b/tests/test_feature_split_char.py new file mode 100644 index 0000000..9ce8c73 --- /dev/null +++ b/tests/test_feature_split_char.py @@ -0,0 +1,29 @@ +import os +from pyfaidx import Faidx, Fasta +from nose.tools import raises + +path = os.path.dirname(__file__) +os.chdir(path) + + +class TestFeatureSplitChar: + def __init__(self): + self.fasta = os.path.join(path, 'data/genes.fasta') + self.faidx = Faidx(self.fasta, split_char='.') + self.genes = Fasta(self.fasta, split_char='.') + + def test_keys(self): + expect = ['3', 'AB821309', 'KF435149', 'KF435150', 'NM_000465', 'NM_001282543', 'NM_001282545', 'NM_001282548', 'NM_001282549', 'NR_104212', 'NR_104215', 'NR_104216', 'XM_005249642', 'XM_005249643', 'XM_005249644', 'XM_005249645', 'XM_005265507', 'XM_005265508', 'XR_241079', 'XR_241080', 'XR_241081'] + result = sorted(self.genes.keys()) + assert result == expect + + def test_key_function_by_dictionary_get_key(self): + expect = 'TTGAAGATTTTGCATGCAGCAGGTGCGCAAGGTGAAATGTTCACTGTTAAA' + result = self.genes['KF435150'][100-1:150] + assert str(result) == expect + + def test_key_function_by_fetch(self): + expect = 'TTGAAGATTTTGCATGCAGCAGGTGCGCAAGGTGAAATGTTCACTGTTAAA' + result = self.faidx.fetch('KF435150', + 100, 150) + assert str(result) == expect