def setUp(self): self.fd, self.path = tempfile.mkstemp() self.connection = 'sqlite:///' + self.path log.info('Test generated connection string %s', self.connection) self.manager = Manager(connection=self.connection) self.manager.create_all()
def test_insert_namespace_persistent(self, mock_get): self.manager.ensure_namespace(HGNC_URL) self._help_check_hgnc(self.manager) alternate_manager = Manager(connection=self.connection) alternate_manager.ensure_namespace(HGNC_URL) self._help_check_hgnc(alternate_manager)
class TemporaryCacheMixin(unittest.TestCase): def setUp(self): self.fd, self.path = tempfile.mkstemp() self.connection = 'sqlite:///' + self.path log.info('Test generated connection string %s', self.connection) self.manager = Manager(connection=self.connection) self.manager.create_all() def tearDown(self): self.manager.session.close() os.close(self.fd) os.remove(self.path)
def setUp(self): super(ManagerMixin, self).setUp() self.db_fd, self.db_file = tempfile.mkstemp() self.connection = 'sqlite:///' + self.db_file self.manager = Manager(connection=self.connection)
def upload_recursive(directory, connection=None, exclude_directory_pattern=None): """Recursively uploads all gpickles in a given directory and sub-directories :param str directory: the directory to traverse :param connection: A connection string or manager :type connection: Optional[str or pybel.manage.Manager] :param Optional[str] exclude_directory_pattern: Any directory names to exclude """ manager = Manager.ensure(connection) paths = list( get_paths_recursive( directory, extension='.gpickle', exclude_directory_pattern=exclude_directory_pattern)) log.info('Paths to upload: %s', paths) for path in paths: try: network = from_pickle(path) except (ImportError, ImportVersionWarning): log.warning( '%s uses a pickle from an old version of PyBEL. Quitting.', path) continue to_database(network, connection=manager, store_parts=True)
def setUpClass(cls): if test_connection: cls.connection = test_connection else: cls.fd, cls.path = tempfile.mkstemp() cls.connection = 'sqlite:///' + cls.path log.info('Test generated connection string %s', cls.connection) cls.manager = Manager(connection=cls.connection) cls.manager.create_all()
def main(manager: Manager, permutations: int = 25): """Run the experiments and uploads them.""" network_directory = os.path.join(BMS_BASE, 'aetionomy', 'neurommsig') gse1297_directory = os.path.join(OMICS_DATA_DIR, 'GSE1297') gse28146_directory = os.path.join(OMICS_DATA_DIR, 'GSE28146') gse63063_directory = os.path.join(OMICS_DATA_DIR, 'GSE63063') omics_directories = [ gse1297_directory, gse28146_directory, gse63063_directory, ] work_group( network_directory=network_directory, omics_directories=omics_directories, manager=manager, permutations=permutations, ) if __name__ == '__main__': logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s") logger.setLevel(logging.INFO) main(Manager())
with open(path) as f: cbn_jgif_dict = json.load(f) graph = pybel.from_cbn_jgif(cbn_jgif_dict) out_path = os.path.join(dir_path, jfg_path.replace('.jgf', '.bel')) with open(out_path, 'w') as o: pybel.to_bel(graph, o) strip_annotations(graph) enrich_pubmed_citations(manager=manager, graph=graph) pybel.to_database(graph, manager=manager) log.info('') log.info('done in %.2f', time.time() - t) if __name__ == '__main__': logging.basicConfig(level=logging.INFO) log.setLevel(logging.INFO) logging.getLogger('pybel.parser.baseparser').setLevel(logging.WARNING) bms_base = os.environ['BMS_BASE'] cbn_base = os.path.join(bms_base, 'cbn', 'Human-2.0') m = Manager() upload_cbn_dir(cbn_base, m)
def convert_paths(paths, connection=None, upload=False, pickle=False, canonicalize=True, infer_central_dogma=True, enrich_citations=False, send=False, version_in_path=False, **kwargs): """Recursively parses and either uploads/pickles graphs in a given set of files :param iter[str] paths: The paths to convert :param connection: The connection :type connection: None or str or pybel.manager.Manager :param bool upload: Should the networks be uploaded to the cache? :param bool pickle: Should the networks be saved as pickles? :param bool canonicalize: Calculate canonical nodes? :param bool infer_central_dogma: Should the central dogma be inferred for all proteins, RNAs, and miRNAs :param bool enrich_citations: Should the citations be enriched using Entrez Utils? :param bool send: Send to PyBEL Web? :param bool version_in_path: Add the current pybel version to the pathname :param kwargs: Parameters to pass to :func:`pybel.from_path` """ manager = Manager.ensure(connection) failures = [] for path in paths: log.info('parsing: %s', path) try: graph = from_path(path, manager=manager, **kwargs) except Exception as e: log.exception('problem parsing %s', path) failures.append((path, e)) continue if canonicalize: add_canonical_names(graph) if infer_central_dogma: infer_central_dogma_mutator(graph) if enrich_citations: enrich_pubmed_citations(graph=graph, manager=manager) if upload: to_database(graph, connection=manager, store_parts=True) if pickle: name = path[:-len( '.bel')] # gets rid of .bel at the end of the file name if version_in_path: new_path = '{}-{}.gpickle'.format(name, get_pybel_version()) else: new_path = '{}.gpickle'.format(name) to_pickle(graph, new_path) log.info('output pickle: %s', new_path) if send: response = to_web(graph) log.info('sent to PyBEL Web with response: %s', response.json()) return failures
return return insert_graph(manager, graph, public=True, use_tqdm=True) def load_cbn(manager: Manager): """Load CBN data as BEL.""" upload_jgf_directory(cbn_human, manager) upload_jgf_directory(cbn_mouse, manager) upload_jgf_directory(cbn_rat, manager) def load_bms(manager: Manager): """Load BEL.""" upload_neurommsig_graphs(manager) upload_bel_directory(selventa_directory, manager) upload_bel_directory(alzheimer_directory, manager, blacklist=['alzheimers']) upload_bel_directory(parkinsons_directory, manager, blacklist=['parkinsons']) if __name__ == '__main__': logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(levelname)s - %(name)s - %(message)s") logger.setLevel(logging.INFO) load_bms(Manager())
def main(manager: Optional[Manager] = None): """Load BEL.""" if manager is None: manager = Manager() upload_bel_directory(alzheimer_directory, manager)