lib.rs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. use std::sync::{Arc, Mutex};
  2. pub mod commands;
  3. pub mod config;
  4. pub mod modkit;
  5. pub mod callers;
  6. pub mod runners;
  7. pub mod collection;
  8. pub mod functions;
  9. #[macro_use]
  10. extern crate lazy_static;
  11. // Define DOCKER_ID lock for handling Docker kill when ctrlc is pressed
  12. lazy_static! {
  13. static ref DOCKER_ID: Arc<Mutex<Option<String>>> = Arc::new(Mutex::new(None));
  14. }
  15. #[cfg(test)]
  16. mod tests {
  17. use log::info;
  18. use self::{callers::deep_variant::DeepVariantConfig, collection::pod5::{FlowCellCase, Pod5Collection}, commands::dorado, config::Config};
  19. use super::*;
  20. use crate::{callers::{clairs::{ClairS, ClairSConfig}, deep_variant::DeepVariant, nanomonsv::{NanomonSV, NanomonSVConfig}}, collection::{bam::{self, BamType}, run_tasks, variants::VariantsCollection, vcf::VcfCollection, Collections, CollectionsConfig}, commands::{bcftools::{bcftools_keep_pass, BcftoolsConfig}, dorado::Dorado}};
  21. #[test]
  22. fn it_works() {
  23. let bam_path = "/data/longreads_basic_pipe/PARACHINI/diag/PARACHINI_diag_hs1.bam";
  24. modkit::modkit(bam_path);
  25. }
  26. #[test]
  27. fn run_dorado() -> anyhow::Result<()> {
  28. let case = FlowCellCase {
  29. id: "CONSIGNY".to_string(), time_point: "mrd".to_string(), barcode: "07".to_string(), pod_dir: "/data/run_data/20240326-CL/CONSIGNY-MRD-NB07_RICCO-DIAG-NB08/20240326_1355_1E_PAU78333_bc25da25/pod5_pass/barcode07".into() };
  30. dorado::Dorado::init(case, Config::default())?.run_pipe()
  31. }
  32. #[test]
  33. fn pod5() -> anyhow::Result<()> {
  34. let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
  35. .build();
  36. let _ = Pod5Collection::new(
  37. "/data/run_data",
  38. "/data/flow_cells.tsv",
  39. "/data/longreads_basic_pipe",
  40. )?;
  41. // let runs = Runs::import_dir("/home/prom/store/banana-pool/run_data", "/data/flow_cells.tsv")?;
  42. Ok(())
  43. }
  44. #[test_log::test]
  45. fn bam() -> anyhow::Result<()> {
  46. let bam_collection = bam::load_bam_collection("/data/longreads_basic_pipe");
  47. bam_collection
  48. .bams
  49. .iter()
  50. .filter(|b| matches!(b.bam_type, BamType::Panel(_)))
  51. .for_each(|b| println!("{b:#?}"));
  52. let u = bam_collection.get("PARACHINI", "mrd");
  53. println!("{u:#?}");
  54. Ok(())
  55. }
  56. #[test_log::test]
  57. fn vcf() -> anyhow::Result<()> {
  58. let mut vcf_collection = VcfCollection::new("/data/longreads_basic_pipe");
  59. vcf_collection.sort_by_id();
  60. vcf_collection
  61. .vcfs
  62. .iter()
  63. .for_each(|v| v.println().unwrap());
  64. Ok(())
  65. }
  66. #[test_log::test]
  67. fn mux() -> anyhow::Result<()> {
  68. let cases = vec![
  69. FlowCellCase { id: "test_04".to_string(), time_point: "diag".to_string(), barcode: "04".to_string(), pod_dir: "/data/test_d".into() },
  70. FlowCellCase { id: "test_05".to_string(), time_point: "diag".to_string(), barcode: "05".to_string(), pod_dir: "/data/test_d".into() },
  71. ];
  72. Dorado::from_mux(cases, Config::default())
  73. }
  74. #[test_log::test]
  75. fn deep_variant() -> anyhow::Result<()> {
  76. let config = DeepVariantConfig {
  77. result_dir: "/data/test".to_string(),
  78. ..DeepVariantConfig::default()
  79. };
  80. DeepVariant::new("test_a", "diag", "/data/test_data/subset.bam", config).run();
  81. Ok(())
  82. }
  83. #[test_log::test]
  84. fn clairs() -> anyhow::Result<()> {
  85. let config = ClairSConfig {
  86. result_dir: "/data/test".to_string(),
  87. ..ClairSConfig::default()
  88. };
  89. ClairS::new("test_a", "/data/test_data/subset.bam", "/data/test_data/subset_mrd.bam", config).run();
  90. Ok(())
  91. }
  92. #[test_log::test]
  93. fn nanomonsv() -> anyhow::Result<()> {
  94. let config = NanomonSVConfig {
  95. result_dir: "/data/test".to_string(),
  96. ..NanomonSVConfig::default()
  97. };
  98. NanomonSV::new("test_a", "/data/test_data/subset.bam", "/data/test_data/subset_mrd.bam", config).run();
  99. Ok(())
  100. }
  101. // cargo test run -- --nocapture; ~/run_scripts/notify_finish.sh &
  102. #[test_log::test]
  103. fn todo() -> anyhow::Result<()> {
  104. let mut collections = Collections::new(
  105. CollectionsConfig::default()
  106. )?;
  107. info!("Runing todo with config: {:#?}", collections);
  108. collections.todo()?;
  109. println!("{:#?}", collections.tasks);
  110. println!("{}", collections.tasks.len());
  111. Ok(())
  112. }
  113. // export RUST_LOG="debug"
  114. #[test_log::test]
  115. fn run_t() -> anyhow::Result<()> {
  116. run_tasks(CollectionsConfig::default())
  117. }
  118. #[test_log::test]
  119. fn somatic() -> anyhow::Result<()> {
  120. let variants_collection = VariantsCollection::new("/data/longreads_basic_pipe")?;
  121. variants_collection.data.iter().for_each(|v| println!("{}\t{}", v.id, v.path.display()));
  122. Ok(())
  123. }
  124. #[test_log::test]
  125. fn bcftools_pass() {
  126. let config = BcftoolsConfig::default();
  127. let id = "RICCO";
  128. let i = format!("/data/longreads_basic_pipe/{id}/diag/nanomonsv/{id}_diag.nanomonsv.result.vcf");
  129. let o = format!("/data/longreads_basic_pipe/{id}/diag/nanomonsv/{id}_diag_nanomonsv_PASSED.vcf.gz");
  130. bcftools_keep_pass(&i, &o, config).unwrap();
  131. }
  132. #[test_log::test]
  133. fn bam_ok() -> anyhow::Result<()> {
  134. let collections = Collections::new(
  135. CollectionsConfig::default()
  136. )?;
  137. let mut res: Vec<_> = collections.bam.by_id_completed(15.0, 10.0).iter().map(|b| {
  138. (b.id.to_string(), b.time_point.to_string(), b.path.to_str().unwrap().to_string())
  139. }).collect();
  140. res.sort_by_key(|b| b.1.clone());
  141. res.sort_by_key(|b| b.0.clone());
  142. res.iter().for_each(|(id, tp, path)| println!("{id}\t{tp}\t{path}"));
  143. Ok(())
  144. }
  145. #[test_log::test]
  146. fn todo_assembler() -> anyhow::Result<()> {
  147. let mut collections = Collections::new(
  148. CollectionsConfig::default()
  149. )?;
  150. collections.todo_assembler()?;
  151. Ok(())
  152. }
  153. }