Skip to content

Commit

Permalink
PIP-883-mirna-template-tech-reps (#38)
Browse files Browse the repository at this point in the history
* update template and add raw fastqs key for mirna
  • Loading branch information
paul-sud authored Jan 24, 2020
1 parent 2cd6877 commit 486ecd9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
7 changes: 2 additions & 5 deletions accession/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from accession import __version__
from accession.accession import accession_factory
from accession.analysis import Analysis, MetaData
from accession.helpers import filter_outputs_by_path


Expand Down Expand Up @@ -75,12 +74,10 @@ def main(args=None):
if args.filter_from_path:
filter_outputs_by_path(args.filter_from_path)
return
metadata = MetaData(args.accession_metadata)
analysis = Analysis(metadata)
connection = Connection(args.server)
if all([args.pipeline_type, analysis, lab, award, connection]):
if all([args.pipeline_type, args.accession_metadata, lab, award, connection]):
accessioner = accession_factory(
args.pipeline_type, analysis, connection, lab, award
args.pipeline_type, args.accession_metadata, connection, lab, award
)
accessioner.accession_steps()
return
Expand Down
26 changes: 19 additions & 7 deletions accession/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path
from typing import Optional, Type

from accession.analysis import Analysis, MetaData
from accession.helpers import string_to_number
from accession.quality_metric import QualityMetric

Expand All @@ -18,19 +19,26 @@ def __init__(self, path_to_accession_step_json):
self._path_to_accession_step_json = path_to_accession_step_json
self._steps = None

def _load_steps(self):
if self._steps:
return
with open(self.path_to_json) as fp:
self._steps = json.load(fp)

@property
def path_to_json(self):
return self._path_to_accession_step_json

@property
def content(self):
if self._steps:
return self._steps["accession.steps"]
else:
with open(self.path_to_json) as fp:
self._steps = json.load(fp)
self._load_steps()
return self._steps["accession.steps"]

@property
def raw_fastqs_keys(self) -> Optional[str]:
self._load_steps()
return self._steps.get("raw_fastqs_keys")


class Accession(ABC):
"""docstring for Accession
Expand Down Expand Up @@ -657,7 +665,9 @@ def make_star_qc_metric(self, encode_bam_file, gs_file):
return self.queue_qc(star_qc_metric, encode_bam_file, "star-quality-metric")


def accession_factory(pipeline_type: str, *args, **kwargs) -> Accession:
def accession_factory(
pipeline_type: str, accession_metadata: str, *args, **kwargs
) -> Accession:
"""
Matches against the user-specified pipeline_type string and returns an instance of
the appropriate accession subclass. Usage of this factory has the nice effect of
Expand All @@ -680,4 +690,6 @@ def accession_factory(pipeline_type: str, *args, **kwargs) -> Accession:
current_dir.parents[1] / "accession_steps" / f"{pipeline_type}_steps.json"
)
accession_steps = AccessionSteps(steps_json_path)
return selected_accession(accession_steps, *args, **kwargs)
metadata = MetaData(accession_metadata)
analysis = Analysis(metadata, raw_fastqs_keys=accession_steps.raw_fastqs_keys)
return selected_accession(accession_steps, analysis, *args, **kwargs)
12 changes: 8 additions & 4 deletions accession/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ class Analysis(object):
Args: metadata: MetaData object
"""

def __init__(self, metadata, auto_populate=True, backend=None):
def __init__(
self, metadata, raw_fastqs_keys=None, auto_populate=True, backend=None
):
self.files = []
self.tasks = []
self.metadata = metadata.content
self.raw_fastqs_keys = raw_fastqs_keys
if self.metadata:
bucket = self.metadata["workflowRoot"].split("gs://")[1].split("/")[0]
if backend is None:
Expand Down Expand Up @@ -130,10 +133,11 @@ def get_files(self, filekey=None, filename=None):
@property
def raw_fastqs(self):
fastqs = []
raw_fastqs_keys = ("fastq", "fastqs")
if self.raw_fastqs_keys is not None:
raw_fastqs_keys = self.raw_fastqs_keys
for file in self.files:
if (
"fastqs" in file.filekeys or "fastq" in file.filekeys
) and file.task is None:
if any([k in file.filekeys for k in raw_fastqs_keys]) and file.task is None:
fastqs.append(file)
return fastqs

Expand Down
7 changes: 5 additions & 2 deletions accession_steps/mirna_steps.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"derived_from_files": [
{
"derived_from_filekey": "fastq",
"derived_from_filekey": "fastqs_to_trim",
"derived_from_inputs": "true",
"derived_from_task": "cutadapt"
},
Expand All @@ -33,7 +33,7 @@
{
"derived_from_files": [
{
"derived_from_filekey": "fastq",
"derived_from_filekey": "fastqs_to_trim",
"derived_from_inputs": "true",
"derived_from_task": "cutadapt"
},
Expand Down Expand Up @@ -110,5 +110,8 @@
],
"wdl_task_name": "wigtobigwig"
}
],
"raw_fastqs_keys": [
"fastqs_to_trim"
]
}

0 comments on commit 486ecd9

Please sign in to comment.