hypline 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,43 @@
1
+ name: docs
2
+ on:
3
+ push:
4
+ branches: ["main"]
5
+
6
+ permissions:
7
+ contents: write
8
+
9
+ jobs:
10
+ deploy:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Configure Git credentials
17
+ run: |
18
+ git config user.name github-actions[bot]
19
+ git config user.email 41898282+github-actions[bot]@users.noreply.github.com
20
+
21
+ - name: Set up Python
22
+ uses: actions/setup-python@v5
23
+ with:
24
+ python-version: "3.10"
25
+
26
+ - name: Create cache key
27
+ run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
28
+
29
+ - name: Cache build files
30
+ uses: actions/cache@v4
31
+ with:
32
+ key: mkdocs-material-${{ env.cache_id }}
33
+ path: .cache
34
+ restore-keys: |
35
+ mkdocs-material-
36
+
37
+ - name: Install dependencies
38
+ run: pip install mkdocs-material
39
+
40
+ - name: Publish docs to gh-pages
41
+ run: |
42
+ cd docs
43
+ mkdocs gh-deploy --force
@@ -0,0 +1,10 @@
1
+ # Python-generated files
2
+ __pycache__/
3
+ *.py[oc]
4
+ build/
5
+ dist/
6
+ wheels/
7
+ *.egg-info
8
+
9
+ # Virtual environments
10
+ .venv
@@ -0,0 +1 @@
1
+ 3.10
hypline-0.1.0/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2025 The Trustees of Princeton University
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
hypline-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,54 @@
1
+ Metadata-Version: 2.4
2
+ Name: hypline
3
+ Version: 0.1.0
4
+ Summary: Data Cleaning and Analysis Pipeline for Hyperscanning Research
5
+ Project-URL: Repository, https://github.com/princeton-ddss/hypline
6
+ Project-URL: Documentation, https://princeton-ddss.github.io/hypline/
7
+ Author-email: Sangyoon Park <datumvitae@gmail.com>
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.10
10
+ Requires-Dist: dill>=0.3.9
11
+ Requires-Dist: natsort>=8.4.0
12
+ Requires-Dist: nibabel>=5.3.2
13
+ Requires-Dist: nilearn>=0.11.1
14
+ Requires-Dist: numpy>=2.2.4
15
+ Requires-Dist: polars>=1.26.0
16
+ Requires-Dist: pydantic>=2.10.6
17
+ Requires-Dist: pyyaml>=6.0.2
18
+ Requires-Dist: rich>=14.0.0
19
+ Requires-Dist: typer>=0.15.2
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Hypline
23
+
24
+ Hypline is a Python package that provides a CLI tool for cleaning and analyzing data from hyperscanning studies involving dyadic conversations.
25
+
26
+ ## Installation
27
+
28
+ Hypline can be installed using `pip`:
29
+
30
+ ```bash
31
+ pip install hypline
32
+ ```
33
+
34
+ It can also be installed using other package managers such as [`uv`](https://docs.astral.sh/uv/) and [`poetry`](https://python-poetry.org/docs/).
35
+
36
+ ## Quick Start
37
+
38
+ Once the package is installed, `hypline` command will be available, like so:
39
+
40
+ ```bash
41
+ hypline --help
42
+ ```
43
+
44
+ Running the above will display an overview of the tool, including supported subcommands.
45
+
46
+ For instance, `clean` is a subcommand for performing confound regression to clean BOLD outputs from [fMRIPrep](https://fmriprep.org/en/stable/index.html), and its details can be viewed by running:
47
+
48
+ ```bash
49
+ hypline clean --help
50
+ ```
51
+
52
+ ## What Next
53
+
54
+ If you want to learn more about Hypline, please check out the official project [documentation](https://princeton-ddss.github.io/hypline/).
@@ -0,0 +1,33 @@
1
+ # Hypline
2
+
3
+ Hypline is a Python package that provides a CLI tool for cleaning and analyzing data from hyperscanning studies involving dyadic conversations.
4
+
5
+ ## Installation
6
+
7
+ Hypline can be installed using `pip`:
8
+
9
+ ```bash
10
+ pip install hypline
11
+ ```
12
+
13
+ It can also be installed using other package managers such as [`uv`](https://docs.astral.sh/uv/) and [`poetry`](https://python-poetry.org/docs/).
14
+
15
+ ## Quick Start
16
+
17
+ Once the package is installed, `hypline` command will be available, like so:
18
+
19
+ ```bash
20
+ hypline --help
21
+ ```
22
+
23
+ Running the above will display an overview of the tool, including supported subcommands.
24
+
25
+ For instance, `clean` is a subcommand for performing confound regression to clean BOLD outputs from [fMRIPrep](https://fmriprep.org/en/stable/index.html), and its details can be viewed by running:
26
+
27
+ ```bash
28
+ hypline clean --help
29
+ ```
30
+
31
+ ## What Next
32
+
33
+ If you want to learn more about Hypline, please check out the official project [documentation](https://princeton-ddss.github.io/hypline/).
@@ -0,0 +1,188 @@
1
+ # Cleaning BOLD Data
2
+
3
+ ## Overview
4
+
5
+ Hypline supports confound regression to clean BOLD outputs from [fMRIPrep](https://fmriprep.org/en/stable/index.html).
6
+
7
+ Specifically, the `clean` subcommand supports this, and its details can be checked by running:
8
+
9
+ ```bash
10
+ hypline clean --help
11
+ ```
12
+
13
+ The `clean` subcommand takes in three required arguments:
14
+
15
+ | Argument | Description |
16
+ | --------------- | ------------------------------------------------------------ |
17
+ | `fmriprep_dir` | Directory containing fMRIPrep outputs |
18
+ | `config_file` | Configuration file containing model specs, etc. |
19
+ | `model_name` | Confound regression model to run (defined in configuration) |
20
+
21
+ and several options:
22
+
23
+ | Option | Description | Default |
24
+ | ------------------------- | --------------------------------------- | ------------------------- |
25
+ | `--output-dir` | Directory to store cleaned BOLD data | `<fmriprep_dir>_cleaned` |
26
+ | `--custom-confounds-dir` | Directory containing custom confounds | None |
27
+ | `--session-name` | Target session name | All |
28
+ | `--task-name` | Target task name | All |
29
+ | `--data-space-name` | Target BOLD data space | `MNI152NLin2009cAsym` |
30
+ | `--n-processes` | Number of processes to run in parallel | `1` |
31
+
32
+ ## Example
33
+
34
+ For illustration, consider we have the fMRIPrep outputs stored in the following location:
35
+
36
+ ``` hl_lines="3-6"
37
+ data/
38
+ └── derivatives/
39
+ └── fmriprep/
40
+ ├── logs/
41
+ ├── sub-003/
42
+ └── ...
43
+ ```
44
+
45
+ ### Setting up configuration
46
+
47
+ We can start by defining the desired confound regression model(s) in the configuration file, like so:
48
+
49
+ ```yaml title="config.yaml"
50
+ model_specs:
51
+
52
+ default:
53
+ confounds:
54
+ - "trans_x"
55
+ - "trans_y"
56
+ - "trans_z"
57
+ - "rot_x"
58
+ - "rot_y"
59
+ - "rot_z"
60
+ - "cosine"
61
+ aCompCor:
62
+ - n_comps: 5
63
+ tissue: "CSF"
64
+ - n_comps: 5
65
+ tissue: "WM"
66
+
67
+ default_task:
68
+ confounds:
69
+ - "trans_x"
70
+ - "trans_y"
71
+ - "trans_z"
72
+ - "rot_x"
73
+ - "rot_y"
74
+ - "rot_z"
75
+ - "cosine"
76
+ custom_confounds:
77
+ - "trial_boxcar"
78
+ - "prompt_boxcar"
79
+ - "speech_boxcar"
80
+ - "listen_boxcar"
81
+ - "button_press"
82
+ - "receive_press"
83
+ - "screen_change"
84
+ aCompCor:
85
+ - n_comps: 5
86
+ tissue: "CSF"
87
+ - n_comps: 5
88
+ tissue: "WM"
89
+ ```
90
+
91
+ We can store the configuration file anywhere we want. Let's say we stored it as follows:
92
+
93
+ ``` hl_lines="3-4"
94
+ data/
95
+ └── derivatives/
96
+ ├── hypline/
97
+ │ └── config.yaml
98
+ └── fmriprep/
99
+ ├── logs/
100
+ ├── sub-003/
101
+ └── ...
102
+ ```
103
+
104
+ ### Using custom confounds
105
+
106
+ If the model involves custom confounds, we should provide the data as subject-level TSV files that each contain a given subject’s confound values per TR. Hence, each TSV file will be a tabular data of shape $n \times m$, where $n$ equals the number of total TRs in a run and $m$ equals the number of custom confounds. With the current directory structure, we may prepare custom confounds as follows:
107
+
108
+ ``` hl_lines="5-9"
109
+ data/
110
+ └── derivatives/
111
+ ├── hypline/
112
+ │ ├── config.yaml
113
+ │ └── custom_confounds/
114
+ │ ├── sub-003/ses-1/func/
115
+ │ │ ├── sub-003_ses-1_task-Conv_run-1_desc-customConfounds_timeseries.tsv
116
+ │ │ └── ...
117
+ │ └── ...
118
+ │
119
+ └── fmriprep/
120
+ ├── logs/
121
+ ├── sub-003/ses-1/func/
122
+ │ ├── sub-003_ses-1_task-Conv_run-1_desc-confounds_timeseries.tsv
123
+ │ ├── sub-003_ses-1_task-Conv_run-1_space-fsaverage6_hemi-L_bold.func.gii
124
+ │ ├── sub-003_ses-1_task-Conv_run-1_space-fsaverage6_hemi-R_bold.func.gii
125
+ │ └── ...
126
+ └── ...
127
+ ```
128
+
129
+ !!! note
130
+
131
+ The custom confound TSV file should have the same name as its corresponding standard confound TSV file, except for the description (i.e., `desc` entity).
132
+
133
+ ### Running the command
134
+
135
+ With this setup, we can run the following to clean surface-level BOLD data for all subjects:
136
+
137
+ ```bash
138
+ hypline clean \
139
+ data/derivatives/fmriprep/ \
140
+ data/derivatives/hypline/config.yml \
141
+ default_task \
142
+ --custom-confounds-dir data/derivatives/hypline/custom_confounds/ \
143
+ --data-space fsaverage6
144
+ --n-processes 8
145
+ ```
146
+
147
+ Note that we are here leveraging multiprocessing (i.e., 8 parallel processes) to speed up the cleaning.
148
+
149
+ ### Outputs
150
+
151
+ The cleaned data will then be stored in the designated location[^1] as follows:
152
+
153
+ ``` hl_lines="20-28"
154
+ data/
155
+ └── derivatives/
156
+ ├── hypline/
157
+ │ ├── config.yaml
158
+ │ └── custom_confounds/ses-1/func/
159
+ │ ├── sub-003/
160
+ │ │ ├── sub-003_ses-1_task-Conv_run-1_desc-customConfounds_timeseries.tsv
161
+ │ │ └── ...
162
+ │ └── ...
163
+ │
164
+ ├── fmriprep/
165
+ │ ├── logs/
166
+ │ ├── sub-003/ses-1/func/
167
+ │ │ ├── sub-003_ses-1_task-Conv_run-1_desc-confounds_timeseries.tsv
168
+ │ │ ├── sub-003_ses-1_task-Conv_run-1_space-fsaverage6_hemi-L_bold.func.gii
169
+ │ │ ├── sub-003_ses-1_task-Conv_run-1_space-fsaverage6_hemi-R_bold.func.gii
170
+ │ │ └── ...
171
+ │ └── ...
172
+ │
173
+ └── fmriprep_cleaned/
174
+ ├── logs/
175
+ │ ├── sub-003.log
176
+ │ └── ...
177
+ ├── sub-003/ses-1/func/
178
+ │ ├── sub-003_ses-1_task-Conv_run-1_space-fsaverage6_hemi-L_desc-clean_bold.func.gii
179
+ │ ├── sub-003_ses-1_task-Conv_run-1_space-fsaverage6_hemi-R_desc-clean_bold.func.gii
180
+ │ └── ...
181
+ └── ...
182
+ ```
183
+
184
+ As shown above, the cleaned data files will be of the same format as their corresponding originals. In fact, their data dimension and other metadata will be the same as the originals, with the only difference being values in the data.
185
+
186
+ Note that log files are automatically generated to record the details of the cleaning process, which will be useful for reproducibility.
187
+
188
+ [^1]: In this case, the default value (`<fmriprep_dir>_cleaned`) is used because the given command does not explicitly specify the output directory (`--output-dir`).
@@ -0,0 +1,45 @@
1
+ # Welcome to Hypline
2
+
3
+ Hypline is a Python package that provides a CLI tool for cleaning and analyzing data from hyperscanning studies involving dyadic conversations.
4
+
5
+ ## Installation
6
+
7
+ Hypline can be installed using `pip` or other package managers such as [`uv`](https://docs.astral.sh/uv/) and [`poetry`](https://python-poetry.org/docs/).
8
+
9
+ === "pip"
10
+
11
+ ```bash
12
+ pip install hypline
13
+ ```
14
+
15
+ === "uv"
16
+
17
+ ```bash
18
+ uv add hypline
19
+ ```
20
+
21
+ === "poetry"
22
+
23
+ ```bash
24
+ poetry add hypline
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ Once the package is installed, `hypline` command will be available, like so:
30
+
31
+ ```bash
32
+ hypline --help
33
+ ```
34
+
35
+ Running the above will display an overview of the tool, including supported subcommands.
36
+
37
+ For instance, `clean` is a subcommand for performing confound regression to clean BOLD outputs from [fMRIPrep](https://fmriprep.org/en/stable/index.html), and its details can be viewed by running:
38
+
39
+ ```bash
40
+ hypline clean --help
41
+ ```
42
+
43
+ ## What Next
44
+
45
+ Please check out user [guides](guides/clean.md) for more detailed instructions and examples.
@@ -0,0 +1,19 @@
1
+ window.MathJax = {
2
+ tex: {
3
+ inlineMath: [["\\(", "\\)"]],
4
+ displayMath: [["\\[", "\\]"]],
5
+ processEscapes: true,
6
+ processEnvironments: true
7
+ },
8
+ options: {
9
+ ignoreHtmlClass: ".*|",
10
+ processHtmlClass: "arithmatex"
11
+ }
12
+ };
13
+
14
+ document$.subscribe(() => {
15
+ MathJax.startup.output.clearCache()
16
+ MathJax.typesetClear()
17
+ MathJax.texReset()
18
+ MathJax.typesetPromise()
19
+ })
@@ -0,0 +1,58 @@
1
+ docs_dir: mkdocs
2
+ site_name: Hypline
3
+ repo_name: princeton-ddss/hypline
4
+ repo_url: https://github.com/princeton-ddss/hypline
5
+ copyright: Copyright &copy; 2025 The Trustees of Princeton University
6
+
7
+ theme:
8
+ name: material
9
+ # logo: images/logo.png
10
+ # favicon: images/favicon.png
11
+ palette:
12
+ - media: "(prefers-color-scheme: light)"
13
+ scheme: default
14
+ toggle:
15
+ icon: material/brightness-7
16
+ name: Switch to dark mode
17
+ - media: "(prefers-color-scheme: dark)"
18
+ scheme: slate
19
+ toggle:
20
+ icon: material/brightness-4
21
+ name: Switch to light mode
22
+ features:
23
+ - content.code.annotate
24
+ - content.code.copy
25
+ - header.autohide
26
+ - navigation.instant
27
+ - navigation.tabs
28
+ - navigation.top
29
+ - navigation.footer
30
+ - search.highlight
31
+ - search.suggest
32
+
33
+ markdown_extensions:
34
+ - admonition
35
+ - attr_list
36
+ - footnotes
37
+ - md_in_html
38
+ - tables
39
+ - toc:
40
+ permalink: true
41
+ - pymdownx.arithmatex:
42
+ generic: true
43
+ - pymdownx.details
44
+ - pymdownx.superfences
45
+ - pymdownx.tabbed:
46
+ alternate_style: true
47
+
48
+ extra_javascript:
49
+ - javascripts/mathjax.js
50
+ - https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js
51
+
52
+ plugins:
53
+ - search
54
+
55
+ nav:
56
+ - Home: index.md
57
+ - Guides:
58
+ - Cleaning BOLD Data: guides/clean.md
@@ -0,0 +1,37 @@
1
+ [project]
2
+ name = "hypline"
3
+ version = "0.1.0"
4
+ description = "Data Cleaning and Analysis Pipeline for Hyperscanning Research"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Sangyoon Park", email = "datumvitae@gmail.com" }
8
+ ]
9
+ requires-python = ">=3.10"
10
+ dependencies = [
11
+ "dill>=0.3.9",
12
+ "natsort>=8.4.0",
13
+ "nibabel>=5.3.2",
14
+ "nilearn>=0.11.1",
15
+ "numpy>=2.2.4",
16
+ "polars>=1.26.0",
17
+ "pydantic>=2.10.6",
18
+ "pyyaml>=6.0.2",
19
+ "rich>=14.0.0",
20
+ "typer>=0.15.2",
21
+ ]
22
+
23
+ [project.urls]
24
+ Repository = "https://github.com/princeton-ddss/hypline"
25
+ Documentation = "https://princeton-ddss.github.io/hypline/"
26
+
27
+ [project.scripts]
28
+ hypline = "hypline:main"
29
+
30
+ [build-system]
31
+ requires = ["hatchling"]
32
+ build-backend = "hatchling.build"
33
+
34
+ [dependency-groups]
35
+ dev = [
36
+ "mkdocs-material>=9.6.11",
37
+ ]
@@ -0,0 +1,5 @@
1
+ from .cli import app
2
+
3
+
4
+ def main():
5
+ app()
@@ -0,0 +1,122 @@
1
+ import multiprocessing as mp
2
+ from pathlib import Path
3
+
4
+ import typer
5
+ from rich import print
6
+ from typing_extensions import Annotated
7
+
8
+ from .regression import ConfoundRegression
9
+ from .utils import DillProcess
10
+
11
+ app = typer.Typer()
12
+
13
+
14
+ @app.command()
15
+ def clean(
16
+ fmriprep_dir: Annotated[
17
+ str,
18
+ typer.Argument(
19
+ help="Directory containing fMRIPrep outputs",
20
+ show_default=False,
21
+ ),
22
+ ],
23
+ config_file: Annotated[
24
+ str,
25
+ typer.Argument(
26
+ help="Configuration file",
27
+ show_default=False,
28
+ ),
29
+ ],
30
+ model_name: Annotated[
31
+ str,
32
+ typer.Argument(
33
+ help="Confound regression model to run (defined in config)",
34
+ show_default=False,
35
+ ),
36
+ ],
37
+ output_dir: Annotated[
38
+ str | None,
39
+ typer.Option(
40
+ help="Directory to store cleaned BOLD data",
41
+ show_default="<fmriprep_dir>_cleaned",
42
+ ),
43
+ ] = None,
44
+ custom_confounds_dir: Annotated[
45
+ str | None,
46
+ typer.Option(help="Directory containing custom confounds"),
47
+ ] = None,
48
+ session_name: Annotated[
49
+ str,
50
+ typer.Option(
51
+ help="Target session name",
52
+ show_default="all",
53
+ ),
54
+ ] = "*",
55
+ task_name: Annotated[
56
+ str,
57
+ typer.Option(
58
+ help="Target task name",
59
+ show_default="all",
60
+ ),
61
+ ] = "*",
62
+ data_space_name: Annotated[
63
+ str,
64
+ typer.Option(help="Target BOLD data space"),
65
+ ] = "MNI152NLin2009cAsym",
66
+ n_processes: Annotated[
67
+ int,
68
+ typer.Option(help="Number of processes to run in parallel"),
69
+ ] = 1,
70
+ ):
71
+ """
72
+ Clean BOLD data for all subjects in the given fMRIPrep outputs.
73
+ """
74
+ subject_ids = [
75
+ path.name[4:] for path in Path(fmriprep_dir).glob("sub-*") if path.is_dir()
76
+ ]
77
+
78
+ def clean_bold(subject_ids: list[str]):
79
+ reg = ConfoundRegression(
80
+ config_file=config_file,
81
+ fmriprep_dir=fmriprep_dir,
82
+ output_dir=output_dir,
83
+ custom_confounds_dir=custom_confounds_dir,
84
+ )
85
+
86
+ reg.clean_bold(
87
+ model_name=model_name,
88
+ subject_ids=subject_ids,
89
+ session_name=session_name,
90
+ task_name=task_name,
91
+ data_space_name=data_space_name,
92
+ )
93
+
94
+ if n_processes < 2:
95
+ clean_bold(subject_ids)
96
+ else:
97
+ if mp.current_process().name == "MainProcess":
98
+ max_processes = mp.cpu_count()
99
+ if n_processes > max_processes:
100
+ n_processes = max_processes
101
+ print(
102
+ "[bold yellow]Warning:[/bold yellow] "
103
+ "Requested processes exceed available CPU "
104
+ "cores. Resetting to match available cores."
105
+ )
106
+
107
+ processes: list[DillProcess] = []
108
+ for i in range(n_processes):
109
+ p = DillProcess(target=clean_bold, args=(subject_ids[i::n_processes],))
110
+ processes.append(p)
111
+ p.start()
112
+ for p in processes:
113
+ p.join()
114
+
115
+
116
+ @app.callback()
117
+ def callback():
118
+ """
119
+ An opinionated framework/toolbox for conducting
120
+ data cleaning and analysis in hyperscanning studies
121
+ involving dyadic conversations.
122
+ """
@@ -0,0 +1,23 @@
1
+ from enum import Enum
2
+
3
+
4
+ class CompCorMethod(Enum):
5
+ ANATOMICAL = "aCompCor"
6
+ TEMPORAL = "tCompCor"
7
+ MEAN = "Mean"
8
+
9
+
10
+ class CompCorTissue(Enum):
11
+ CSF = "CSF"
12
+ WM = "WM"
13
+ COMBINED = "combined"
14
+
15
+
16
+ class SurfaceSpace(Enum):
17
+ FS_AVERAGE_5 = "fsaverage5"
18
+ FS_AVERAGE_6 = "fsaverage6"
19
+
20
+
21
+ class VolumeSpace(Enum):
22
+ MNI_152_NLIN_6_ASYM = "MNI152NLin6Asym"
23
+ MNI_152_NLIN_2009_C_ASYM = "MNI152NLin2009cAsym"