onconova.terminology.utils
CodeSystemMap
module-attribute
¶
ensure_list(val)
¶
Ensure that a given value is returned as a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
The value to be checked and converted into a list if necessary. |
required |
Returns:
Type | Description |
---|---|
List[Any]
|
List[Any]: A list containing the original value if it was not a list, otherwise the original list itself. |
Source code in onconova/terminology/utils.py
ensure_within_string_limits(string)
¶
get_dictreader_and_size(file, has_header=True, verbose=True)
¶
Get a DictReader for a file and the total number of rows. Accepts .csv
, .tsv
, and .obo
files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
TextIO
|
The file to read from. |
required |
|
bool
|
True if the file has a header row. Defaults to True. |
True
|
|
bool
|
True if progress should be printed. Defaults to True. |
True
|
Returns:
Type | Description |
---|---|
Tuple[DictReader | List[Dict[str, str]], int]
|
Tuple[List[Dict[str, str]], int]: A tuple containing the DictReader (or list for OBO files) and the number of rows. |
Raises:
Type | Description |
---|---|
ValueError
|
If the file format is not supported. |
Source code in onconova/terminology/utils.py
get_file_location(path, filepart)
¶
Get the file location by searching for a file containing the specified substring in its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The directory path to search in. |
required |
|
str
|
The substring to search for in file names. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The full path of the found file. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If no file containing the substring is found in the directory. |
Source code in onconova/terminology/utils.py
parent_to_children(codesystem)
¶
Preprocesses the codesystem to create a mapping from parent codes to their children.
This function takes in a codesystem as a dictionary where each value is a concept with code
and parent
attributes. It then creates a mapping from parent codes to their children (i.e., concepts that have the parent
code as their parent
attribute).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
dict
|
A dictionary where each value is a concept with |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
Mapping[str, List[CodedConcept]]
|
A dictionary mapping parent codes to a list of their child concepts. |
Notes
This function caches its results, so if it is called with the same codesystem multiple times, it will return the same result without recomputing it.
Source code in onconova/terminology/utils.py
parse_OBO_file(file)
¶
Parses a Gene Ontology dump in OBO v1.2 format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
Any
|
An iterable object that yields lines of text, representing an OBO file. |
required |
Yields:
Name | Type | Description |
---|---|---|
dict |
Dict[str, Any]
|
Each GO term as a dictionary with keys as term attributes and values as attributes' values, converting single-element lists to single values. |
Source code in onconova/terminology/utils.py
printGreen(skk)
¶
printRed(skk)
¶
printYellow(skk)
¶
request_http_get(api_url, raw=False)
¶
Make a GET request to an API endpoint, parse the JSON response, and return the parsed JSON data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
The URL of the API endpoint to make the request to. |
required |
|
bool
|
If True, return the raw response text instead of the parsed JSON data. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Any
|
Union[Dict[str, Any], str]: The parsed JSON data if raw is False, otherwise the raw response text. |
Note
This function sets up the necessary configurations, including basic authentication, proxies, and certificate verification, to make a secure API request.
Source code in onconova/terminology/utils.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|