Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTX-4247: Created a bioinformatics folder, moved the qiime2 folder th… #29

Merged
merged 6 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from typing import List, Optional
from pathlib import Path
from typing import Optional

import subprocess
import logging
from .utils import compressGzip, createSample, getDemuxSamples, getDenoisedSamples, \
getFastqDPSamples, getFastqMPSamples, getMetadataSample, getPhylogeneticTreeSamples, \
isDemultiplexedSample, isDenoisedSample, isFastqDPSample, isFastqMPSample, \
isMetadataSample, isPhylogeneticTreeSample, sampleNumber


class QiimeCommandException(Exception):
pass


def logProcessOutput(output: bytes, severity: int) -> None:
decoded = output.decode("UTF-8")

for line in decoded.split("\n"):
# skip empty lines
if line.strip() == "":
continue

# ignoring type for now, has to be fixed in coretexpylib
logging.getLogger("coretexpylib").log(severity, line)


def QiimeCommand(args: List[str]) -> None:
process = subprocess.Popen(
args,
shell = False,
cwd = Path(__file__).parent,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)

stdout, stderr = process.communicate()

if len(stdout) > 0:
logProcessOutput(stdout, logging.INFO)

if len(stderr) > 0:
severity = logging.CRITICAL
if process.returncode == 0:
severity = logging.WARNING

logProcessOutput(stderr, severity)

if process.returncode != 0:
raise QiimeCommandException
from ..utils import command


def toolsImport(
Expand All @@ -82,7 +44,7 @@ def toolsImport(
"--input-format" , inputFormat
])

QiimeCommand(args)
command(args)


def demuxEmpSingle(
Expand All @@ -93,7 +55,7 @@ def demuxEmpSingle(
errorCorretctionDetailsPath: str
) -> None:

QiimeCommand([
command([
"qiime", "demux", "emp-single",
"--i-seqs", sequencesPath,
"--m-barcodes-file", barcodesPath,
Expand All @@ -105,7 +67,7 @@ def demuxEmpSingle(


def demuxSummarize(dataPath: str, visualizationPath: str) -> None:
QiimeCommand([
command([
"qiime", "demux", "summarize",
"--i-data", dataPath,
"--o-visualization", visualizationPath
Expand All @@ -121,7 +83,7 @@ def dada2DenoiseSingle(
denoisingStatsPath: str
) -> None:

QiimeCommand([
command([
"qiime", "dada2", "denoise-single",
"--i-demultiplexed-seqs", inputPath,
"--p-trim-left", str(trimLeft),
Expand All @@ -133,15 +95,15 @@ def dada2DenoiseSingle(


def metadataTabulate(inputFile: str, visualizationPath: str) -> None:
QiimeCommand([
command([
"qiime", "metadata", "tabulate",
"--m-input-file", inputFile,
"--o-visualization", visualizationPath
])


def featureTableSummarize(inputPath: str, visualizationPath: str, metadataPath: str) -> None:
QiimeCommand([
command([
"qiime", "feature-table", "summarize",
"--i-table", inputPath,
"--o-visualization", visualizationPath,
Expand All @@ -150,7 +112,7 @@ def featureTableSummarize(inputPath: str, visualizationPath: str, metadataPath:


def featureTableTabulateSeqs(inputPath: str, visualizationPath: str) -> None:
QiimeCommand([
command([
"qiime", "feature-table", "tabulate-seqs",
"--i-data", inputPath,
"--o-visualization", visualizationPath
Expand All @@ -165,7 +127,7 @@ def phylogenyAlignToTreeMafftFasttree(
rootedTreePath: str
) -> None:

QiimeCommand([
command([
"qiime", "phylogeny", "align-to-tree-mafft-fasttree",
"--i-sequences", sequencesPath,
"--o-alignment", aligmentPath,
Expand All @@ -183,7 +145,7 @@ def diversityCoreMetricsPhylogenetic(
outputDir: str
) -> None:

QiimeCommand([
command([
"qiime", "diversity", "core-metrics-phylogenetic",
"--i-phylogeny", phlogenyPath,
"--i-table", tablePath,
Expand All @@ -199,7 +161,7 @@ def diversityAlphaGroupSignificance(
visualizationPath: str
) -> None:

QiimeCommand([
command([
"qiime", "diversity", "alpha-group-significance",
"--i-alpha-diversity", alphaDiversityPath,
"--m-metadata-file", metadataPath,
Expand All @@ -215,7 +177,7 @@ def diversityBetaGroupSignificance(
pairwise: bool
) -> None:

QiimeCommand([
command([
"qiime", "diversity", "beta-group-significance",
"--i-distance-matrix", distanceMatrixPath,
"--m-metadata-file", metadataPath,
Expand All @@ -232,7 +194,7 @@ def emperorPlot(
visualizationPath: str
) -> None:

QiimeCommand([
command([
"qiime", "emperor", "plot",
"--i-pcoa", pcoaPath,
"--m-metadata-file", metadataPath,
Expand All @@ -249,7 +211,7 @@ def diversityAlphaRarefaction(
visualizationPath: str
) -> None:

QiimeCommand([
command([
"qiime", "diversity", "alpha-rarefaction",
"--i-table", tablePath,
"--i-phylogeny", phylogenyPath,
Expand All @@ -265,7 +227,7 @@ def featureClassifierClassifySklearn(
classificationPath: str
) -> None:

QiimeCommand([
command([
"qiime", "feature-classifier", "classify-sklearn",
"--i-classifier", classifierPath,
"--i-reads", readsPath,
Expand All @@ -280,7 +242,7 @@ def taxaBarplot(
visualizationPath: str
) -> None:

QiimeCommand([
command([
"qiime", "taxa", "barplot",
"--i-table", tablePath,
"--i-taxonomy", taxonomyPath,
Expand All @@ -296,7 +258,7 @@ def featureTableFilterSamples(
filteredTablePath: str
) -> None:

QiimeCommand([
command([
"qiime", "feature-table", "filter-samples",
"--i-table", tablePath,
"--m-metadata-file", metadataPath,
Expand All @@ -306,7 +268,7 @@ def featureTableFilterSamples(


def compositionAddPseudocount(tablePath: str, compositionTablePath: str) -> None:
QiimeCommand([
command([
"qiime", "composition", "add-pseudocount",
"--i-table", tablePath,
"--o-composition-table", compositionTablePath
Expand All @@ -320,7 +282,7 @@ def compositionAncom(
visualizationPath: str
) -> None:

QiimeCommand([
command([
"qiime", "composition", "ancom",
"--i-table", tablePath,
"--m-metadata-file", metadataPath,
Expand All @@ -336,7 +298,7 @@ def taxaCollapse(
collapsedTablePath: str
) -> None:

QiimeCommand([
command([
"qiime", "taxa", "collapse",
"--i-table", tablePath,
"--i-taxonomy", taxonomyPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import logging
import gzip

from ..coretex import Experiment, CustomSample, CustomDataset
from ...coretex import Experiment, CustomSample, CustomDataset


def createSample(name: str, datasetId: int, path: Path, experiment: Experiment, stepName: str, retryCount: int = 0) -> CustomSample:
Expand Down
Loading