Example #1
0
 def test_query_with_login(self):
     """A properly authenticated query sould return a dictionary.
     """
     sbh_query = sbha.SynBioHubQuery(sbha.SD2Constants.SD2_SERVER)
     sbh_query.login(self.user, self.password)
     result = sbh_query.query_design_inducers()
     self.assertEqual(type(result), dict)
Example #2
0
 def test_query_without_login(self):
     """An exception should be raised if a query is run without calling login first.
     """
     sbh_query = sbha.SynBioHubQuery(sbha.SD2Constants.SD2_SERVER)
     with self.assertRaises(SPARQLWrapper.SPARQLExceptions.Unauthorized) as exc:
         # Silence the warning generated by SPARQLWrapper when
         # text/html is received instead of JSON
         with warnings.catch_warnings():
             warnings.simplefilter("ignore")
             result = sbh_query.query_design_inducers()
Example #3
0
 def test_wrong_user(self):
     sbh_query = sbha.SynBioHubQuery(sbha.SD2Constants.SD2_SERVER)
     with self.assertRaises(SPARQLWrapper.SPARQLExceptions.Unauthorized) as exc:
         sbh_query.login('Not_the_U5eR', self.password)
Example #4
0
 def test_login(self):
     sbh_query = sbha.SynBioHubQuery(sbha.SD2Constants.SD2_SERVER)
     result = sbh_query.login(self.user, self.password)
     self.assertEqual(result, None)
Example #5
0
 def __init__(self, url):
     self._url = url
     self._query = sbha.SynBioHubQuery(url)
Example #6
0
def main(argv=None):
    args = parse_args(argv)

    # Init logging
    init_logging(args.debug)

    # Get SynBioHub password
    sbh_password = os.getenv('SBH_PASSWORD')
    if sbh_password is None:
        raise Exception('Environment does not contain SBH_PASSWORD')

    if args.staging:
        sbh_query = sbha.SynBioHubQuery(sbha.SD2Constants.SD2_STAGING_SERVER,
                                        spoofed_url=sbha.SD2Constants.SD2_SERVER)
    else:
        sbh_query = sbha.SynBioHubQuery(sbha.SD2Constants.SD2_SERVER)
    logging.info('Authenticating to {}'.format(sbh_query._server))
    sbh_query.login(args.user, sbh_password)
    logging.info('Authentication complete')

    # --------------------------------------------------

    # for s, title in find_grna(sbh_query):
    #     if 'gRNA Gene' in title:
    #         logging.info('%s     %s', s, title)
    # return

    # --------------------------------------------------

    # coll = 'https://hub.sd2e.org/user/sd2e/design/yeast_gates_plasmids/1'
    # coll_members = format_query_result(sbh_query, sbh_query.query_collection_members([coll]))
    # for m in sorted(coll_members):
    #     logging.info('yeast_gates_plasmid: %s', m)

    # --------------------------------------------------

    # Tell me about this thing...

    # subj = 'https://hub.sd2e.org/user/sd2e/design/anno_120009203/1'
    # for p, o in subject_info(sbh_query, subj):
    #     logging.info('%s    %s    %s', subj, p, o)
    # return

    # --------------------------------------------------

    # things = so_query(sbh_query, SBOL_FUNCTIONAL_COMPONENT)
    # for thing in things:
    #     logging.info('%s     ---->     %s', thing['s'], thing['o'])
    # sys.exit(0)

    # definers = subjects_for(sbh_query, SBOL_DEFINITION, 'https://hub.sd2e.org/user/sd2e/design/anno_120009203/1')
    gene = R10_GRNA_GENE
    gene = R3_GRNA_GENE

    data_frame = find_construct_experiments(sbh_query, gene)
    logging.info('Found %d experiments', data_frame.size)

    sys.exit(0)

    for x in results:
        logging.info('%s', x)
        title = title_for(sbh_query, x)
        logging.info('\ttitle: %s', title)
        # for triple in results[x]:
        #     logging.info('\t%r', triple)
        logging.info('--------------------------------------------------')

    sys.exit(0)

    cp_members = {}
    for cp in CHALLENGE_PROBLEMS:
        cp_members[cp] = format_query_result(sbh_query, sbh_query.query_collection_members([cp]))

    for cp in cp_members:
        actual_members = set(members).intersection(set(cp_members[cp]))
        for m in actual_members:
            logging.info('Component of %s (%s)', m, cp)
            titles = title_for(sbh_query, m)
            for title in titles:
                logging.info('%s title: %s', m, title)
            logging.info('Chain: %r', [(cp, SBOL_MEMBER, m)] + results[m])
import sys
import logging

import synbiohub_adapter as sbha
import sbh_prospector as sbhp
"""Find all the strains contained in all the members of the yeast
gates challenge problem.
"""

# Enter the sd2e SynBioHub password
SBH_USER = '******'
SBH_PASSWORD = '******'

# Authenticate to SynBioHub
sbh_query = sbha.SynBioHubQuery(sbha.SD2Constants.SD2_SERVER)
sbh_query.login(SBH_USER, SBH_PASSWORD)

# First get all the members of the yeast gates challenge problem
yg_members = sbhp.objects_for(sbh_query,
                              sbha.SD2Constants.YEAST_GATES_DESIGN_COLLECTION,
                              sbhp.SBOL_MEMBER)
print('Found {} yeast gate challenge problem members'.format(len(yg_members)))

# Iterate through the members, finding contained strains
all_strains = []
print('Looking for strains...', end='', flush=True)
yg_count = 0
for yg in yg_members:
    # print(yg)
    strains = sbhp.find_contained_strains(sbh_query, yg)
    all_strains.extend(strains)