def __init__(self, folder_path, use_db_metadata_classes=None, use_edge_metadata_classes=None):
        gcConst.O_FILE_PATH = os.path.join(folder_path, gcConst.O_FILE_FOLDER_NAME)
        gcConst.IN_FILE_PATH = os.path.join(folder_path, gcConst.IN_FILE_FOLDER_NAME)

        self.db_file_metadata = [x() for x in utils.get_leaf_subclasses(DbMetadata)]
        self.file_readers = [x() for x in utils.get_leaf_subclasses(FileReader)]
        self.file_processors = [x() for x in utils.get_leaf_subclasses(FileProcessor)]
        self.infile_metadata = [x() for x in utils.get_leaf_subclasses(InfileMetadata)]
        self.edge_metadata = [x(graphProp.QUALITY) for x in utils.get_leaf_subclasses(EdgeRegularMetadata)] + [
            x(graphProp.QUALITY) for x in utils.get_leaf_subclasses(EdgeOntoMetadata)
        ]
        self.tn_edge_metadata = [x(graphProp.QUALITY) for x in utils.get_leaf_subclasses(TnEdgeRegularMetadata)]

        self.dbType_reader_map = utils.cls_list_to_dic(self.file_readers, "dbType")
        self.readerType_processor_map = utils.cls_list_to_dic(self.file_processors, "readerType")
        self.infileType_inMetadata_map = {x.infileType: x for x in self.infile_metadata}

        # if not glob.DIRECTED:
        ## remove onto
        #    if use_edge_metadata_classes is None:
        #        use_edge_metadata_classes = [x(glob.QUALITY) for x in utils.get_leaf_subclasses(EdgeRegularMetadata)]
        #    else:
        #        temp_use_edge_metadata_classes =[]
        #        for edge_class in use_edge_metadata_classes:
        #            if inspect.isclass(edge_class):
        #                if not issubclass(edge_class, EdgeOntoMetadata):
        #                    temp_use_edge_metadata_classes.append(edge_class())
        #            else:
        #                if not issubclass(type(edge_class), EdgeOntoMetadata):
        #                    temp_use_edge_metadata_classes.append(edge_class)
        #        use_edge_metadata_classes = temp_use_edge_metadata_classes
        #        #use_edge_metadata_classes = [x for x in use_edge_metadata_classes if not issubclass(type(x), EdgeOntoMetadata)]

        # use only the desired sources
        if use_db_metadata_classes is not None:
            self.init_custom_sources_bottom_up(use_db_metadata_classes)
        if use_edge_metadata_classes is not None:
            self.init_custom_sources_top_down(use_edge_metadata_classes)

        graphProp.EDGE_TYPES = [str(x.__class__.__name__) for x in self.edge_metadata]
Exemple #2
0
    def init_custom_sources_top_down(self, use_edge_metdata_classes):
        """hepler __init__ function for custom edge_metadata_classes"""

        # remove edge_metadata
        logging.info("Edge Metadata removed: " + str([
            x.__class__.__name__
            for x in self.edge_metadata if x.EDGE_INMETA_CLASS not in
            [y.EDGE_INMETA_CLASS for y in use_edge_metdata_classes]
        ]))
        self.edge_metadata = []

        for x in use_edge_metdata_classes:
            if inspect.isclass(x):
                self.edge_metadata.append(x())
            else:
                self.edge_metadata.append(x)

        # remove inMetadata
        infileType_edgeMetadata_map = utils.cls_list_to_dic(
            self.edge_metadata, "EDGE_INMETA_CLASS.INFILE_TYPE")
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(self.edge_metadata,
                                  "MAP1_META_CLASS.INFILE_TYPE",
                                  lambda a: a.MAP1_META_CLASS is not None))
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(self.edge_metadata,
                                  "MAP2_META_CLASS.INFILE_TYPE",
                                  lambda a: a.MAP2_META_CLASS is not None))
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(
                self.edge_metadata, "MAP1_ALT_ID_META_CLASS.INFILE_TYPE",
                lambda a: a.MAP1_ALT_ID_META_CLASS is not None))
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(
                self.edge_metadata, "MAP2_ALT_ID_META_CLASS.INFILE_TYPE",
                lambda a: a.MAP2_ALT_ID_META_CLASS is not None))

        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(self.tn_edge_metadata,
                                  "EDGE_INMETA_CLASS.INFILE_TYPE"))
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(self.tn_edge_metadata,
                                  "MAP1_META_CLASS.INFILE_TYPE",
                                  lambda a: a.MAP1_META_CLASS is not None))
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(self.tn_edge_metadata,
                                  "MAP2_META_CLASS.INFILE_TYPE",
                                  lambda a: a.MAP2_META_CLASS is not None))
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(
                self.tn_edge_metadata,
                "MAP1_ALT_ID_META_CLASS.INFILE_TYPE",
                lambda a: a.MAP1_ALT_ID_META_CLASS is not None,
            ))
        infileType_edgeMetadata_map.update(
            utils.cls_list_to_dic(
                self.tn_edge_metadata,
                "MAP2_ALT_ID_META_CLASS.INFILE_TYPE",
                lambda a: a.MAP2_ALT_ID_META_CLASS is not None,
            ))

        keep_infileTypes = list(infileType_edgeMetadata_map.keys())
        logging.info("Infile Metadata removed: " + str([
            x.__class__.__name__ for x in self.infile_metadata
            if x.infileType not in keep_infileTypes
        ]))
        self.infile_metadata = [
            x for x in self.infile_metadata if x.infileType in keep_infileTypes
        ]
        self.infileType_inMetadata_map = {
            x.infileType: x
            for x in self.infile_metadata
        }

        # remove processors
        logging.info("Processors removed: " + str([
            x.__class__.__name__ for x in self.file_processors
            if x.infileType not in keep_infileTypes
        ]))
        self.file_processors = [
            x for x in self.file_processors if x.infileType in keep_infileTypes
        ]
        self.readerType_processor_map = utils.cls_list_to_dic(
            self.file_processors, "readerType")

        # remove readers
        keep_readerType = list(self.readerType_processor_map.keys())
        logging.info("Readers removed: " + str([
            x.__class__.__name__
            for x in self.file_readers if x.readerType not in keep_readerType
        ]))
        self.file_readers = [
            x for x in self.file_readers if x.readerType in keep_readerType
        ]
        self.dbType_reader_map = utils.cls_list_to_dic(self.file_readers,
                                                       "dbType")

        # remove db_metadata
        keep_dbType = list(self.dbType_reader_map.keys())
        logging.info("DB_source removed: " + str([
            x.__class__.__name__
            for x in self.db_file_metadata if x.dbType not in keep_dbType
        ]))

        self.db_file_metadata = [
            x for x in self.db_file_metadata if x.dbType in keep_dbType
        ]
