def test_sars2_legacy(): result = konstel.generate('sars-cov-2-s-legacy.protein', f'{data_dir}/spike.prot.fa') assert result['id'] == 'S:papoheme' result = konstel.generate('sars-cov-2-s-legacy.genome', f'{data_dir}/spike.genome.fa') assert result['id'] == 'S:papoheme'
def generate(scheme: str, file: str, format: typing.Union[str, None] = None, output: str = 'json', length: int = 0, hide_prefix: bool = False): ''' Generate identifier(s) for input file path or stdin according to the specified scheme Returns dict, and prints format specified in OUTPUT :arg scheme: Scheme name; use {scheme}.{directive} if scheme specifies multiple directives :arg file: Input path or - for stdin :arg format: Input format; mandatory if scheme specifies multiple formats :arg output: Output format (json, tsv, table) :arg length: Encoding length; overrides scheme :arg hide_prefix: Hide encoding prefix; overrides scheme ''' outputs = konstel.generate(scheme, file, format, output, length, hide_prefix) print(konstel.format_encodings(outputs, output))
def test_sars2_generate_stdin(): with open(f'{data_dir}/spike.genome.fa') as sys.stdin: result = konstel.generate('sars-cov-2-s.genome', file='-') print(result) assert result['id'] == 'S:sapapag'
def test_sars2_generate_prot(): result = konstel.generate('sars-cov-2-s.protein', f'{data_dir}/spike.prot.fa') print(result) assert result['id'] == 'S:sapapag'
def test_sars2_generate_nucl(): result = konstel.generate('sars-cov-2-s.genome', f'{data_dir}/spike.genome.fa') print(result) assert result['id'] == 'S:sapapag'
def test_sars2_generate_length(): result = konstel.generate('sars-cov-2-s.protein', f'{data_dir}/spike.prot.fa', length=21) assert result['id'] == 'S:huhijig-akihifu-tofikip'
def test_validation_alphabet(): sys.stdin = io.StringIO('ACGTX') with pytest.raises(RuntimeError): konstel.generate('generic.nucl', file='-')
def test_sars2_generate_nucl(): result = konstel.generate('sars-cov-2-s.genome', f'{data_dir}/spike.genome.fa') assert result['id'] == 'S:huhijig-akih'
def test_sars2_generate_prot(): result = konstel.generate('sars-cov-2-s.protein', f'{data_dir}/spike.prot.fa') assert result['id'] == 'S:huhijig-akih'
def test_bio_normalisation(): result1 = konstel.generate('bio.nuc', '-', sequence='ACGT') result2 = konstel.generate('bio.nuc', '-', sequence='A-\nC G\tT') assert result1['id'] == 'bituzu-gupahu-zolodu-lumaki-suripi-rozitu-guhabi' assert result1['id'] == result2['id']
def test_direct_string_input(): result = konstel.generate('string', '-', sequence='ACGT') assert result['id'] == 'bituzu-gupahu-zolodu-lumaki-suripi-rozitu-guhabi'
def test_stdin_string(): sys.stdin = io.StringIO('ACGT') result = konstel.generate('string', file='-') assert result['id'] == 'bituzu-gupahu-zolodu-lumaki-suripi-rozitu-guhabi'