annotate get_projects.py @ 0:a8eee1c3b6d7 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:34:56 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
1 import argparse
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
2 import os
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
4
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
5
a8eee1c3b6d7 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
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
8
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
9
a8eee1c3b6d7 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:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
11 """
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
13
a8eee1c3b6d7 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).
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
15 """
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
16
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
17 parser = argparse.ArgumentParser(
a8eee1c3b6d7 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"
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
19 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
20
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
22 parser.add_argument(
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
23 "-c",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
24 "--credentials-file",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
25 dest="credentials_file",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
26 type=str,
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
27 required=False, # Optional
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
28 help=(
a8eee1c3b6d7 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 "
a8eee1c3b6d7 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 "
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
31 "used."
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
32 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
33 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
34
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
36 parser.add_argument(
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
37 "-l",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
38 "--login-name",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
39 dest="login",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
40 type=str,
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
41 required=True,
a8eee1c3b6d7 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"
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
43 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
44
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
46 parser.add_argument(
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
47 "-o",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
48 "--output-file",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
49 dest="output",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
50 type=str,
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
51 default="projects.csv",
a8eee1c3b6d7 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')"
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
53 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
54
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
56 parser.add_argument(
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
57 "-t",
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
58 "--type",
a8eee1c3b6d7 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"],
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
60 default="generic",
a8eee1c3b6d7 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')"
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
62 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
63
a8eee1c3b6d7 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()
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
65
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
66
a8eee1c3b6d7 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):
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
68 """
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
70
a8eee1c3b6d7 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:
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
74
a8eee1c3b6d7 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.
a8eee1c3b6d7 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
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
78 """
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
79
a8eee1c3b6d7 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
a8eee1c3b6d7 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 "."
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
82
a8eee1c3b6d7 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
a8eee1c3b6d7 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):
a8eee1c3b6d7 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}")
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
86
a8eee1c3b6d7 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
a8eee1c3b6d7 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")
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
89
a8eee1c3b6d7 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
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
92
a8eee1c3b6d7 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"
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
94
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
95
a8eee1c3b6d7 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:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
97 """
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
99
a8eee1c3b6d7 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,
a8eee1c3b6d7 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:
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
103
a8eee1c3b6d7 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.
a8eee1c3b6d7 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
a8eee1c3b6d7 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.
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
108 """
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
109
a8eee1c3b6d7 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:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
111 credentials = load(file)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
112
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
113 dialect = credentials["dialect"]
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
114 username = credentials["user"]
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
115 password = credentials["password"]
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
116 host = credentials["host"]
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
117 port = credentials["port"]
a8eee1c3b6d7 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"]
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
119
a8eee1c3b6d7 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}"
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
121
a8eee1c3b6d7 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)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
123
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
124
a8eee1c3b6d7 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:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
126 """
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
128
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
133 """
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
134
a8eee1c3b6d7 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.
a8eee1c3b6d7 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"]
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
137
a8eee1c3b6d7 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.
a8eee1c3b6d7 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)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
140
a8eee1c3b6d7 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.
a8eee1c3b6d7 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()
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
143
a8eee1c3b6d7 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.
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
146
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
147
a8eee1c3b6d7 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):
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
149 """
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
151
a8eee1c3b6d7 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:
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
156
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
161 """
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
162
a8eee1c3b6d7 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"]
a8eee1c3b6d7 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"]
a8eee1c3b6d7 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"]
a8eee1c3b6d7 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"]
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
167
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
168 # Construct the query:
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 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.
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
177
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
178 query = (
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
179 db.select(
a8eee1c3b6d7 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"),
a8eee1c3b6d7 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"),
a8eee1c3b6d7 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")
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
183 )
a8eee1c3b6d7 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)
a8eee1c3b6d7 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)
a8eee1c3b6d7 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)
a8eee1c3b6d7 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)
a8eee1c3b6d7 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)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
189 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
190
a8eee1c3b6d7 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.
a8eee1c3b6d7 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())
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
193
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
194
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
195 def main():
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
196
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
198 args = get_arguments()
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
199
a8eee1c3b6d7 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
a8eee1c3b6d7 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)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
202
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
203 try:
a8eee1c3b6d7 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
a8eee1c3b6d7 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)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
206
a8eee1c3b6d7 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
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
208 metadata = db.MetaData()
a8eee1c3b6d7 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"])
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
210
a8eee1c3b6d7 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:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
212 # Get user ID
a8eee1c3b6d7 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)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
214
a8eee1c3b6d7 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:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
216 raise ValueError(
a8eee1c3b6d7 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 \"{}\". "
a8eee1c3b6d7 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 "
a8eee1c3b6d7 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/."
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
220 .format(args.login)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
221 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
222
a8eee1c3b6d7 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
a8eee1c3b6d7 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)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
225
a8eee1c3b6d7 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
a8eee1c3b6d7 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:
a8eee1c3b6d7 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))
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
229
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
230 # Display the result
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
231 if projects.empty:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
232 raise ValueError(
a8eee1c3b6d7 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 \"{}\". "
a8eee1c3b6d7 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."
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
235 .format(args.login)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
236 )
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
237 else:
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
238 print(projects)
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
239
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
240 except FileNotFoundError:
a8eee1c3b6d7 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}\".")
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
242
a8eee1c3b6d7 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:
a8eee1c3b6d7 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}")
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
245
a8eee1c3b6d7 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:
a8eee1c3b6d7 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}")
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
248
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
249
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
250 if __name__ == "__main__":
a8eee1c3b6d7 planemo upload for repository https://github.com/jw44lavo/galaxy-tools/blob/bgo/tools/lambdaminer/ commit 3f45cd07445498cefa73931cadf3d1115245ca1e
ufz
parents:
diff changeset
251 main()