Skip to content

Commit

Permalink
chore(dev): skip missing remap vircov pd
Browse files Browse the repository at this point in the history
  • Loading branch information
esteinig committed Dec 15, 2024
1 parent 9598112 commit b56191b
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 117 deletions.
24 changes: 11 additions & 13 deletions app/src/lib/components/data/sample/cards/InternalControls.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import '@carbon/charts-svelte/styles.css'
import { BarChartSimple, ChartTheme, ScaleTypes } from '@carbon/charts-svelte';
import type { OrganismControl, Cerebro } from '$lib/utils/types';
Expand Down Expand Up @@ -59,6 +60,7 @@
grid: {
y: { enabled: false },
x: { enabled: false },
backgroundColor: "transparent"
},
axes: {
left: {
Expand Down Expand Up @@ -92,7 +94,11 @@
<p class="text-xs opacity-60 flex justify-start pb-8">
<span>Internal control coverage</span>
</p>
<BarChartSimple data={organismControlData} options={barChartOptions} />

<div class="qc-internal-controls">
<BarChartSimple data={organismControlData} options={barChartOptions} />
</div>

{:else}
<div class="flex justify-center">
<p class="text-sm opacity-60 pt-24">No organism control data available</p>
Expand All @@ -101,17 +107,9 @@
</div>


<!--
Overwrite the root variable that is responsible
for setting the background colors of the Carbon
plot - there is probably a way to adjust these
to the Skeleton UI / Tailwind color scheme
variables but it is eluding me...
-->
<style lang="postcss">
:root {
--cds-grid-bg: rgb(0, 0, 0, 0);
/* Scoped globally but applied only within this component */
:global(.qc-internal-controls .chart-grid-backdrop) {
display: none;
}
</style>

<link rel="stylesheet" href="/carbon.css">
</style>
16 changes: 5 additions & 11 deletions app/src/lib/components/data/sample/cards/ReadQuality.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import '@carbon/charts-svelte/styles.css'
import { MeterChart, ChartTheme } from '@carbon/charts-svelte'
import { Statuses } from '@carbon/charts';
import { type Cerebro } from '$lib/utils/types';
Expand Down Expand Up @@ -220,24 +221,17 @@
</div>

<style lang="postcss">
:root {
--cds-grid-bg: rgba(0, 0, 0, 0);
}
.qc-meter-chart {
--cds-grid-bg: rgba(0, 0, 0, 0.1); /* Set desired background */
}
/* Scoped globally but applied only within this component */
:global(.proportional-meter-total) {
:global(.qc-meter-chart .proportional-meter-total) {
display: none;
}
/* Scoped globally but applied only within this component */
:global(.proportional-meter-title) {
:global(.qc-meter-chart .proportional-meter-title) {
display: none;
}
/* Scoped globally but applied only within this component */
:global(.status-indicator) {
:global(.qc-meter-chart .status-indicator) {
display: none;
}
</style>

<link rel="stylesheet" href="/carbon.css">

20 changes: 9 additions & 11 deletions app/src/lib/components/data/sample/cards/SyntheticControls.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import '@carbon/charts-svelte/styles.css'
import { ERCC_CONCENTRATIONS, ERCC_GROUPS, getCssVariableAsHex } from "$lib/utils/helpers";
import type { Cerebro, ErccControl } from "$lib/utils/types";
import { sampleCorrelation } from "simple-statistics";
Expand Down Expand Up @@ -156,7 +157,9 @@
<span class="ml-5 text-xs opacity-40">r<sup>2</sup><sub>C</sub> = {groupCoefficients.C.toFixed(4)}</span>
<span class="ml-5 text-xs opacity-40">r<sup>2</sup><sub>D</sub> = {groupCoefficients.D.toFixed(4)}</span>
</p>
<ScatterChart data={correlationData} options={correlationPlotOptions}></ScatterChart>
<div class="qc-ercc-chart">
<ScatterChart data={correlationData} options={correlationPlotOptions}></ScatterChart>
</div>

{:else}
<div class="flex justify-center">
Expand All @@ -168,15 +171,10 @@

</div>

<!--
Overwrite the root variable that is responsible
for setting the background colors of the Carbon
plot - there is probably a way to adjust these
to the Skeleton UI / Tailwind color scheme
variables but it is eluding me...
-->

<style lang="postcss">
:root {
--cds-grid-bg: rgb(0, 0, 0, 0);
}
/* Scoped globally but applied only within this component */
:global(.qc-ercc-chart .chart-grid-backdrop) {
display: none;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,13 @@
<label class="label">
<span class="font-medium mb-2">Read classifier</span>
<select bind:value={tool} class="select">
<option value="{PathogenDetectionTool.Ganon2}">{PathogenDetectionTool.Ganon2}</option>
<option value="{PathogenDetectionTool.Kraken2}">{PathogenDetectionTool.Kraken2}</option>
<option value="{PathogenDetectionTool.Ganon2}">{PathogenDetectionTool.Ganon2}</option>
<option value="{PathogenDetectionTool.Bracken}">{PathogenDetectionTool.Bracken}</option>
<option value="{PathogenDetectionTool.Metabuli}">{PathogenDetectionTool.Metabuli}</option>
<option value="{PathogenDetectionTool.Kmcp}">{PathogenDetectionTool.Kmcp}</option>
<option value="{PathogenDetectionTool.Sylph}">{PathogenDetectionTool.Sylph}</option>
<option value="{PathogenDetectionTool.Vircov}">{PathogenDetectionTool.Vircov}</option>
</select>
</label>

Expand Down
2 changes: 1 addition & 1 deletion cerebro/stack/client/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use cerebro_client::utils::init_logger;
use cerebro_client::client::CerebroClient;
use cerebro_client::terminal::{TowerCommands, ProjectCommands, StageCommands, WatcherCommands, App, Commands};

// use cerebro_pipe::sample::WorkflowSample;
use cerebro_model::api::cerebro::model::Cerebro;
use cerebro_pipe::taxa::taxon::TaxonExtraction;

fn main() -> anyhow::Result<()> {

Expand Down
55 changes: 32 additions & 23 deletions cerebro/stack/pipe/src/modules/panviral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use taxonomy::ncbi;
use vircov::vircov::VircovRecord;

use crate::{error::WorkflowError, nextflow::panviral::PanviralOutput, taxa::taxon::Taxon, utils::read_tsv};
use crate::{error::WorkflowError, nextflow::panviral::PanviralOutput, taxa::taxon::{Taxon, TaxonExtraction}, utils::read_tsv};

use super::quality::QualityControl;

Expand Down Expand Up @@ -46,36 +46,45 @@ impl Panviral {
let pathogen = serde_json::from_reader(reader)?;
Ok(pathogen)
}
// Uses the provided taxonomy to create the taxon structs for the database model
pub fn get_taxa(&self, taxonomy_directory: &PathBuf, strict: bool) -> Result<HashMap<String, Taxon>, WorkflowError> {
}

impl TaxonExtraction for Panviral {
fn get_taxa(&self, taxonomy_directory: &PathBuf, strict: bool) -> Result<HashMap<String, Taxon>, WorkflowError> {
let taxonomy = ncbi::load(taxonomy_directory)?;

let mut taxa = HashMap::new();
let mut taxa: HashMap<String, Taxon> = HashMap::new();
for record in &self.records {

let taxid = match &record.taxid {
None => {
log::error!("Taxid not found for record with reference sequence: {}", record.reference);
return Err(WorkflowError::PanviralTaxidAnnotationMissing)
},
Some(taxid) => taxid
};

let mut taxon = match Taxon::from_taxid(taxid.clone(), &taxonomy, true) {
Err(err) => {
log::error!("Failed to find taxid '{}' in provided taxonomy", taxid);
if strict {
return Err(err)
} else {
log::warn!("Strict mode is not enabled - detection of taxid '{}' will be skipped", taxid);
continue;
}
return Err(WorkflowError::PanviralTaxidAnnotationMissing);
},
Ok(taxon) => taxon,
Some(taxid) => taxid,
};
taxon.evidence.alignment.push(record.clone());
taxa.insert(taxid.clone(), taxon);

if let Some(existing_taxon) = taxa.get_mut(taxid) {
// If the taxid is already present, update its evidence
existing_taxon.evidence.alignment.push(record.clone());
} else {
// Otherwise, create a new Taxon and insert it into the HashMap
let mut taxon = match Taxon::from_taxid(taxid.clone(), &taxonomy, true) {
Err(err) => {
log::error!("Failed to find taxid '{}' in provided taxonomy", taxid);
if strict {
return Err(err);
} else {
log::warn!(
"Strict mode is not enabled - detection of taxid '{}' will be skipped",
taxid
);
continue;
}
},
Ok(taxon) => taxon,
};
taxon.evidence.alignment.push(record.clone());
taxa.insert(taxid.clone(), taxon);
}
}
Ok(taxa)
}
Expand Down
67 changes: 37 additions & 30 deletions cerebro/stack/pipe/src/modules/pathogen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{collections::HashMap, fs::File, io::{BufReader, BufWriter}, path::{Pat
use serde::{Deserialize, Serialize};
use taxonomy::{ncbi, GeneralTaxonomy, TaxRank, Taxonomy};

use crate::{error::WorkflowError, nextflow::pathogen::{PathogenOutput, SylphReportRecord}, taxa::taxon::Taxon, utils::{read_tsv, write_tsv}};
use crate::{error::WorkflowError, nextflow::pathogen::{PathogenOutput, SylphReportRecord}, taxa::taxon::{Taxon, TaxonExtraction}, utils::{read_tsv, write_tsv}};

use super::quality::QualityControl;

Expand Down Expand Up @@ -273,7 +273,7 @@ impl PathogenDetection {

let remap_reads = match record.remap_alignments {
Some(reads) => reads,
None => return Err(WorkflowError::PathogenRemapDataMissing)
None => continue // remapping stage unsuccessful - can occur when very few reads detectec in scanning stage
};


Expand Down Expand Up @@ -543,34 +543,6 @@ impl PathogenDetection {
.cloned()
.collect()
}
// Uses the provided taxonomy to create the taxon structs for the database model
pub fn get_taxa(&self, taxonomy_directory: &PathBuf, strict: bool) -> Result<HashMap<String, Taxon>, WorkflowError> {

let taxonomy = ncbi::load(taxonomy_directory)?;

let mut taxa = HashMap::new();

// Pathogen detection records
for record in &self.records {

let mut taxon = match Taxon::from_taxid(record.taxid.clone(), &taxonomy, true) {
Ok(taxon) => taxon,
Err(err) => {
log::error!("Failed to find taxid '{}' in provided taxonomy", record.taxid);
if strict {
return Err(err)
} else {
log::warn!("Strict mode is not enabled - detection of taxid '{}' will be skipped", record.taxid);
continue;
}
}
};
taxon.evidence.records.push(record.clone());
taxa.insert(record.taxid.clone(), taxon);
}

Ok(taxa)
}
pub fn write_records(records: &Vec<PathogenDetectionRecord>, path: &Path) -> Result<(), WorkflowError> {
write_tsv(&records, path, true)
}
Expand Down Expand Up @@ -599,6 +571,41 @@ impl PathogenDetection {
}
}

impl TaxonExtraction for PathogenDetection {
fn get_taxa(&self, taxonomy_directory: &PathBuf, strict: bool) -> Result<HashMap<String, Taxon>, WorkflowError> {
let taxonomy = ncbi::load(taxonomy_directory)?;

let mut taxa: HashMap<String, Taxon> = HashMap::new();
for record in &self.records {

if let Some(existing_taxon) = taxa.get_mut(&record.taxid) {
// If the taxid is already present, update its evidence
existing_taxon.evidence.records.push(record.clone());
} else {
// Otherwise, create a new Taxon and insert it into the HashMap
let mut taxon = match Taxon::from_taxid(record.taxid.clone(), &taxonomy, true) {
Err(err) => {
log::error!("Failed to find taxid '{}' in provided taxonomy", &record.taxid);
if strict {
return Err(err);
} else {
log::warn!(
"Strict mode is not enabled - detection of taxid '{}' will be skipped",
record.taxid
);
continue;
}
},
Ok(taxon) => taxon,
};
taxon.evidence.records.push(record.clone());
taxa.insert(record.taxid.clone(), taxon);
}
}
Ok(taxa)
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, clap::ValueEnum)]
pub enum PathogenDetectionRank {
Superkingdom,
Expand Down
4 changes: 4 additions & 0 deletions cerebro/stack/pipe/src/taxa/taxon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ use crate::modules::pathogen::{PathogenDetectionRecord, PathogenDetectionResult}
use crate::{error::WorkflowError, utils::get_colored_string};


pub trait TaxonExtraction {
fn get_taxa(&self, taxonomy_directory: &PathBuf, strict: bool) -> Result<HashMap<String, Taxon>, WorkflowError>;
}

fn _get_annotations(taxon: &Taxon, annotations: &Vec<TaxonAnnotations>) -> Option<String> {

let annotation_strings: Vec<String> = annotations.iter().map(|data| {
Expand Down
5 changes: 3 additions & 2 deletions lib/production/utils.nf
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ def getProductionConfig() {
/* Panviral Enrichment */

def getPanviralEnrichmentDatabases() {

return [
panviralEnrichment: getPanviralEnrichmentVirusDatabases(),
qualityControl: getQualityControlDatabases(),
]

}

def getPanviralEnrichmentVirusDatabases() {
Expand All @@ -43,6 +45,7 @@ def getPanviralEnrichmentTaxonomy() {
/* Pathogen Detection */

def getPathogenDetectionDatabases() {

return [
qualityControl: getQualityControlDatabases(),
taxonomicProfile: getTaxonomicProfileDatabases(),
Expand All @@ -67,8 +70,6 @@ def getMetagenomeAssemblyDatabases() {

def magParams = params.pathogenDetection.metagenomeAssembly;

log.info "$params"

return [
ncbiDatabase: magParams.ncbiDatabase ? getPathogenAssemblyNcbiDatabase(magParams) : Channel.empty(),
sylphDatabase: magParams.contigProfile ? getPathogenAssemblySylphDatabase(magParams) : Channel.empty(),
Expand Down
Loading

0 comments on commit b56191b

Please sign in to comment.