Skip to content

Commit

Permalink
Initial setup for element aviti
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjunnebo committed Aug 29, 2024
1 parent 49d11af commit 22bbbcf
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
65 changes: 65 additions & 0 deletions taca/analysis/analysis_element.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Analysis methods for sequencing runs produced by Element instruments."""

import glob
import logging
import os

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L3-L5

Added lines #L3 - L5 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L7-L8

Added lines #L7 - L8 were not covered by tests

logger = logging.getLogger(__name__)

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L10

Added line #L10 was not covered by tests


def run_preprocessing(given_run):

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L13

Added line #L13 was not covered by tests
"""Run demultiplexing in all data directories.
:param str given_run: Process a particular run instead of looking for runs
"""

def _process(run):

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
"""Process a run/flowcell and transfer to analysis server.
:param taca.element.Run run: Run to be processed and transferred
"""
# Check if sequencing is finished. (is the final file there and was it completed OK)
# if sequencing is not done
# Update statusdb?
# return
# else If sequencing finished and demux not started
# Update statusdb
# Get/generate sample sheet
# Start demux
# else if sequencing finished and demux ongoing
# do nothing
# Else if sequencing started and demux finished
# 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
# transfer run to miarka
# remove hidden file if transfer was successful
# Update transfer log
# archive run to nosync
# elif run is being transferred (hidden file exists)
# return
# elif run is already transferred (in transfer log)
# warn that transferred run has not been archived



if given_run:
run = Aviti_Run(run) #TODO: Needs to change if more Element machines are aquired in the future
_process(runObj)

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L49-L51

Added lines #L49 - L51 were not covered by tests
else:
data_dirs = CONFIG.get("element_analysis").get("data_dirs") #TODO: add to config
for data_dir in data_dirs:

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L53-L54

Added lines #L53 - L54 were not covered by tests
# Run folder looks like DATE_*_*_*, the last section is the FC name.
runs = glob.glob(os.path.join(data_dir, "[1-9]*_*_*_*")) #TODO: adapt to aviti format
for run in runs:
runObj = Aviti_Run(run)
try:
_process(runObj)
except: #TODO: chatch error message and print it

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L56-L61

Added lines #L56 - L61 were not covered by tests
# This function might throw and exception,
# it is better to continue processing other runs
logger.warning(f"There was an error processing the run {run}")
pass

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

View check run for this annotation

Codecov / codecov/patch

taca/analysis/analysis_element.py#L64-L65

Added lines #L64 - L65 were not covered by tests
23 changes: 23 additions & 0 deletions taca/analysis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from taca.analysis import analysis as an
from taca.analysis import analysis_nanopore
from taca.analysis import analysis_element

Check warning on line 7 in taca/analysis/cli.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/cli.py#L7

Added line #L7 was not covered by tests


@click.group()
Expand Down Expand Up @@ -71,6 +72,28 @@ def updatedb(rundir, software):
"""Save the run to statusdb."""
an.upload_to_statusdb(rundir, software)

# Element analysis subcommands


@analysis.command()
@click.option(

Check warning on line 79 in taca/analysis/cli.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/cli.py#L78-L79

Added lines #L78 - L79 were not covered by tests
"-r",
"--run",
type=click.Path(exists=True),
default=None,
help="Demultiplex only a particular run",
)
def demultiplex_element(run):

Check warning on line 86 in taca/analysis/cli.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/cli.py#L86

Added line #L86 was not covered by tests
"""Demultiplex and transfer all runs present in the data directories."""
analysis_element.run_preprocessing(run)

Check warning on line 88 in taca/analysis/cli.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/cli.py#L88

Added line #L88 was not covered by tests


@analysis.command()
@click.argument("run")
def element_updatedb(run):

Check warning on line 93 in taca/analysis/cli.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/cli.py#L91-L93

Added lines #L91 - L93 were not covered by tests
"""Save the run to statusdb."""
analysis_element.upload_to_statusdb(run)

Check warning on line 95 in taca/analysis/cli.py

View check run for this annotation

Codecov / codecov/patch

taca/analysis/cli.py#L95

Added line #L95 was not covered by tests


# Nanopore analysis subcommands

Expand Down
7 changes: 7 additions & 0 deletions taca/element/Aviti_Runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from taca.element.Element_Runs import Run

Check warning on line 1 in taca/element/Aviti_Runs.py

View check run for this annotation

Codecov / codecov/patch

taca/element/Aviti_Runs.py#L1

Added line #L1 was not covered by tests


class Aviti_Run(Run):
def __init__(self, run_dir, configuration):
super().__init__(run_dir, configuration)
self.sequencer_type = "Aviti"

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

View check run for this annotation

Codecov / codecov/patch

taca/element/Aviti_Runs.py#L4-L7

Added lines #L4 - L7 were not covered by tests
18 changes: 18 additions & 0 deletions taca/element/Element_Runs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import logging
import os

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

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L1-L2

Added lines #L1 - L2 were not covered by tests

logger = logging.getLogger(__name__)

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#L4

Added line #L4 was not covered by tests


class Run:

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#L7

Added line #L7 was not covered by tests
"""Defines an Element run"""

def __init__(self, run_dir, configuration):
if not os.path.exists(run_dir):
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"

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

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L10-L15

Added lines #L10 - L15 were not covered by tests

def is_transferred(self, transfer_file):
pass

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

View check run for this annotation

Codecov / codecov/patch

taca/element/Element_Runs.py#L17-L18

Added lines #L17 - L18 were not covered by tests
3 changes: 3 additions & 0 deletions taca/element/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Classes to parse and work with Element data
"""

0 comments on commit 22bbbcf

Please sign in to comment.