Skip to content

Commit

Permalink
update load_db script (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
nleroy917 committed Dec 21, 2023
1 parent f6fb1a6 commit 2858949
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@ postgres/
.idea
environment/local.env
qdrant_storage/
postgres-data/
postgres-data/
local_cache/
7 changes: 5 additions & 2 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# pephub scripts

These are useful scripts for pephub. They provide utilities to manage the interface between PEPs, a PEP database, and PEPhub. Read below about each script.

### `load_db.py`
This will help you load a database of PEPs from a directory of PEPs.

This will help you load a database of PEPs from a directory of PEPs. Note, that a namespace is **required** for each PEP. This is the name of the folder that the PEP is in. For example, if you have a PEP in `peps/ChangLab/PEP_1`, then the namespace is `ChangLab`. If you have a PEP in `peps/demo/basic`, then the namespace is `demo`. The namespace is used to identify the PEP in the database.

**Usage:**

```console
python load_db.py \
--username $POSTGRES_USERNAME \
Expand Down Expand Up @@ -64,4 +67,4 @@ peps
│ ├── GSE101516
│ │ ├── GSE101516_samples.csv
│ │ └── GSE101516_samples.yaml
```
```
7 changes: 5 additions & 2 deletions scripts/load_db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import argparse
import os
from tqdm import tqdm
from pepdbagent import Connection
from pepdbagent import PEPDatabaseAgent as Connection
import peppy

from utils import is_valid_namespace, is_valid_project, extract_project_file_name
Expand Down Expand Up @@ -76,6 +76,7 @@ def build_connection_string(args: argparse.Namespace) -> str:
# get file path
FILE_PATH = args.files


# traverse directory
for name in tqdm(os.listdir(FILE_PATH), desc="Uploading repository", leave=True):
# build a path to the namespace
Expand All @@ -95,4 +96,6 @@ def build_connection_string(args: argparse.Namespace) -> str:
p = peppy.Project(
f"{path_to_proj}/{extract_project_file_name(path_to_proj)}"
)
pagent.upload_project(p, name)
pagent.project.create(
p, name, p.name, description=f"Uploaded from, {path_to_proj}"
)

0 comments on commit 2858949

Please sign in to comment.