Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample registry lib and tests #20

Merged
merged 8 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
COPY . .

RUN pip install -r requirements.txt
RUN pip install /app/app/sample_registry
RUN pip install /app/app/sample_registry/

ENTRYPOINT [ "python" ]
CMD [ "app/app.py" ]
5 changes: 4 additions & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def show_tags(tag=None, val=None):
@app.route("/runs")
@app.route("/runs/<run_acc>")
def show_runs(run_acc=None):
if run_acc:
run_acc = "".join(filter(str.isdigit, run_acc.strip())) # Sanitize run_acc

if request.path.endswith(".json"):
run = db.session.query(Run).filter(Run.run_accession == run_acc).all()
with open(f"run_{run_acc}", "wb") as f: # TEMP
Expand Down Expand Up @@ -176,7 +179,7 @@ def show_runs(run_acc=None):
def show_stats():
num_samples = db.session.query(Sample).count()
num_samples_with_sampletype = (
db.session.query(Sample).filter(Sample.sample_type != None).count()
db.session.query(Sample).filter(Sample.sample_type is not None).count()
)
num_samples_with_standard_sampletype = (
db.session.query(Sample)
Expand Down
40 changes: 25 additions & 15 deletions app/sample_registry/src/sample_registry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@ def sample_registry_version():
sys.stderr.write(__version__)


try:
db_host = os.environ["DB_HOST"]
db_user = os.environ["DB_USER"]
db_name = os.environ["DB_NAME"]
db_pswd = os.environ["DB_PSWD"]
SQLALCHEMY_DATABASE_URI = f"postgresql://{db_user}:{db_pswd}@{db_host}/{db_name}"
except KeyError:
# For development purposes, use a SQLite db prefilled with some demo data
sys.stdout.write(
"Missing database connection information in environment, using test SQLite database\n"
)
sys.stdout.write(
f"DB_HOST: {os.environ.get('DB_HOST')}\nDB_USER: {os.environ.get('DB_USER')}\nDB_NAME: {os.environ.get('DB_NAME')}\nDB_PSWD: {os.environ.get('DB_PSWD')}\n"
)
SQLALCHEMY_DATABASE_URI = f"sqlite:///{Path(__file__).parent.parent.parent.parent.parent.resolve()}/sample_registry.sqlite3"
print({k: v for k, v in os.environ.items() if "PYTEST" in k})

if "PYTEST_VERSION" in os.environ:
# Set SQLALCHEMY_DATABASE_URI to an in-memory SQLite database for testing
SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:"
else:
try:
db_host = os.environ["DB_HOST"]
db_user = os.environ["DB_USER"]
db_name = os.environ["DB_NAME"]
db_pswd = os.environ["DB_PSWD"]
SQLALCHEMY_DATABASE_URI = (
f"postgresql://{db_user}:{db_pswd}@{db_host}/{db_name}"
)
except KeyError:
# For development purposes, use a SQLite db prefilled with some demo data
sys.stdout.write(
"Missing database connection information in environment, using test SQLite database\n"
)
sys.stdout.write(
f"DB_HOST: {os.environ.get('DB_HOST')}\nDB_USER: {os.environ.get('DB_USER')}\nDB_NAME: {os.environ.get('DB_NAME')}\nDB_PSWD: {os.environ.get('DB_PSWD')}\n"
)
SQLALCHEMY_DATABASE_URI = f"sqlite:///{Path(__file__).parent.parent.parent.parent.parent.resolve()}/sample_registry.sqlite3"

print(SQLALCHEMY_DATABASE_URI)

# Create database engine
engine = create_engine(SQLALCHEMY_DATABASE_URI, echo=False)
Expand Down
Loading
Loading