• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miykael / atlasreader / 14943562776

10 May 2025 08:19AM UTC coverage: 85.622%. Remained the same
14943562776

push

github

M.Notter
Adds Shaefer 200 atlas

0 of 1 new or added line in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

399 of 466 relevant lines covered (85.62%)

4.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.08
/atlasreader/cli.py
1
"""
2
Functions for command line interface to generate cluster / peak summary
3
"""
4

5
import argparse
5✔
6
import os.path as op
5✔
7

8
from atlasreader.atlasreader import (
5✔
9
    _ATLASES,
10
    check_atlases,
11
    create_output,
12
    read_atlas_peak,
13
)
14

15

16
def _check_limit(num, limits=[0, 100]):
5✔
17
    """
18
    Ensures that `num` is within provided `limits`
19

20
    Parameters
21
    ----------
22
    num : float
23
        Number to assess
24
    limits : list, optional
25
        Lower and upper bounds that `num` must be between to be considered
26
        valid
27
    """
28
    lo, hi = limits
×
29
    num = float(num)
×
30

31
    if num < lo or num > hi:
×
32
        raise ValueError(f"Provided value {num} is outside expected limits {limits}.")
×
33

34
    return num
×
35

36

37
def _atlasreader_parser():
5✔
38
    """Reads command line arguments and returns input specifications"""
39
    parser = argparse.ArgumentParser()
×
40
    parser.add_argument(
×
41
        "filename",
42
        type=op.abspath,
43
        metavar="file",
44
        help="The full or relative path to the statistical "
45
        "map from which cluster information should be "
46
        "extracted.",
47
    )
48
    parser.add_argument(
×
49
        "cluster_extent",
50
        type=int,
51
        metavar="min_cluster_size",
52
        help="Number of contiguous voxels required for a "
53
        "cluster to be considered for analysis.",
54
    )
55
    parser.add_argument(
×
56
        "-a",
57
        "--atlas",
58
        type=str.lower,
59
        default="default",
60
        nargs="+",
61
        choices=_ATLASES + ["all", "default"],
62
        metavar="atlas",
63
        help="Atlas(es) to use for examining anatomical "
64
        "delineation of clusters in provided statistical "
65
        "map. Default: AAL, Desikan-Killiany & "
66
        "Harvard-Oxford.",
67
    )
68
    parser.add_argument(
×
69
        "-t",
70
        "--threshold",
71
        type=float,
72
        default=1.96,
73
        dest="voxel_thresh",
74
        metavar="threshold",
75
        help="Value threshold that voxels in provided file "
76
        "must surpass in order to be considered in "
77
        "cluster extraction. Use `direction` to specify "
78
        "the directionallity of the threshold. If a "
79
        "negative number is provided a  percentile "
80
        "threshold is used instead, where the percentile "
81
        "is determined by the equation "
82
        "`100 - voxel_thresh`. Default: 1.96",
83
    )
84
    parser.add_argument(
×
85
        "-x",
86
        "--direction",
87
        type=str,
88
        default="both",
89
        dest="direction",
90
        metavar="direction",
91
        help="Specifies the direction in which the threshold "
92
        "should be applied. Possible values are "
93
        "'both', 'pos' or 'neg'. Default: 'both'",
94
    )
95
    parser.add_argument(
×
96
        "-p",
97
        "--probability",
98
        type=_check_limit,
99
        default=5,
100
        dest="prob_thresh",
101
        metavar="threshold",
102
        help="Threshold to consider when using a "
103
        "probabilistic atlas for extracting anatomical "
104
        "cluster locations. Value will apply to all "
105
        "request probabilistic atlases, and should range "
106
        "between 0 and 100. Default: 5",
107
    )
108
    parser.add_argument(
×
109
        "-o",
110
        "--outdir",
111
        type=str,
112
        default=None,
113
        dest="outdir",
114
        metavar="outdir",
115
        help="Output directory for created files. If it is "
116
        "not specified, then output files are created in "
117
        "the same directory as the statistical map that "
118
        "is provided. Default: None",
119
    )
120
    parser.add_argument(
×
121
        "-d",
122
        "--mindist",
123
        type=float,
124
        default=None,
125
        dest="min_distance",
126
        metavar="distance",
127
        help="If specified, the program will attempt to find "
128
        "subpeaks within detected clusters, rather than "
129
        "a single peak per cluster. The specified value "
130
        "will determine the minimum distance (in mm) "
131
        "required between subpeaks. Default: None",
132
    )
133
    return parser.parse_args()
×
134

135

136
def atlasreader_main():
5✔
137
    """
138
    The primary entrypoint for calling atlas reader via the command line
139

140
    All parameters are read via argparse, so this should only be called from
141
    the command line!
142
    """
143

144
    opts = _atlasreader_parser()
×
145
    create_output(
×
146
        opts.filename,
147
        atlas=check_atlases(opts.atlas),
148
        voxel_thresh=opts.voxel_thresh,
149
        direction=opts.direction,
150
        cluster_extent=opts.cluster_extent,
151
        prob_thresh=opts.prob_thresh,
152
        outdir=opts.outdir,
153
        min_distance=opts.min_distance,
154
    )
155

156

157
def _queryatlas_parser():
5✔
158
    """Reads command line arguments and returns input specifications"""
159

160
    parser = argparse.ArgumentParser()
×
161
    parser.add_argument(
×
162
        "coordinate",
163
        nargs=3,
164
        type=float,
165
        help="The coordinate (in MNI space) for which to "
166
        "query atlases. Should be provided as space-"
167
        "delimited x y z coordinates, e.g., -10.5 -30.0 "
168
        "15.3.",
169
    )
170
    parser.add_argument(
×
171
        "-a",
172
        "--atlas",
173
        type=str.lower,
174
        default="all",
175
        nargs="+",
176
        choices=_ATLASES + ["all"],
177
        metavar="atlas",
178
        help="Atlas(es) to use for examining anatomical "
179
        "delineation of clusters in provided statistical "
180
        "map. Default: all available atlases.",
181
    )
182
    parser.add_argument(
×
183
        "-p",
184
        "--probability",
185
        type=_check_limit,
186
        default=5,
187
        dest="prob_thresh",
188
        metavar="threshold",
189
        help="Threshold to consider when using a "
190
        "probabilistic atlas for extracting anatomical "
191
        "cluster locations. Value will apply to all "
192
        "requested probabilistic atlases, and should "
193
        "range between 0 and 100. Default: 5",
194
    )
195
    return parser.parse_args()
×
196

197

198
def queryatlas_main():
5✔
199
    """
200
    The primary entrypoint for querying atlases via the command line
201

202
    All parameters are read via argparse, so this should only be called from
203
    the command line!
204
    """
205

206
    opts = _queryatlas_parser()
×
207
    print("{0:<25} {1:<25}\n{2:<25} {2:<25}".format("Atlas", "Label", "=" * 10))
×
208
    for atlas in check_atlases(opts.atlas):
×
209
        label = read_atlas_peak(atlas, opts.coordinate, opts.prob_thresh)
×
210
        if isinstance(label, list):
×
NEW
211
            label = "\n{}".format(" " * 26).join(
×
212
                ["{:>2}% {}".format(*e) for e in label]
213
            )
UNCOV
214
        print(f"{atlas.atlas:<25} {label}")
×
215

216

217
if __name__ == "__main__":
5✔
218
    raise RuntimeError(
×
219
        "`atlasreader/cli.py` should not be run "
220
        "directly. Please `pip install` atlasreader and "
221
        "use the `atlasreader` or `queryatlas` commands, "
222
        "instead."
223
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc