Beispiel #1
0
def test_fragments_by_id__usingwebservice_withsomebadid(base_url):
    with requests_mock.mock() as m:
        url = base_url + '/fragments?fragment_ids=2n2k_MTN_frag1,foo-bar'
        # TODO use value mol
        fragments = [{
            'nr_r_groups': 0, 'smiles': 'CC1(C)C=C(C[S-])C(C)(C)[NH+]1O', 'pdb_code': '2n2k',
            'atom_codes': 'O1,N1,C1,C2,C3,C4,S1,C5,C6,C7,C8,C9', 'het_code': 'MTN', 'hash_code': 'd491952cd7c9dc30',
            'frag_nr': 1, 'frag_id': '2n2k_MTN_frag1', 'rowid': 175992, 'het_chain': 'A', 'het_seq_nr': 101,
            'prot_chain': 'A', 'uniprot_acc': 'P0CG48', 'uniprot_name': 'Polyubiquitin-C', 'prot_name': 'ubiquitin',
            'ec_number': None, 'mol': None,
            'pdb_title': 'Ensemble structure of the closed state of Lys63-linked diubiquitin in the absence of a ligand',
        }]
        body = {
            'detail': "Fragment with identifier 'foo-bar' not found",
            'absent_identifiers': ['foo-bar'],
            'fragments': fragments,
            'status': 404,
            'title': 'Not Found',
            'type': 'about:blank'
        }
        m.get(url, json=body, status_code=404, headers={'Content-Type': 'application/problem+json'})

        with pytest.raises(IncompleteFragments) as e:
            frag_ids = pd.Series(['2n2k_MTN_frag1', 'foo-bar'])
            fragments_by_id(frag_ids, base_url)

        assert_frame_equal(pd.DataFrame(fragments), e.value.fragments)
        assert e.value.absent_identifiers == ['foo-bar']
Beispiel #2
0
def test_fragments_by_id__withbadid():
    frag_ids = pd.Series(['foo-bar'])

    with pytest.raises(IncompleteFragments) as e:
        fragments_by_id(frag_ids, 'data/fragments.sqlite')

    assert_frame_equal(e.value.fragments, pd.DataFrame())
    assert e.value.absent_identifiers == ['foo-bar']
Beispiel #3
0
def test_fragments_by_id__withbadid():
    frag_ids = pd.Series(['foo-bar'])

    with pytest.raises(IncompleteFragments) as e:
        fragments_by_id(frag_ids, 'data/fragments.sqlite')

    assert_frame_equal(e.value.fragments, pd.DataFrame())
    assert e.value.absent_identifiers == ['foo-bar']
Beispiel #4
0
def test_fragments_by_id__withsomebadid():
    frag_ids = pd.Series(['2n2k_MTN_frag1', 'foo-bar'])

    with pytest.raises(IncompleteFragments) as e:
        fragments_by_id(frag_ids, 'data/fragments.sqlite')

    fragments = [{
        'nr_r_groups':
        0,
        'smiles':
        'CC1(C)C=C(C[S-])C(C)(C)[NH+]1O',
        'pdb_code':
        '2n2k',
        'atom_codes':
        'O1,N1,C1,C2,C3,C4,S1,C5,C6,C7,C8,C9',
        'het_code':
        'MTN',
        'hash_code':
        'd491952cd7c9dc30',
        'frag_nr':
        1,
        'frag_id':
        '2n2k_MTN_frag1',
        'rowid':
        175992,
        'het_chain':
        'A',
        'het_seq_nr':
        101,
        'prot_chain':
        'A',
        'uniprot_acc':
        'P0CG48',
        'uniprot_name':
        'Polyubiquitin-C',
        'prot_name':
        'ubiquitin',
        'ec_number':
        None,
        'pdb_title':
        'Ensemble structure of the closed state of Lys63-linked diubiquitin in the absence of a ligand',
    }]
    # ignoring molecules
    e.value.fragments.drop('mol', axis=1, inplace=True, errors='ignore')
    assert_frame_equal(e.value.fragments, pd.DataFrame(fragments))
    assert e.value.absent_identifiers == ['foo-bar']
