-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpepingester.py
70 lines (60 loc) · 2.03 KB
/
pepingester.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import peppy
from pepdbagent import Connection
from pepdbagent.const import DEFAULT_TAG
from geofetch import Geofetcher
from const import INPUT_TYPES
from utils import build_argparser, detect_input_type
def main():
# build and parse args
parser = build_argparser()
args = parser.parse_args()
# init pep agent
pagent = Connection(
host=args.hostname,
port=args.port,
database=args.dbname,
user=args.username,
password=args.password,
)
# init geofetcher
geofetcher = Geofetcher(processed=True, data_source="all")
# get PEP input type
input_type = args.type or detect_input_type(args.pep)
if input_type not in INPUT_TYPES:
raise ValueError(
f"Input type couldnt be detected. Please ensure a valid path to a PEP or GEO accession was supplied."
)
if input_type == "path":
p = peppy.Project(args.pep)
p.name = args.project_name
pagent.upload_project(
p,
namespace=args.namespace,
name=args.project_name,
tag=(args.tag or DEFAULT_TAG),
)
return 0
if input_type == "geo":
# here I will use the geofetch.Geofetcher object to create a
# peppy.Project object from an accession id and then
# upload it to the database
projects = geofetcher.get_project(args.pep)
for d_type, project in projects.items():
tag = d_type.replace("_", "")
print(f"PROJECT_NAME: {args.project_name}")
if project: # verify that there was no error (False) or the datatype existed (not None)
project.name = args.project_name
pagent.upload_project(
project,
namespace=args.namespace,
name=args.project_name,
tag=tag,
)
return 0
if __name__ == "__main__":
try:
sys.exit(main())
except KeyboardInterrupt:
print("Canceling pipeline.")
sys.exit(1)