Exemplo n.º 1
0
def test_search_field(field, molecular_definition, params, ref_ids):
    query = rcsb.FieldQuery(field, molecular_definition, **params)
    test_ids = rcsb.search(query)
    test_count = rcsb.count(query)

    assert set(test_ids) == set(ref_ids)
    assert test_count == len(ref_ids)
Exemplo n.º 2
0
# and count the number
for i, year in enumerate(years):
    # A query that comprises one year
    date_query = rcsb.FieldQuery(
        "rcsb_accession_info.initial_release_date",
        range_closed=(datetime.combine(datetime(year, 1, 1), time.min),
                      datetime.combine(datetime(year, 12, 31), time.max)))
    xray_query = rcsb.FieldQuery("exptl.method",
                                 exact_match="X-RAY DIFFRACTION")
    nmr_query = rcsb.FieldQuery("exptl.method", exact_match="SOLUTION NMR")
    em_query = rcsb.FieldQuery("exptl.method",
                               exact_match="ELECTRON MICROSCOPY")
    # Get the amount of structures, that were released in that year
    # AND were elucidated with the respective method
    xray_count[i], nmr_count[i], em_count[i] = [
        rcsb.count(date_query & method_query)
        for method_query in [xray_query, nmr_query, em_query]
    ]
    # Get the total amount of structures released in that year
    tot_count[i] = rcsb.count(date_query)

fig, ax = plt.subplots(figsize=(8.0, 5.0))
ax.set_title("PDB release statistics")
ax.set_xlim(years[0] - 1, years[-1] + 1)
ax.set_xticks(years)
ax.set_xticklabels([str(y) for y in years], rotation=45)
ax.set_xlabel("Year")
ax.set_ylabel("Released structures per year")
ax.bar(years, xray_count, color=biotite.colors["darkorange"], label="X-Ray")
ax.bar(years,
       nmr_count,
Exemplo n.º 3
0
########################################################################
# In many cases you are not interested in a specific structure, but you
# want a set of structures that fits your desired criteria.
# For this purpose the *RCSB* search API can be used.
# At first you have to create :class:`Query` object for the property you
# want to filter.
# The :func:`search()` method takes the :class:`Query` and returns a
# list of PDB IDs, which itself can be used as input for
# :func:`fetch()`.
# Likewise, :func:`count()` is used to count the number of matching
# PDB IDs.

query = rcsb.BasicQuery("HCN1")
pdb_ids = rcsb.search(query)
print(pdb_ids)
print(rcsb.count(query))
files = rcsb.fetch(pdb_ids, "mmtf", gettempdir())

########################################################################
# This was a simple search for the occurrence of the search term in any
# field.
# You can also search for a value in a specific field with a
# :class:`FieldQuery`.
# A complete list of the available fields and its supported operators
# is documented
# `on this page <https://search.rcsb.org/search-attributes.html>`_.

# Query for 'lacA' gene
query1 = rcsb.FieldQuery("rcsb_entity_source_organism.rcsb_gene_name.value",
                         exact_match="lacA")
# Query for resolution below 1.5 Å
Exemplo n.º 4
0
def test_search_basic():
    query = rcsb.BasicQuery("tc5b")
    assert rcsb.search(query) == ["1L2Y"]
    assert rcsb.count(query) == 1
Exemplo n.º 5
0
def test_search_invalid(field, params):
    invalid_query = rcsb.FieldQuery(field, **params)
    with pytest.raises(RequestError, match="400"):
        rcsb.search(invalid_query)
    with pytest.raises(RequestError, match="400"):
        rcsb.count(invalid_query)
Exemplo n.º 6
0
def test_search_empty():
    query = rcsb.BasicQuery("This will not match any ID")
    assert rcsb.search(query) == []
    assert rcsb.count(query) == 0
Exemplo n.º 7
0
def test_search_return_type(return_type, expected):
    query = rcsb.BasicQuery("tc5b")
    assert rcsb.search(query, return_type) == expected
    assert rcsb.count(query, return_type) == len(expected)
Exemplo n.º 8
0
def test_search_motif():
    # motif is taken from official RCSB search API tutorial
    MOTIF = "C-x(2,4)-C-x(3)-[LIVMFYWC]-x(8)-H-x(3,5)-H."
    query = rcsb.MotifQuery(MOTIF, "prosite", "protein")
    test_count = rcsb.count(query)
    assert test_count == pytest.approx(503, rel=0.1)