Beispiel #5
0
def test_fragments_by_id__withsomebadid():
    frag_ids = pd.Series(['2n2k_MTN_frag1', 'foo-bar'])

    with pytest.raises(IncompleteFragments) as e:
        fragments_by_id(frag_ids, 'data/fragments.sqlite')

    fragments = [{
        'nr_r_groups': 0, 'smiles': 'CC1(C)C=C(C[S-])C(C)(C)[NH+]1O', 'pdb_code': '2n2k',
        'atom_codes': 'O1,N1,C1,C2,C3,C4,S1,C5,C6,C7,C8,C9', 'het_code': 'MTN', 'hash_code': 'd491952cd7c9dc30',
        'frag_nr': 1, 'frag_id': '2n2k_MTN_frag1', 'rowid': 175992, 'het_chain': 'A', 'het_seq_nr': 101,
        'prot_chain': 'A', 'uniprot_acc': 'P0CG48', 'uniprot_name': 'Polyubiquitin-C', 'prot_name': 'ubiquitin',
        'ec_number': None,
        'pdb_title': 'Ensemble structure of the closed state of Lys63-linked diubiquitin in the absence of a ligand',
    }]
    # ignoring molecules
    e.value.fragments.drop('mol', axis=1, inplace=True, errors='ignore')
    assert_frame_equal(e.value.fragments, pd.DataFrame(fragments))
    assert e.value.absent_identifiers == ['foo-bar']
Beispiel #6
0
def test_fragments_by_id__usingwebservice_withbadid(base_url):
    with requests_mock.mock() as m:
        url = base_url + '/fragments?fragment_ids=foo-bar'
        body = {
            'detail': "Fragment with identifier 'foo-bar' not found",
            'absent_identifiers': ['foo-bar'],
            'fragments': [],
            'status': 404,
            'title': 'Not Found',
            'type': 'about:blank'
        }
        m.get(url, json=body, status_code=404, headers={'Content-Type': 'application/problem+json'})

        with pytest.raises(IncompleteFragments) as e:
            frag_ids = pd.Series(['foo-bar'])
            fragments_by_id(frag_ids, base_url)

        assert e.value.fragments.empty
        assert e.value.absent_identifiers == ['foo-bar']
Beispiel #7
0
def test_fragments_by_id__usingwebservice_withbadid(base_url):
    with requests_mock.mock() as m:
        url = base_url + '/fragments?fragment_ids=foo-bar'
        body = {
            'detail': "Fragment with identifier 'foo-bar' not found",
            'absent_identifiers': ['foo-bar'],
            'fragments': [],
            'status': 404,
            'title': 'Not Found',
            'type': 'about:blank'
        }
        m.get(url,
              json=body,
              status_code=404,
              headers={'Content-Type': 'application/problem+json'})

        with pytest.raises(IncompleteFragments) as e:
            frag_ids = pd.Series(['foo-bar'])
            fragments_by_id(frag_ids, base_url)

        assert e.value.fragments.empty
        assert e.value.absent_identifiers == ['foo-bar']
Beispiel #8
0
def test_fragments_by_id():
    frag_ids = pd.Series(['2n2k_MTN_frag1'])

    result = fragments_by_id(frag_ids, 'data/fragments.sqlite')

    # ignoring molecules
    result.drop('mol', axis=1, inplace=True)
    expected = [{
        'nr_r_groups': 0, 'smiles': 'CC1(C)C=C(C[S-])C(C)(C)[NH+]1O', 'pdb_code': '2n2k',
        'atom_codes': 'O1,N1,C1,C2,C3,C4,S1,C5,C6,C7,C8,C9', 'het_code': 'MTN', 'hash_code': 'd491952cd7c9dc30',
        'frag_nr': 1, 'frag_id': '2n2k_MTN_frag1', 'rowid': 175992, 'het_chain': 'A', 'het_seq_nr': 101,
        'prot_chain': 'A', 'uniprot_acc': 'P0CG48', 'uniprot_name': 'Polyubiquitin-C', 'prot_name': 'ubiquitin',
        'ec_number': None,
        'pdb_title': 'Ensemble structure of the closed state of Lys63-linked diubiquitin in the absence of a ligand',
    }]
    assert_frame_equal(result, pd.DataFrame(expected))
