Beispiel #1
0
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'
Beispiel #2
0
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))
Beispiel #3
0
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'
Beispiel #4
0
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'
Beispiel #5
0
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'
Beispiel #6
0
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'
Beispiel #7
0
def test_validation_alphabet():
    sys.stdin = io.StringIO('ACGTX')
    with pytest.raises(RuntimeError):
        konstel.generate('generic.nucl', file='-')
Beispiel #8
0
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'
Beispiel #9
0
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'
Beispiel #10
0
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']
Beispiel #11
0
def test_direct_string_input():
    result = konstel.generate('string', '-', sequence='ACGT')
    assert result['id'] == 'bituzu-gupahu-zolodu-lumaki-suripi-rozitu-guhabi'
Beispiel #12
0
def test_stdin_string():
    sys.stdin = io.StringIO('ACGT')
    result = konstel.generate('string', file='-')
    assert result['id'] == 'bituzu-gupahu-zolodu-lumaki-suripi-rozitu-guhabi'