Skip to content

Commit

Permalink
Process aviti data from sequencing to demux
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjunnebo committed Aug 29, 2024
1 parent 36dbafd commit d005446
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 16 deletions.
43 changes: 28 additions & 15 deletions taca/analysis/analysis_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@

from taca.element.Element_Runs import Aviti_Run
from taca.utils.config import CONFIG
from taca.utils import statusdb

Check warning on line 9 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L7-L9

Added lines #L7 - L9 were not covered by tests


logger = logging.getLogger(__name__)

Check warning on line 12 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L12

Added line #L12 was not covered by tests

def _upload_to_statusdb(run):

Check warning on line 14 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L14

Added line #L14 was not covered by tests
"""Triggers the upload to statusdb.
:param Run run: the object run
"""
pass

Check warning on line 19 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L19

Added line #L19 was not covered by tests

def run_preprocessing(given_run):

Check warning on line 21 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L21

Added line #L21 was not covered by tests
"""Run demultiplexing in all data directories.
Expand All @@ -21,21 +29,26 @@ def _process(run):
:param taca.element.Run run: Run to be processed and transferred
"""
# Fetch statusdb document for run

# Get previous status of run from statusdb document
# Check if sequencing is finished. (is the final file there and was it completed OK)
# if sequencing is not done
# compare previous status with current status and update statusdb document if different
# return
# else if sequencing finished and demux not started
# Get/generate sample sheet
#TODO: Fetch statusdb document for run
#TODO: Get previous status of run from statusdb document
sequencing_done = run.check_sequencing_status()
demultiplexing_status = run.get_demultiplexing_status()
if not sequencing_done:

Check warning on line 36 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L34-L36

Added lines #L34 - L36 were not covered by tests
#TODO: compare previous status with current status and update statusdb document if different
return
elif sequencing_done and demultiplexing_status == "not started":
if not run.manifest_exists(): # Assumes that we use the same manifest as for sequencing. TODO: demux settings need to be added to the original manifest by lims

Check warning on line 40 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L38-L40

Added lines #L38 - L40 were not covered by tests
#TODO: email operator that manifest is missing
return

Check warning on line 42 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L42

Added line #L42 was not covered by tests
# Start demux
# compare previous status with current status and update statusdb document if different
# else if sequencing finished and demux ongoing
# compare previous status with current status and update statusdb document if different
# return
# Else if sequencing started and demux finished
run.start_demux()

Check warning on line 44 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L44

Added line #L44 was not covered by tests
#TODO: compare previous status with current status and update statusdb document if different
return
elif sequencing_done and demultiplexing_status == "ongoing":

Check warning on line 47 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L46-L47

Added lines #L46 - L47 were not covered by tests
#TODO: compare previous status with current status and update statusdb document if different
return
elif sequencing_done and demultiplexing_status == "finished":

Check warning on line 50 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L49-L50

Added lines #L49 - L50 were not covered by tests
# Sync metadata to ngi-data-ns
# check if run is transferred or transfer is ongoing
# if run has not been transferred and transfer is not ongoing
# make a hidden file to indicate that transfer has started
Expand All @@ -53,7 +66,7 @@ def _process(run):
# elif run is already transferred (in transfer log)
# compare previous status with current status and update statusdb document if different
# warn that transferred run has not been archived

pass

Check warning on line 69 in taca/analysis/analysis_element.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L69

Added line #L69 was not covered by tests


if given_run:
Expand Down
51 changes: 50 additions & 1 deletion taca/element/Element_Runs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import logging
import os
import json
from datetime import datetime

Check warning on line 4 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L1-L4

Added lines #L1 - L4 were not covered by tests

from taca.utils import misc
from taca.utils.filesystem import chdir

Check warning on line 7 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L6-L7

Added lines #L6 - L7 were not covered by tests

logger = logging.getLogger(__name__)

Check warning on line 9 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L9

Added line #L9 was not covered by tests

Expand All @@ -12,7 +17,51 @@ def __init__(self, run_dir, configuration):
raise RuntimeError(f"Could not locate run directory {run_dir}")
self.run_dir = os.path.abspath(run_dir)
self.CONFIG = configuration
self.demux_dir = "Demultiplexing"
self.demux_dir = os.path.join(self.run_dir, "Demultiplexing")
self.final_sequencing_file = os.path.join(self.run_dir, "RunUploaded.json")
self.demux_stats_file = os.path.join(self.demux_dir, "RunStats.json") #TODO: How to handle SideA/SideB?
self.run_manifest_file = os.path.join(self.run_dir, "RunManifest.csv")

Check warning on line 23 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L15-L23

Added lines #L15 - L23 were not covered by tests

def check_sequencing_status(self):
if os.path.exists(self.final_sequencing_file):
with open(self.final_sequencing_file) as json_file:
sequencing_outcome = json.load(json_file).get("outcome")
if sequencing_outcome != "OutcomeCompleted":
return False

Check warning on line 30 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L25-L30

Added lines #L25 - L30 were not covered by tests
else:
return True

Check warning on line 32 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L32

Added line #L32 was not covered by tests
else:
return False

Check warning on line 34 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L34

Added line #L34 was not covered by tests

def get_demultiplexing_status(self):
if not os.path.exists(self.demux_dir):
return "not started"
elif os.path.exists(self.demux_dir) and not os.path.isfile(self.demux_stats_file):
return "ongoing"
elif os.path.exists(self.demux_dir) and os.path.isfile(self.demux_stats_file):
return "finished"

Check warning on line 42 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L36-L42

Added lines #L36 - L42 were not covered by tests

def manifest_exists(self):
return os.path.isfile(self.run_manifest_file)

Check warning on line 45 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L44-L45

Added lines #L44 - L45 were not covered by tests

def generate_demux_command(self):
command = [self.CONFIG.get(self.software)["bin"], #TODO add path to bases2fastq executable to config

Check warning on line 48 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L47-L48

Added lines #L47 - L48 were not covered by tests
self.run_dir,
self.demux_dir, #TODO: how to handle SideA/SideB?
"-p 12"
]
return command

Check warning on line 53 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L53

Added line #L53 was not covered by tests

def start_demux(self):
with chdir(self.run_dir):
cmd = self.generate_demux_command()
misc.call_external_command_detached(

Check warning on line 58 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L55-L58

Added lines #L55 - L58 were not covered by tests
cmd, with_log_files=True, prefix=f"demux_"
)
logger.info(

Check warning on line 61 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L61

Added line #L61 was not covered by tests
"Bases2Fastq conversion and demultiplexing "
f"started for run {os.path.basename(self.id)} on {datetime.now()}"
)

def is_transferred(self, transfer_file):
pass

Check warning on line 67 in taca/element/Element_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L66-L67

Added lines #L66 - L67 were not covered by tests
Expand Down

0 comments on commit d005446

Please sign in to comment.