Beispiel #9
0
def test_fragments_by_id_with_prefix():
    frag_ids = pd.Series(['2n2k_MTN_frag1'])

    result = fragments_by_id(frag_ids, 'data/fragments.sqlite', 'prefix_')

    # ignoring molecules
    result.drop('prefix_mol', axis=1, inplace=True)
    expected = [{
        'prefix_nr_r_groups':
        0,
        'prefix_smiles':
        'CC1(C)C=C(C[S-])C(C)(C)[NH+]1O',
        'prefix_pdb_code':
        '2n2k',
        'prefix_atom_codes':
        'O1,N1,C1,C2,C3,C4,S1,C5,C6,C7,C8,C9',
        'prefix_het_code':
        'MTN',
        'prefix_hash_code':
        'd491952cd7c9dc30',
        'prefix_frag_nr':
        1,
        'prefix_frag_id':
        '2n2k_MTN_frag1',
        'prefix_rowid':
        175992,
        'prefix_het_chain':
        'A',
        'prefix_het_seq_nr':
        101,
        'prefix_prot_chain':
        'A',
        'prefix_uniprot_acc':
        'P0CG48',
        'prefix_uniprot_name':
        'Polyubiquitin-C',
        'prefix_prot_name':
        'ubiquitin',
        'prefix_ec_number':
        None,
        'prefix_pdb_title':
        'Ensemble structure of the closed state of Lys63-linked diubiquitin in the absence of a ligand',
    }]
    assert_frame_equal(result, pd.DataFrame(expected))
from kripodb.canned import fragments_by_pdb_codes, fragments_by_id

# Map options to kripo arguments
id_column = options['id_column']
fragments_db_filename = options['fragmentsdb']
id_type = options['id_type']

# Select input column
queries = input_table[id_column]

# Fetch fragments
if id_type == 'pdb':
    output_table = fragments_by_pdb_codes(queries, fragments_db_filename)
elif id_type == 'fragment':
    output_table = fragments_by_id(queries, fragments_db_filename)
else:
    raise NotImplementedError('Type of identifier unknown')
Beispiel #11
0
def test_fragments_by_id__usingwebservice_withsomebadid(base_url):
    with requests_mock.mock() as m:
        url = base_url + '/fragments?fragment_ids=2n2k_MTN_frag1,foo-bar'
        # TODO use value mol
        fragments = [{
            'nr_r_groups':
            0,
            'smiles':
            'CC1(C)C=C(C[S-])C(C)(C)[NH+]1O',
            'pdb_code':
            '2n2k',
            'atom_codes':
            'O1,N1,C1,C2,C3,C4,S1,C5,C6,C7,C8,C9',
            'het_code':
            'MTN',
            'hash_code':
            'd491952cd7c9dc30',
            'frag_nr':
            1,
            'frag_id':
            '2n2k_MTN_frag1',
            'rowid':
            175992,
            'het_chain':
            'A',
            'het_seq_nr':
            101,
            'prot_chain':
            'A',
            'uniprot_acc':
            'P0CG48',
            'uniprot_name':
            'Polyubiquitin-C',
            'prot_name':
            'ubiquitin',
            'ec_number':
            None,
            'mol':
            None,
            'pdb_title':
            'Ensemble structure of the closed state of Lys63-linked diubiquitin in the absence of a ligand',
        }]
        body = {
            'detail': "Fragment with identifier 'foo-bar' not found",
            'absent_identifiers': ['foo-bar'],
            'fragments': fragments,
            'status': 404,
            'title': 'Not Found',
            'type': 'about:blank'
        }
        m.get(url,
              json=body,
              status_code=404,
              headers={'Content-Type': 'application/problem+json'})

        with pytest.raises(IncompleteFragments) as e:
            frag_ids = pd.Series(['2n2k_MTN_frag1', 'foo-bar'])
            fragments_by_id(frag_ids, base_url)

        assert_frame_equal(pd.DataFrame(fragments), e.value.fragments)
        assert e.value.absent_identifiers == ['foo-bar']