Exemple #3
0
    def init_custom_sources_bottom_up(self, use_db_metdata_classes):
        """helper __init__ function for custom db_metadata_classes"""

        self.db_file_metadata = []

        # remove dbMetadata from list
        # make sure to use instances of classes
        for x in use_db_metdata_classes:
            if inspect.isclass(x):
                self.db_file_metadata.append(x())
            else:
                self.db_file_metadata.append(x)

        # remove readers
        keep_dbType = [x.dbType for x in self.db_file_metadata]
        logging.info("readers removed: " + str([
            x.__class__.__name__
            for x in self.file_readers if x.dbType not in keep_dbType
        ]))
        self.file_readers = [
            x for x in self.file_readers if x.dbType in keep_dbType
        ]
        self.dbType_reader_map = utils.cls_list_to_dic(self.file_readers,
                                                       "dbType")

        # remove processors
        keep_readerType = [x.readerType for x in self.file_readers]
        logging.info("processors removed: %s" % (str([
            x.__class__.__name__ for x in self.file_processors
            if x.readerType not in keep_readerType
        ])))
        self.file_processors = [
            x for x in self.file_processors if x.readerType in keep_readerType
        ]
        self.readerType_processor_map = utils.cls_list_to_dic(
            self.file_processors, "readerType")

        # remove infile metadata
        keep_infileType = [x.infileType for x in self.file_processors]
        logging.info("processors removed: " + str([
            x.__class__.__name__ for x in self.infile_metadata
            if x.infileType not in keep_infileType
        ]))
        self.infile_metadata = [
            x for x in self.infile_metadata if x.infileType in keep_infileType
        ]
        self.infileType_inMetadata_map = {
            x.infileType: x
            for x in self.infile_metadata
        }

        # remove edge metadata
        logging.info("edges removed: " + str([
            x.__class__.__name__
            for x in self.edge_metadata + self.tn_edge_metadata
            if x.EDGE_INMETA_CLASS.INFILE_TYPE not in keep_infileType
        ]))
        self.edge_metadata = [
            x for x in self.edge_metadata
            if x.EDGE_INMETA_CLASS.INFILE_TYPE in keep_infileType
        ]
        self.tn_edge_metadata = [
            x for x in self.tn_edge_metadata
            if x.EDGE_INMETA_CLASS.INFILE_TYPE in keep_infileType
        ]

        # check for deleted dependencies of mappings
        additional_remove_metaEdges = []
        additional_remove_mapping_infileType = []
        for metaEdge in self.edge_metadata + self.tn_edge_metadata:
            mappings = [
                metaEdge.MAP1_META_CLASS,
                metaEdge.MAP2_META_CLASS,
                metaEdge.MAP1_ALT_ID_META_CLASS,
                metaEdge.MAP2_ALT_ID_META_CLASS,
            ]
            for mapping in mappings:

                if mapping is not None and mapping.INFILE_TYPE not in keep_infileType:
                    additional_remove_metaEdges.append(metaEdge)
                    additional_remove_mapping_infileType.append(
                        mapping.INFILE_TYPE)
        if len(additional_remove_metaEdges) > 0:
            message = (
                "\nDue to manual exclusion of DB resources, also the edges: %s\n "
                "will be removed due to deleted dependencies of used mappings (i.e. %s\n "
                "Consider manually exclude edges instead of DB resources." % (
                    str([
                        x.__class__.__name__
                        for x in additional_remove_metaEdges
                    ]),
                    str([str(x)
                         for x in additional_remove_mapping_infileType]),
                ))
            logging.warning(message)
            if globConst.GUI_MODE:
                from openbiolink.gui import gui

                gui.askForExit(message)
            elif globConst.INTERACTIVE_MODE:
                Cli.ask_for_exit(message)
            else:
                sys.exit()

            self.edge_metadata = [
                x for x in self.edge_metadata
                if x not in additional_remove_metaEdges
            ]
            self.tn_edge_metadata = [
                x for x in self.tn_edge_metadata
                if x not in additional_remove_metaEdges
            ]