Tracking records that could not be processed

The NotCompleted object

This is an object returned when a composable function did not complete a task. NotCompleted is a special result type that can be produced by a composable app. These objects evaluate to False.

An app can return a NotCompleted result for one of 2 reasons. The object contains information regarding the input data, where the issue arose and whatever message was provided by the code (like an exception traceback).

NotCompleted FALSE type

The results when a condition was not met. For example, below I create an app that will return alignments that with 2 specific sequences but I’m including one that does not exist (“Mouse”). So this will fail.

from cogent3 import get_app

reader = get_app("load_aligned", format="fasta")
select_seqs = get_app("take_named_seqs", "Mouse", "Human")
aln = reader("data/primate_brca1.fasta")
result = select_seqs(aln)
result
NotCompleted(type=FALSE, origin=take_named_seqs, source="primate_brca1.fasta", message="named seq(s) {'Mouse'} not in ['Chimpanzee', 'Galago', 'Gorilla', 'HowlerMon', 'Human', 'Orangutan', 'Rhesus']")
result == False
result.type
result.message
"named seq(s) {'Mouse'} not in ['Chimpanzee', 'Galago', 'Gorilla', 'HowlerMon', 'Human', 'Orangutan', 'Rhesus']"

NotCompleted ERROR type

An ERROR type is returned if an exception is raised during the calculation. We trigger it in this case by trying to open a non-existent file.

result = reader("primate_brca1.fasta")
result
NotCompleted(type=ERROR, origin=load_aligned, source="primate_brca1.fasta", message="Traceback (most recent call last):
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 255, in _read_it
    data = path.read()
AttributeError: 'PosixPath' object has no attribute 'read'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/composable.py", line 1020, in _call
    result = self.main(val, *args, **kwargs)
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 293, in main
    return _load_seqs(path, ArrayAlignment, self._parser, self.moltype)
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 265, in _load_seqs
    data = _read_it(path)
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 258, in _read_it
    data = path.read_text()
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/pathlib.py", line 1132, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/pathlib.py", line 1117, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: 'primate_brca1.fasta'
")

Composed functions propagate NotCompleted results

process = reader + select_seqs
result = process("data/primate_brca1.fasta")
result
NotCompleted(type=FALSE, origin=take_named_seqs, source="primate_brca1.fasta", message="named seq(s) {'Mouse'} not in ['Chimpanzee', 'Galago', 'Gorilla', 'HowlerMon', 'Human', 'Orangutan', 'Rhesus']")

and

result = process("primate_brca1.fasta")
result
NotCompleted(type=ERROR, origin=load_aligned, source="primate_brca1.fasta", message="Traceback (most recent call last):
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 255, in _read_it
    data = path.read()
AttributeError: 'PosixPath' object has no attribute 'read'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/composable.py", line 1020, in _call
    result = self.main(val, *args, **kwargs)
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 293, in main
    return _load_seqs(path, ArrayAlignment, self._parser, self.moltype)
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 265, in _load_seqs
    data = _read_it(path)
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/site-packages/cogent3/app/io_new.py", line 258, in _read_it
    data = path.read_text()
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/pathlib.py", line 1132, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "/Users/gavin/opt/miniconda3/envs/c310dev/lib/python3.10/pathlib.py", line 1117, in open
    return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: 'primate_brca1.fasta'
")