Package geofetch Documentation
Package Overview
The geofetch package provides tools for downloading metadata and data from Gene Expression Omnibus (GEO) and Sequence Read Archive (SRA). It can convert GEO/SRA metadata into PEP format for easy integration with other PEPkit tools.
Key Features
- GEO/SRA Download: Fetch metadata and raw data from NCBI repositories
- PEP Generation: Automatically create PEP-formatted project configs
- Flexible Filtering: Search and filter GEO datasets by date and criteria
- SRA Integration: Download and convert SRA data to FASTQ format
- Processed Data: Download processed data matrices from GEO
Installation
pip install geofetch
Quick Example
from geofetch import Geofetcher
# Initialize geofetcher
gf = Geofetcher()
# Fetch a GEO series
gf.fetch_all(input="GSE####", name="my_project")
API Reference
Geofetcher Class
The main class for fetching data from GEO/SRA:
Geofetcher
Geofetcher(name='', metadata_root='', metadata_folder='', just_metadata=False, refresh_metadata=False, config_template=None, pipeline_samples=None, pipeline_project=None, skip=0, acc_anno=False, use_key_subset=False, processed=False, data_source='samples', filter=None, filter_size=None, geo_folder='.', split_experiments=False, bam_folder='', fq_folder='', sra_folder='', bam_conversion=False, picard_path='', input=None, const_limit_project=50, const_limit_discard=1000, attr_limit_truncate=500, max_soft_size='1GB', discard_soft=False, add_dotfile=False, disable_progressbar=False, add_convert_modifier=False, opts=None, max_prefetch_size=None, **kwargs)
Class to download or get projects, metadata, data from GEO and SRA.
Constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str | None
|
GSE number or path to the input file. |
None
|
name
|
str
|
Specify a project name. Defaults to GSE number or name of accessions file name. |
''
|
metadata_root
|
str
|
Specify a parent folder location to store metadata. The project name will be added as a subfolder (Default: $SRAMETA:). |
''
|
metadata_folder
|
str
|
Specify an absolute folder location to store metadata. No subfolder will be added. Overrides value of --metadata-root (Default: Not used (--metadata-root is used by default)). |
''
|
just_metadata
|
bool
|
If set, don't actually run downloads, just create metadata. |
False
|
refresh_metadata
|
bool
|
If set, re-download metadata even if it exists. |
False
|
config_template
|
str | None
|
Project config yaml file template. |
None
|
pipeline_samples
|
str | None
|
Specify one or more filepaths to SAMPLES pipeline interface yaml files. These will be added to the project config file to make it immediately compatible with looper. (Default: null). |
None
|
pipeline_project
|
str | None
|
Specify one or more filepaths to PROJECT pipeline interface yaml files. These will be added to the project config file to make it immediately compatible with looper. (Default: null). |
None
|
acc_anno
|
bool
|
Produce annotation sheets for each accession. Project combined PEP for the whole project won't be produced. |
False
|
discard_soft
|
bool
|
Create project without downloading soft files on the disc. |
False
|
add_dotfile
|
bool
|
Add .pep.yaml file that points .yaml PEP file. |
False
|
disable_progressbar
|
bool
|
Set true to disable progressbar. |
False
|
const_limit_project
|
int
|
Optional: Limit of the number of the constant sample characters that should not be in project yaml. (Default: 50). |
50
|
const_limit_discard
|
int
|
Optional: Limit of the number of the constant sample characters that should not be discarded (Default: 250). |
1000
|
attr_limit_truncate
|
int
|
Optional: Limit of the number of sample characters. Any attribute with more than X characters will truncate to the first X, where X is a number of characters (Default: 500). |
500
|
max_soft_size
|
str
|
Optional: Max size of soft file. Supported input formats: 12B, 12KB, 12MB, 12GB. [Default value: 1GB]. |
'1GB'
|
processed
|
bool
|
Download processed data (Default: download raw data). |
False
|
data_source
|
str
|
Specifies the source of data on the GEO record to retrieve processed data, which may be attached to the collective series entity, or to individual samples. Allowable values are: samples, series or both (all). Ignored unless 'processed' flag is set. (Default: samples). |
'samples'
|
filter
|
str | None
|
Filter regex for processed filenames (Default: None). Ignored unless 'processed' flag is set. |
None
|
filter_size
|
str | None
|
Filter size for processed files that are stored as sample repository (Default: None). Works only for sample data. Supported input formats: 12B, 12KB, 12MB, 12GB. Ignored unless 'processed' flag is set. |
None
|
geo_folder
|
str
|
Specify a location to store processed GEO files. Ignored unless 'processed' flag is set. (Default: $GEODATA:). |
'.'
|
split_experiments
|
bool
|
Split SRR runs into individual samples. By default, SRX experiments with multiple SRR Runs will have a single entry in the annotation table, with each run as a separate row in the subannotation table. This setting instead treats each run as a separate sample [Works with raw data]. |
False
|
bam_folder
|
str
|
Optional: Specify folder of bam files. Geofetch will not download sra files when corresponding bam files already exist. (Default: $SRABAM:) [Works with raw data]. |
''
|
fq_folder
|
str
|
Optional: Specify folder of fastq files. Geofetch will not download sra files when corresponding fastq files already exist. (Default: $SRAFQ:) [Works with raw data]. |
''
|
use_key_subset
|
bool
|
Use just the keys defined in this module when writing out metadata. [Works with raw data]. |
False
|
sra_folder
|
str
|
Optional: Specify a location to store sra files. |
''
|
bam_conversion
|
bool
|
Optional: set True to convert bam files [Works with raw data]. |
False
|
picard_path
|
str
|
Specify a path to the picard jar, if you want to convert fastq to bam [Works with raw data]. |
''
|
add_convert_modifier
|
bool
|
Add looper SRA convert modifier to config file. |
False
|
skip
|
int
|
Skip some accessions. (Default: no skip). |
0
|
opts
|
object | None
|
opts object [Optional]. |
None
|
max_prefetch_size
|
str | int | None
|
Argument to prefetch command's --max-size option. |
None
|
kwargs
|
object
|
Other values. |
{}
|
Source code in geofetch/geofetch.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 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 | |
fetch_all
fetch_all(input, name=None)
Main function driver/workflow.
Searches, filters, downloads and saves data and metadata from GEO and SRA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
GSE or input file with GSE accessions. |
required |
name
|
str | None
|
Name of the project. |
None
|
Returns:
| Type | Description |
|---|---|
None | Project
|
None or peppy Project. |
Source code in geofetch/geofetch.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |
fetch_processed_one
fetch_processed_one(gse_file_content, gsm_file_content, gsm_filter_list)
Fetch one processed GSE project and return its metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gse_file_content
|
list[str]
|
GSE soft file content. |
required |
gsm_file_content
|
list[str]
|
GSM soft file content. |
required |
gsm_filter_list
|
dict
|
List of GSM that have to be downloaded. |
required |
Returns:
| Type | Description |
|---|---|
tuple[list, list]
|
Tuple of (meta_processed_samples, meta_processed_series). |
Source code in geofetch/geofetch.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
get_projects
get_projects(input, just_metadata=True, discard_soft=True)
Fetch projects from GEO|SRA and return peppy projects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
str
|
GSE number, or path to file of GSE numbers. |
required |
just_metadata
|
bool
|
Process only metadata. |
True
|
discard_soft
|
bool
|
Clean run, without downloading soft files. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Peppy project or list of projects, if acc_anno is set. |
Source code in geofetch/geofetch.py
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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
Finder Class
Class for searching and finding GSE accessions:
Finder
Finder(filters=None, retmax=RETMAX)
Class for finding GSE accessions in special period of time.
Initialize Finder with optional filters and result limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
str | None
|
Filters that have to be added to the query. Filter Patterns can be found here: https://www.ncbi.nlm.nih.gov/books/NBK3837/#EntrezHelp.Using_the_Advanced_Search_Pag |
None
|
retmax
|
int
|
Maximum number of retrieved accessions. |
RETMAX
|
Source code in geofetch/finder.py
32 33 34 35 36 37 38 39 40 41 42 43 44 | |
find_differences
staticmethod
find_differences(old_list, new_list)
Compare 2 lists and search for elements that are not in old list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_list
|
list[str]
|
Old list of elements. |
required |
new_list
|
list[str]
|
New list of elements. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of elements that are not in old list but are in new_list. |
Source code in geofetch/finder.py
135 136 137 138 139 140 141 142 143 144 145 146 147 | |
generate_file
generate_file(file_path, gse_list=None)
Save the list of GSE accessions stored in this Finder object to a given file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Root to the file where gse accessions have to be saved. |
required |
gse_list
|
list[str] | None
|
List of gse accessions. |
None
|
Source code in geofetch/finder.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
get_gse_all
get_gse_all()
Get list of all gse accessions available in GEO.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of gse accessions. |
Source code in geofetch/finder.py
46 47 48 49 50 51 52 53 | |
get_gse_by_date
get_gse_by_date(start_date, end_date=None)
Search gse accessions by providing start date and end date. By default, the last date is today.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
str
|
The oldest date of update (from YYYY/MM/DD to now) [input format: 'YYYY/MM/DD']. |
required |
end_date
|
str | None
|
The nearest date of update (from __ to YYYY/MM/DD) [input format: 'YYYY/MM/DD']. |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of gse accessions. |
Source code in geofetch/finder.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
get_gse_by_day_count
get_gse_by_day_count(n_days=1)
Get list of gse accessions that were uploaded or updated in last X days.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_days
|
int
|
Number of days from now [e.g. 5]. |
1
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of gse accessions. |
Source code in geofetch/finder.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
get_gse_id_by_query
get_gse_id_by_query(url)
Run esearch (ncbi search tool) by specifying URL and retrieve gse list result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL of the query. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of gse ids. |
Source code in geofetch/finder.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
get_gse_last_3_month
get_gse_last_3_month()
Get list of gse accessions that were uploaded or updated in last 3 months.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of gse accessions. |
Source code in geofetch/finder.py
55 56 57 58 59 60 61 62 | |
get_gse_last_week
get_gse_last_week()
Get list of gse accessions that were uploaded or updated in last week.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of gse accessions. |
Source code in geofetch/finder.py
64 65 66 67 68 69 70 71 | |
uid_to_gse
staticmethod
uid_to_gse(uid)
UID to GSE accession converter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uid
|
str
|
UID string (Unique Identifier Number in GEO). |
required |
Returns:
| Type | Description |
|---|---|
str
|
GSE id string. |
Source code in geofetch/finder.py
121 122 123 124 125 126 127 128 129 130 131 132 133 | |