annotate get_projects.py @ 0:713502c9a98f draft default tip

planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
author ufz
date Mon, 17 Mar 2025 20:35:10 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
1 import argparse
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
2 import os
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
3 from json import load
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
4
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
5
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
6 import pandas as pd
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
7 import sqlalchemy as db
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
8
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
9
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
10 def get_arguments() -> argparse.Namespace:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
11 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
12 Parse and return the command-line arguments required for the script.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
13
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
14 return: argparse.Namespace: Parsed arguments containing credentials_file (str) and login (str).
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
15 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
16
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
17 parser = argparse.ArgumentParser(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
18 description="Read the projects of the current user from the Lambda-Miner Database"
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
19 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
20
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
21 # Add argument for the credentials file
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
22 parser.add_argument(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
23 "-c",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
24 "--credentials-file",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
25 dest="credentials_file",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
26 type=str,
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
27 required=False, # Optional
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
28 help=(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
29 "Credential file in JSON format including dialect, user, password, host, port, and "
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
30 "database. If not provided, the environment variable LAMBDAMINER_CREDENTIALS will be "
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
31 "used."
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
32 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
33 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
34
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
35 # Add argument for the login name
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
36 parser.add_argument(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
37 "-l",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
38 "--login-name",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
39 dest="login",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
40 type=str,
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
41 required=True,
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
42 help="UFZ login name of the user"
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
43 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
44
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
45 # Add argument for the output file
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
46 parser.add_argument(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
47 "-o",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
48 "--output-file",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
49 dest="output",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
50 type=str,
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
51 default="projects.csv",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
52 help="Specifiy the output file path including the file name (default: 'projects.csv')"
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
53 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
54
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
55 # Add argument for the type
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
56 parser.add_argument(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
57 "-t",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
58 "--type",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
59 choices=["generic", "import", "calibration", "assignment", "validation", "export"],
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
60 default="generic",
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
61 help="Specify the workflow type (default: 'generic')"
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
62 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
63
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
64 return parser.parse_args()
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
65
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
66
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
67 def parse_check_args(args):
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
68 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
69 Parse and validate command line arguments.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
70
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
71 Following actions are performed:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
72 - Check of the existence of the specified directory in the output path.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
73 - Assignment the correct credentials file to the arguments.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
74
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
75 :param args: command line arguments.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
76 :type args: argparse.Namespace
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
77 :raises FileNotFoundError: If the specified directory in the output path does not exist.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
78 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
79
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
80 # Extract the directory part of the specified output path
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
81 dir_path = os.path.dirname(args.output) or "."
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
82
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
83 # Check if the directory exists and raise error if not
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
84 if not os.path.isdir(dir_path):
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
85 raise FileNotFoundError(f"Error: The directory does not exist: {dir_path}")
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
86
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
87 # Get environment variable LAMBDAMINER_CREDENTIALS
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
88 envar_credentials = os.getenv("LAMBDAMINER_CREDENTIALS")
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
89
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
90 # Use the provided argument or fallback to the environment variable
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
91 args.credentials_file = args.credentials_file or envar_credentials
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
92
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
93 assert args.credentials_file is not None, "Error: No credentials specified"
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
94
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
95
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
96 def get_engine(credentials_path: str, echo: bool = False) -> db.engine.Engine:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
97 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
98 Create and return a SQLAlchemy engine based on the supplied credentials.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
99
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
100 The engine is created using the data from the supplied credentials file,
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
101 which should be in JSON format and include the following keys:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
102 dialect, user, password, host, port, database
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
103
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
104 :param credentials_path: The path to the credentials file.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
105 :type credentials_path: str
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
106 :return: The SQLAlchemy engine object.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
107 :rtype: sqlalchemy.engine.Engine
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
108 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
109
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
110 with open(credentials_path) as file:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
111 credentials = load(file)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
112
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
113 dialect = credentials["dialect"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
114 username = credentials["user"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
115 password = credentials["password"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
116 host = credentials["host"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
117 port = credentials["port"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
118 database_name = credentials["database"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
119
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
120 database_url = f"{dialect}://{username}:{password}@{host}:{port}/{database_name}"
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
121
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
122 return db.create_engine(database_url, echo=echo)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
123
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
124
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
125 def get_user_id(connection, metadata, login: str) -> int:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
126 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
127 Retrieve the user_id for a given login.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
128
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
129 :param connection: The database connection.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
130 :param metadata: The database metadata containing table definitions.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
131 :param login: The login username to search for.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
132 :return: The user_id if found, otherwise None.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
133 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
134
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
135 # Access the 'ufz_user' table from metadata.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
136 User = metadata.tables["ufz_user"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
137
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
138 # Construct a query to select the user_id where the login matches.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
139 query = db.select(User.c.user_id).where(User.c.login == login)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
140
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
141 # Execute the query and fetch the scalar result.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
142 result = connection.execute(query).scalar()
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
143
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
144 # Return the user_id as an integer if found, otherwise return None.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
145 return int(result) if result else None
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
146
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
147
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
148 def get_projects_with_sample_count(connection, metadata, user_id):
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
149 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
150 Retrieve projects and their sample counts for a given user_id.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
151
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
152 The query will return a pandas DataFrame with the columns:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
153 project_id : The id of the project.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
154 name : The name of the project.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
155 sample_count : The number of samples associated with the project.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
156
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
157 :param connection: The database connection.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
158 :param metadata: The database metadata containing table definitions.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
159 :param user_id: The user_id to search for.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
160 :return: A pandas DataFrame with the projects and their sample counts.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
161 """
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
162
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
163 User = metadata.tables["ufz_user"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
164 User_Project = metadata.tables["ufz_user_project"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
165 Project = metadata.tables["project"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
166 Sample = metadata.tables["sample"]
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
167
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
168 # Construct the query:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
169 # 1. Select project_id, name and the count of sample_id as sample_count.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
170 # 2. Join the tables ufz_user_project, ufz_user, project and sample.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
171 # - Join ufz_user_project with project on project_id.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
172 # - Join ufz_user with ufz_user_project on user_id.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
173 # - Join sample with project on project_id.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
174 # - Use an outer join to include projects without samples.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
175 # 3. Filter the results to only include the given user_id.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
176 # 4. Group the results by project_id and name.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
177
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
178 query = (
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
179 db.select(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
180 Project.c.project_id.label("Project ID"),
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
181 Project.c.name.label("Project Name"),
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
182 db.func.count(Sample.c.sample_id).label("Sample Count")
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
183 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
184 .join(User_Project, User_Project.c.project_id == Project.c.project_id)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
185 .join(User, User.c.user_id == User_Project.c.user_id)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
186 .join(Sample, Sample.c.project == Project.c.project_id, isouter=True)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
187 .where(User.c.user_id == user_id)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
188 .group_by(Project.c.project_id, Project.c.name)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
189 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
190
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
191 # Execute the query, fetch the results, and return the DataFrame.
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
192 return pd.DataFrame(connection.execute(query).fetchall())
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
193
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
194
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
195 def main():
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
196
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
197 # Parse command-line arguments
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
198 args = get_arguments()
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
199
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
200 # Parse and check the specified command line arguments
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
201 parse_check_args(args)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
202
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
203 try:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
204 # Load credentials and create the database engine
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
205 engine = get_engine(args.credentials_file)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
206
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
207 # Reflect metadata and connect to the database
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
208 metadata = db.MetaData()
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
209 metadata.reflect(bind=engine, only=["ufz_user", "ufz_user_project", "project", "sample"])
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
210
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
211 with engine.connect() as conn:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
212 # Get user ID
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
213 user_id = get_user_id(conn, metadata, args.login)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
214
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
215 if not user_id:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
216 raise ValueError(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
217 "No Lambda-Miner user found with the login name \"{}\". "
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
218 "Please find the description on how to register for the Lambda-Miner at "
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
219 "https://lambda-miner-project.pages.ufz.de/lambda-miner-workflows/getting-started/."
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
220 .format(args.login)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
221 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
222
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
223 # Get projects with sample counts
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
224 projects = get_projects_with_sample_count(conn, metadata, user_id)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
225
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
226 # Write projects as a CSV file to the specified output
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
227 with open(args.output, "w") as f:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
228 f.write(projects.to_csv(index=False))
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
229
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
230 # Display the result
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
231 if projects.empty:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
232 raise ValueError(
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
233 "No projects found for the user \"{}\". "
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
234 "Please create a project before going on."
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
235 .format(args.login)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
236 )
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
237 else:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
238 print(projects)
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
239
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
240 except FileNotFoundError:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
241 raise FileNotFoundError(f"Credentials file not found at \"{args.credentials_file}\".")
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
242
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
243 except db.exc.SQLAlchemyError as e:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
244 raise RuntimeError(f"Database error occurred: {e}")
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
245
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
246 except Exception as e:
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
247 raise RuntimeError(f"An unexpected error occurred: {e}")
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
248
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
249
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
250 if __name__ == "__main__":
713502c9a98f planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
251 main()