#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Citation {
pub tool: &'static str,
pub text: &'static str,
pub doi: &'static str,
}
impl Citation {
#[must_use]
pub fn render(&self) -> String {
format!("{} doi:{}", self.text, self.doi)
}
}
pub const KNOWN: &[Citation] = &[
Citation {
tool: "minimap2",
text: "Li H (2018) Minimap2: pairwise alignment for nucleotide sequences. \
Bioinformatics 34(18):3094-3100.",
doi: "10.1093/bioinformatics/bty191",
},
Citation {
tool: "samtools",
text: "Danecek P, Bonfield JK, Liddle J, Marshall J, Ohan V, Pollard MO, \
Whitwham A, Keane T, McCarthy SA, Davies RM, Li H (2021) Twelve years \
of SAMtools and BCFtools. GigaScience 10(2):giab008.",
doi: "10.1093/gigascience/giab008",
},
Citation {
tool: "hivdb",
text: "Rhee SY, Gonzales MJ, Kantor R, Betts BJ, Ravela J, Shafer RW (2003) \
Human immunodeficiency virus reverse transcriptase and protease \
sequence database. Nucleic Acids Research 31(1):298-303.",
doi: "10.1093/nar/gkg100",
},
Citation {
tool: "bcftools",
text: "Danecek P, Bonfield JK, Liddle J, Marshall J, Ohan V, Pollard MO, \
Whitwham A, Keane T, McCarthy SA, Davies RM, Li H (2021) Twelve years \
of SAMtools and BCFtools. GigaScience 10(2):giab008.",
doi: "10.1093/gigascience/giab008",
},
Citation {
tool: "rdkit",
text: "Landrum G et al. RDKit: Open-source cheminformatics. \
https://www.rdkit.org",
doi: "10.5281/zenodo.591637",
},
Citation {
tool: "bwa",
text: "Li H (2013) Aligning sequence reads, clone sequences and assembly \
contigs with BWA-MEM. arXiv:1303.3997 [q-bio.GN].",
doi: "10.48550/arXiv.1303.3997",
},
];
pub const ENGINE: &str = "ligase";
#[must_use]
pub fn engine(versions: &[String]) -> String {
let versions = if versions.is_empty() {
crate::version().to_owned()
} else {
versions.join(", ")
};
format!(
"Njeri K. Ligase: dimension-checked, reproducible computational biology \
pipelines (version {versions}). https://github.com/Neoforge-Labs/ligase"
)
}
#[must_use]
pub fn of(tool: &str) -> Option<&'static Citation> {
KNOWN.iter().find(|citation| citation.tool == tool)
}
#[cfg(test)]
mod tests {
#![allow(clippy::expect_used)]
use super::*;
#[test]
fn a_known_tool_has_a_reference_with_a_doi() {
let citation = of("minimap2").expect("minimap2 is in the table");
assert!(citation.text.contains("Li H"));
assert!(
citation
.render()
.contains("doi:10.1093/bioinformatics/bty191")
);
}
#[test]
fn samtools_and_bcftools_share_their_paper() {
let samtools = of("samtools").expect("in the table");
let bcftools = of("bcftools").expect("in the table");
assert_eq!(samtools.doi, bcftools.doi);
}
#[test]
fn the_aligner_a_library_step_runs_is_the_one_cited() {
let citation = of("bwa").expect("bwa is in the table");
assert!(
citation.text.contains("BWA-MEM"),
"`ligase.steps.bwa.mem` runs BWA-MEM, and that is the algorithm \
bwa asks to be cited for: {}",
citation.text
);
assert!(citation.render().contains("doi:10.48550/arXiv.1303.3997"));
}
#[test]
fn a_library_is_cited_for_the_software_it_is_rather_than_a_paper() {
let citation = of("rdkit").expect("rdkit is in the table");
assert!(citation.text.contains("rdkit.org"), "{}", citation.text);
assert!(citation.render().contains("doi:10.5281/zenodo.591637"));
}
#[test]
fn every_library_the_engine_knows_can_be_credited() {
for tool in crate::exec::LIBRARY {
assert!(
of(tool).is_some(),
"`{tool}` is a library tool with no reference to give"
);
}
}
#[test]
fn every_reference_carries_a_doi() {
for citation in KNOWN {
assert!(
citation.doi.starts_with("10."),
"{} has no resolvable DOI",
citation.tool
);
}
}
#[test]
fn the_engine_is_cited_for_the_version_that_ran() {
let reference = engine(&["0.3.0".to_owned()]);
assert!(reference.contains("Ligase"), "{reference}");
assert!(reference.contains("version 0.3.0"), "{reference}");
assert!(
reference.contains("https://github.com/Neoforge-Labs/ligase"),
"{reference}"
);
assert!(!reference.contains("doi:"), "{reference}");
}
#[test]
fn a_run_that_spanned_two_engine_versions_names_both() {
let reference = engine(&["0.3.0".to_owned(), "0.4.0".to_owned()]);
assert!(reference.contains("0.3.0"), "{reference}");
assert!(reference.contains("0.4.0"), "{reference}");
}
#[test]
fn the_engine_falls_back_to_this_build_when_a_run_recorded_nothing() {
let reference = engine(&[]);
assert!(reference.contains(crate::version()), "{reference}");
}
#[test]
fn an_unknown_tool_has_no_reference() {
assert!(
of("minimap3").is_none(),
"the engine does not invent a reference from a name"
);
}
}