コード例 #1
0
    def test_threading_detect(self):
        frame_count = sum(1 for _ in fastobo.iter(MS, threads=0))
        self.assertEqual(frame_count, MS_FRAMES)

        with open(MS, 'rb') as f:
            frame_count = sum(1 for _ in fastobo.iter(f, threads=0))
            self.assertEqual(frame_count, MS_FRAMES)
コード例 #2
0
ファイル: obo.py プロジェクト: srravula1/pronto
    def parse_from(self, handle, threads=None):
        # Load the OBO document through an iterator using fastobo
        doc = fastobo.iter(handle, ordered=True)

        # Extract metadata from the OBO header and resolve imports
        self.ont.metadata = self.extract_metadata(doc.header())
        self.ont.imports.update(
            self.process_imports(
                self.ont.metadata.imports,
                self.ont.import_depth,
                os.path.dirname(self.ont.path or str()),
                self.ont.timeout,
            )
        )

        # Merge inheritance cache from imports
        self.import_inheritance()

        # Extract frames from the current document.
        try:
            with multiprocessing.pool.ThreadPool(threads) as pool:
                pool.map(self.extract_entity, doc)
        except SyntaxError as s:
            location = self.ont.path, s.lineno, s.offset, s.text
            raise SyntaxError(s.args[0], location) from None

        # Update inheritance cache with symmetric of `subClassOf`
        self.symmetrize_inheritance()
コード例 #3
0
    def load_ontology(self, path):
        """Load and parse ontologies - currently support OBO files only."""
        if path is None:
            path = self.DefaultOnotology

        try:
            with fsspec.open(path) as f:
                obo = fastobo.iter(f)
                terms = filter(
                    lambda stanza: type(stanza) is fastobo.term.TermFrame, obo)
                names = [
                    tag.name for term in terms for tag in term
                    if type(tag) is fastobo.term.NameClause
                ]
                self.ontology_data = names

        except FileNotFoundError as e:
            raise OntologyLoadFailure(
                "Unable to find OBO ontology path") from e

        except SyntaxError as e:
            raise OntologyLoadFailure(
                f"{path}:{e.lineno}:{e.offset} OBO syntax error, unable to read ontology"
            ) from e

        except Exception as e:
            raise OntologyLoadFailure(f"{path}:Error loading OBO file") from e
コード例 #4
0
ファイル: obo.py プロジェクト: zhaoqiuye/pronto
    def parse_from(self, handle):
        # Load the OBO document through an iterator using fastobo
        doc = fastobo.iter(handle)

        # Extract metadata from the OBO header and resolve imports
        self.ont.metadata = self.extract_metadata(doc.header())
        self.ont.imports.update(
            self.process_imports(
                self.ont.metadata.imports,
                self.ont.import_depth,
                os.path.dirname(self.ont.path or str()),
                self.ont.timeout,
            ))

        # Extract frames from the current document.
        try:
            for frame in doc:
                if isinstance(frame, fastobo.term.TermFrame):
                    self.enrich_term(frame)
                elif isinstance(frame, fastobo.typedef.TypedefFrame):
                    self.enrich_relationship(frame)
        except SyntaxError as s:
            location = self.ont.path, s.lineno, s.offset, s.text
            raise SyntaxError(s.args[0], location) from None