File size: 833 Bytes
44459bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Helper methods for reading input files."""

import re
from itertools import filterfalse, tee
from pathlib import Path


def partition_template_pdb_from_file(
    custom_templates: list[str | Path],
) -> tuple[list[str], list[Path]]:
    """Partitions custom templates files from PDB codes and removes duplicates.

    Inspired from `partition` function in itertools cookbook:
    https://docs.python.org/dev/library/itertools.html#itertools-recipes

    Args:
        custom_templates (list[str | Path]): List of custom templates

    Returns:
        The list of PDB codes and the list of custom files.
    """

    def pred(x):
        return re.match(r"^[a-zA-Z0-9]{4}$", str(x))

    t1, t2 = tee(custom_templates)
    pdb_codes = filter(pred, t1)
    custom_files = filterfalse(pred, t2)
    return (pdb_codes, custom_files)