コード例 #1
0
ファイル: test_cgd.py プロジェクト: zzygyx9119/mckb
class CGDTestCase(unittest.TestCase):
    """
    Test connection, loading, and querying of CGD snapshot

    CGDTestCase is an integration test using the Travis CI
    testing environment to test with a mysql database
    The database is created and populated in the .travis.yml file
    """

    def setUp(self):
        database = 'cgd_test'
        user = '******'
        self.cgd_test = CGD(database, user)
        self.connection, self.cursor = self.cgd_test._connect_to_database()
        return

    def tearDown(self):
        self.cgd_test._disconnect_from_database(self.cursor, self.connection)
        self.cgd_test = None
        return

    def test_queries(self):
        """
        Just checking that these run without errors, probably needs
        do so some actual checking of things
        :return:
        """
        self.cgd_test.check_if_db_is_empty(self.cursor)

        # test queries
        self.cgd_test.execute_query(self.cursor, self.cgd_test.static_files['disease_drug_variant_query']['file'])
        self.cgd_test.execute_query(self.cursor, self.cgd_test.static_files['variant_protein_query']['file'])
        self.cgd_test.execute_query(self.cursor, self.cgd_test.static_files['variant_cdna_query']['file'])
        self.cgd_test.execute_query(self.cursor, self.cgd_test.static_files['genotypes_with_no_protein_cdna_mapping']['file'])
        self.cgd_test.execute_query(self.cursor, self.cgd_test.static_files['fusion_copy_any_mutation_genotypes']['file'])

        return

    def test_fetch(self):
        """.
        Just checking that we can fetch sources without errors
        :return:
        """
        self.cgd_test.fetch()
        return

    def test_parse(self):
        """
        Just checking that we can parse sources without errors
        :return:
        """
        self.cgd_test.parse()
        return
コード例 #2
0
ファイル: GraphGenerator.py プロジェクト: zzygyx9119/mckb
def main():
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger(__name__)

    parser = argparse.ArgumentParser(
        description='Cancer Knowledge Base Graph'
        ' Generator',
        formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('--host',
                        '-H',
                        type=str,
                        default="localhost",
                        help='Location of MySQL Server')
    parser.add_argument('--database', '-D', type=str, help='Name of database')
    parser.add_argument('--user', '-u', help='Username')
    parser.add_argument('--password', '-p', help='Password')
    parser.add_argument('--config',
                        '-c',
                        help='Config file, see example '
                        'formatting in conf directory')

    args = parser.parse_args()

    # Config file overrides command line credentials
    # We need to refactor the Dipper config.py so it is reusable here
    if args.config is not None:
        credentials = json.load(open(args.config, 'r'))
        args.host = credentials['dbauth']['cgd']['host']
        args.database = credentials['dbauth']['cgd']['database']
        args.user = credentials['dbauth']['cgd']['user']
        args.password = credentials['dbauth']['cgd']['password']

    if args.password is None:
        if sys.stdin.isatty():
            args.password = getpass.getpass(prompt="Enter your password: "******"Enter your password: ")

    # Parse test source
    cgd = CGD(args.database, args.user, args.password, args.host)
    cgd.fetch(False)
    cgd.parse()
    cgd.write(format='turtle')
    return