annotate get_db_info.py @ 2:3bb9bbecae97 draft default tip

planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 767392e3136912fa30d1e0786eba789dd77d722c-dirty
author tduigou
date Wed, 03 Sep 2025 14:07:14 +0000
parents 54e716c11b71
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
1 import subprocess
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
2 import argparse
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
3 import time
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
4 import json
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
5 import os
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
6 import socket
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
7 import re
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
8 from Bio.Seq import Seq
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
9 import pandas as pd
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
10 from Bio.SeqRecord import SeqRecord
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
11 from sqlalchemy import create_engine, inspect
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
12 from sqlalchemy.engine.url import make_url
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
13 from sqlalchemy.sql import text
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
14 from sqlalchemy.exc import OperationalError
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
15
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
16
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
17 def fix_db_uri(uri):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
18 """Replace __at__ with @ in the URI if needed."""
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
19 return uri.replace("__at__", "@")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
20
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
21
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
22 def is_port_in_use(uri):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
23 """Check if a TCP port is already in use on host."""
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
24 url = make_url(uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
25 host = url.host
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
26 port = url.port
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
27 with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
28 s.settimeout(2)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
29 return s.connect_ex((host, port)) == 0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
30
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
31
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
32 def extract_db_name(uri):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
33 """Extract the database name from the SQLAlchemy URI."""
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
34 url = make_url(uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
35 return url.database
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
36
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
37
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
38 # this fuction is to activate the Docker id the DB is in container. BUT IT IS NOT USED IN MAIN()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
39 def start_postgres_container(db_name):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
40 """Start a PostgreSQL container with the given database name as the container name."""
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
41 container_name = db_name
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
42
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
43 # Check if container is already running
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
44 container_running = subprocess.run(
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
45 f"docker ps -q -f name={container_name}", shell=True, capture_output=True, text=True
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
46 )
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
47
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
48 if container_running.stdout.strip():
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
49 print(f"Container '{container_name}' is already running.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
50 return
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
51
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
52 # Check if container exists (stopped)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
53 container_exists = subprocess.run(
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
54 f"docker ps -a -q -f name={container_name}", shell=True, capture_output=True, text=True
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
55 )
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
56
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
57 if container_exists.stdout.strip():
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
58 print(f"Starting existing container '{container_name}'...")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
59 subprocess.run(f"docker start {container_name}", shell=True)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
60 print(f"PostgreSQL Docker container '{container_name}' activated.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
61 return
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
62
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
63 # If container does not exist, create and start a new one
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
64 port = 5432 if not is_port_in_use(5432) else 5433
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
65 postgres_password = os.getenv("POSTGRES_PASSWORD", "RK17")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
66
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
67 start_command = [
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
68 "docker", "run", "--name", container_name,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
69 "-e", f"POSTGRES_PASSWORD={postgres_password}",
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
70 "-p", f"{port}:5432",
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
71 "-d", "postgres"
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
72 ]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
73
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
74 try:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
75 subprocess.run(start_command, check=True)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
76 print(f"PostgreSQL Docker container '{container_name}' started on port {port}.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
77 except subprocess.CalledProcessError as e:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
78 print(f"Failed to start Docker container: {e}")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
79
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
80
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
81 def wait_for_db(uri, timeout=60):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
82 """Try connecting to the DB until it works or timeout."""
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
83 engine = create_engine(uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
84 start_time = time.time()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
85 while time.time() - start_time < timeout:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
86 try:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
87 with engine.connect():
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
88 print("Connected to database.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
89 return
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
90 except OperationalError:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
91 print("Database not ready, retrying...")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
92 time.sleep(2)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
93 raise Exception("Database connection failed after timeout.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
94
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
95
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
96 def fetch_annotations(csv_file, sequence_column, annotation_columns, db_uri, table_name, fragment_column_name, output, output_report):
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
97 """Fetch annotations from the database and save the result as GenBank files."""
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
98 db_uri = fix_db_uri(db_uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
99 df = pd.read_csv(csv_file, sep=',', header=None)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
100
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
101 engine = create_engine(db_uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
102 connection = engine.connect()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
103
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
104 annotated_data = []
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
105
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
106 try:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
107 with connection:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
108 inspector = inspect(engine)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
109 columns = [column['name'] for column in inspector.get_columns(table_name)]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
110
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
111 # Fetch all fragments from the table once
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
112 if fragment_column_name not in columns:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
113 raise ValueError(f"Fragment column '{fragment_column_name}' not found in table '{table_name}'.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
114
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
115 fragment_column_index = columns.index(fragment_column_name)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
116 all_rows = connection.execute(text(f"SELECT * FROM {table_name}")).fetchall()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
117 fragment_map = {row[fragment_column_index]: row for row in all_rows}
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
118
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
119 # Compare fragments between CSV and DB
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
120 csv_fragments = set()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
121 all_ids = set(df[0].dropna().astype(str))
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
122 for _, row in df.iterrows():
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
123 for col in df.columns:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
124 if col != 0:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
125 fragment = row[col]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
126 if pd.notna(fragment):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
127 fragment_str = str(fragment)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
128 if fragment_str not in all_ids:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
129 csv_fragments.add(fragment_str)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
130
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
131 db_fragments = set(fragment_map.keys())
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
132 missing_fragments = sorted(list(csv_fragments - db_fragments))
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
133
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
134 # Write report file
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
135 with open(output_report, "w") as report_file:
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
136 if missing_fragments:
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
137 for frag in missing_fragments:
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
138 report_file.write(f"{frag}\n")
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
139 else:
2
3bb9bbecae97 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 767392e3136912fa30d1e0786eba789dd77d722c-dirty
tduigou
parents: 1
diff changeset
140 report_file.write("")
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
141
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
142 # === CONTINUE WITH GB FILE CREATION ===
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
143 for _, row in df.iterrows():
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
144 annotated_row = {"Backbone": row[0], "Fragments": []}
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
145 for col in df.columns:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
146 if col != 0:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
147 fragment = row[col]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
148 if fragment not in csv_fragments:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
149 continue
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
150 db_row = fragment_map.get(fragment)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
151
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
152 if db_row:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
153 fragment_data = {"id": fragment}
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
154 for i, column_name in enumerate(columns[1:]): # skip ID column
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
155 fragment_data[column_name] = db_row[i + 1]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
156 else:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
157 fragment_data = {"id": fragment, "metadata": "No data found"}
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
158
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
159 annotated_row["Fragments"].append(fragment_data)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
160
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
161 annotated_data.append(annotated_row)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
162
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
163 except Exception as e:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
164 print(f"Error occurred during annotation: {e}")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
165 raise # Ensures the error exits the script
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
166
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
167 # GenBank file generation per fragment
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
168 try:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
169 for annotated_row in annotated_data:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
170 backbone_id = annotated_row["Backbone"]
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
171
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
172 for fragment in annotated_row["Fragments"]:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
173 fragment_id = fragment["id"]
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
174
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
175 # Skip generation for missing fragments
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
176 if fragment_id in missing_fragments:
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
177 continue
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
178
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
179 sequence = fragment.get(sequence_column, "")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
180 annotation = fragment.get(annotation_columns, "")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
181
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
182 # Create the SeqRecord
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
183 record = SeqRecord(
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
184 Seq(sequence),
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
185 id=fragment_id,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
186 name=fragment_id,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
187 description=f"Fragment {fragment_id} from Backbone {backbone_id}"
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
188 )
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
189
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
190 # Add annotations to GenBank header
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
191 record.annotations = {
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
192 k: str(fragment[k]) for k in annotation_columns if k in fragment
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
193 }
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
194
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
195 # LOCUS line extraction from annotation
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
196 locus_line_match = re.search(r"LOCUS\s+.+", annotation)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
197 if locus_line_match:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
198 locus_line = locus_line_match.group()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
199 else:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
200 print(f"LOCUS info missing for fragment {fragment_id}")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
201 locus_line = f"LOCUS {fragment_id: <20} {len(sequence)} bp DNA linear UNK 01-JAN-2025"
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
202
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
203 # Format sequence
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
204 if "ORIGIN" in sequence:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
205 origin_block = sequence.strip()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
206 else:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
207 formatted_sequence = "ORIGIN\n"
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
208 seq_str = str(record.seq)
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
209 for i in range(0, len(seq_str), 60):
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
210 line_seq = seq_str[i:i + 60]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
211 formatted_sequence += f"{str(i + 1).rjust(9)} { ' '.join([line_seq[j:j+10] for j in range(0, len(line_seq), 10)]) }\n"
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
212 origin_block = formatted_sequence.strip()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
213
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
214 # Extract FEATURES section
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
215 features_section = ""
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
216 features_start = annotation.find("FEATURES")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
217 if features_start != -1:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
218 features_section = annotation[features_start:]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
219
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
220 # Write GenBank file
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
221 if not os.path.exists(output):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
222 os.makedirs(output)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
223
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
224 gb_filename = os.path.join(output, f"{fragment_id}.gb")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
225 with open(gb_filename, "w") as f:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
226 f.write(locus_line + "\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
227 f.write(f"DEFINITION {record.description}\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
228 f.write(f"ACCESSION {record.id}\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
229 f.write(f"VERSION DB\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
230 f.write(f"KEYWORDS .\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
231 f.write(f"SOURCE .\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
232 f.write(features_section)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
233 f.write(origin_block + "\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
234 f.write("//\n")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
235
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
236 except Exception as e:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
237 print(f"Error saving GenBank files: {e}")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
238 return
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
239
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
240
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
241 def main():
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
242 parser = argparse.ArgumentParser(description="Fetch annotations from PostgreSQL database and save as JSON.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
243 parser.add_argument("--input", required=True, help="Input CSV file")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
244 parser.add_argument("--use_json_paramers", required=True, help="Use parameters from JSON: true/false")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
245 parser.add_argument("--sequence_column", required=False, help="DB column contains sequence for ganbank file")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
246 parser.add_argument("--annotation_columns", required=False, help="DB column contains head for ganbank file")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
247 parser.add_argument("--db_uri", required=False, help="Database URI connection string")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
248 parser.add_argument("--table", required=False, help="Table name in the database")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
249 parser.add_argument("--fragment_column", required=False, help="Fragment column name in the database")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
250 parser.add_argument("--output", required=True, help="Output dir for gb files")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
251 parser.add_argument("--json_conf", required=False, help="JSON config file with DB parameters")
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
252 parser.add_argument("--report", required=True, help="Output report for fragments checking in DB")
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
253 args = parser.parse_args()
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
254
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
255 # get param and chek for json
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
256 config_params = {}
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
257 use_json = args.use_json_paramers == 'true'
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
258 if use_json:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
259 if not args.json_conf:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
260 raise ValueError("You must provide --json_conf when --use_json_paramers is 'true'")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
261 with open(args.json_conf, "r") as f:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
262 config_params = json.load(f)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
263 else:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
264 config_params = {
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
265 "table": args.table,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
266 "sequence_column": args.sequence_column,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
267 "annotation_column": args.annotation_columns,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
268 "fragment_column": args.fragment_column,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
269 "db_uri": args.db_uri,
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
270 }
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
271
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
272 # Extract final resolved parameters
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
273 table = config_params["table"]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
274 sequence_column = config_params["sequence_column"]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
275 annotation_column = config_params["annotation_column"]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
276 fragment_column = config_params["fragment_column"]
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
277 db_uri = fix_db_uri(config_params["db_uri"])
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
278
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
279 # Wait until the database is ready
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
280 db_uri = fix_db_uri(db_uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
281 # db_name = extract_db_name(db_uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
282 # start_postgres_container(db_name)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
283 MAX_RETRIES = 3
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
284 for attempt in range(1, MAX_RETRIES + 1):
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
285 try:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
286 wait_for_db(db_uri)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
287 break # Success
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
288 except Exception as e:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
289 if attempt == MAX_RETRIES:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
290 print(f"Attempt {attempt} failed: Could not connect to database at {db_uri}.")
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
291 raise e
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
292 else:
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
293 time.sleep(2)
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
294
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
295 # Fetch annotations from the database and save as gb
1
54e716c11b71 planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit 98d5e65b8008dbca117b2e0655cfdd54655fac48-dirty
tduigou
parents: 0
diff changeset
296 fetch_annotations(args.input, sequence_column, annotation_column, db_uri, table, fragment_column, args.output, args.report)
0
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
297
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
298 if __name__ == "__main__":
934050a8037e planemo upload for repository https://github.com/brsynth/galaxytools/tree/main/tools commit af45e5e0e81535ab0423b0bcff8b5b220bb9b4d0-dirty
tduigou
parents:
diff changeset
299 main()