Skip to content

Commit

Permalink
attach estimate biomass to api
Browse files Browse the repository at this point in the history
  • Loading branch information
wasade committed Feb 22, 2022
1 parent 559908a commit 85521c4
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
22 changes: 22 additions & 0 deletions q2_katharoseq/_format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import qiime2.plugin.model as model


STATS_HEADER = ['sample-id',
'log_total_reads',
'estimated_biomass_per_pcrrxn',
'estimated_biomass_per_dnarxn',
'extraction_mass_g',
'estimated_cells_per_g',
'log_estimated_cells_per_g']


class EstimatedBiomassFmt(model.TextFileFormat):
def sniff(self):
line = open(str(self)).readline()
hdr = line.strip().split(',')

return hdr == STATS_HEADER


EstimatedBiomassDirFmt = model.SingleFileDirectoryFormat(
'EstimatedBiomassDirFmt', 'est_biomass.csv', EstimatedBiomassFmt)
16 changes: 16 additions & 0 deletions q2_katharoseq/_transformer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd

from .plugin_setup import plugin
from ._format import EstimatedBiomassFmt


@plugin.register_transformer
def _1(data: pd.DataFrame) -> EstimatedBiomassFmt:
ff = EstimatedBiomassFmt()
data.to_csv(str(ff))
return ff


@plugin.register_transformer
def _2(ff: EstimatedBiomassFmt) -> pd.DataFrame:
return pd.read_csv(str(ff), index_col='sample-id')
3 changes: 3 additions & 0 deletions q2_katharoseq/_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from qiime2.plugin import SemanticType

EstimatedBiomass = SemanticType('EstimatedBiomass')
52 changes: 51 additions & 1 deletion q2_katharoseq/plugin_setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import importlib
from qiime2.plugin import (Plugin, Citations, Str, Int,
MetadataColumn, Categorical, Numeric, Choices)
from q2_types.feature_table import (FeatureTable, Frequency)
from . import read_count_threshold
from . import read_count_threshold, estimating_biomass
import q2_katharoseq
from q2_katharoseq._type import EstimatedBiomass
from q2_katharoseq._format import EstimatedBiomassFmt, EstimatedBiomassDirFmt


citations = Citations.load('citations.bib', package='q2_katharoseq')
Expand All @@ -19,6 +22,12 @@
)


plugin.register_formats(EstimatedBiomassFmt, EstimatedBiomassDirFmt)
plugin.register_semantic_types(EstimatedBiomass)
plugin.register_semantic_type_to_format(EstimatedBiomass,
artifact_format=EstimatedBiomassDirFmt)


plugin.visualizers.register_function(
function=read_count_threshold,
inputs={
Expand Down Expand Up @@ -60,3 +69,44 @@
'positive signal in samples with as few as 50 to 500 cells.',
citations=[citations['minich2018']]
)


plugin.methods.register_function(
function=estimating_biomass,
inputs={},
parameters={'total_reads': MetadataColumn[Numeric],
'control_cell_extraction': MetadataColumn[Numeric],
'positive_control_column': MetadataColumn[Categorical],
'positive_control_value': Str,
'extraction_mass_g': MetadataColumn[Categorical],
'min_total_reads': Int,
'pcr_template_vol': Int,
'dna_extract_vol': Int},
outputs=[('estimated_biomass', EstimatedBiomass)],
input_descriptions={},
parameter_descriptions={
'total_reads': 'The total reads present in each sample.',
'control_cell_extraction': 'The number of cells in the controls.',
'positive_control_column': (
'The column in the sample metadata that describes which samples '
'are and are not controls.'),
'positive_control_value': (
'The value in the control column that demarks which samples are '
'the positive controls.'),
'extraction_mass_g': (
'The column in the sample metadata that describes the extraction '
'mass for the controls'),
'min_total_reads': 'The minimum threshold to apply.',
'pcr_template_vol': 'The PCR template volume.',
'dna_extract_vol': 'The DNA extraction volume.'},
output_descriptions={
'estimated_biomass': (
'A dataframe containing the details on estimated biomass')
},
name='Estimate the biomass of samples using KatharoSeq controls.',
description='Estimate the biomass of samples using KatharoSeq controls.',
citations=[]
)


importlib.import_module('q2_katharoseq._transformer')

0 comments on commit 85521c4

Please sign in to comment.