#[cfg(test)] mod testing { use anyhow::Result; use assert_cmd::prelude::*; use bedrs::{Bed3, Coordinates}; use std::process::Command; #[test] fn test_sort_bed3() -> Result<()> { let input = "tests/datasets/sort/unsorted.bed"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd.arg("sort").arg("-i").arg(input).output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row .split('\t') .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(fields[0], fields[1], fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_par_sort_bed3() -> Result<()> { let input = "tests/datasets/sort/unsorted.bed"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("-t") .arg("0") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row .split('\t') .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(fields[0], fields[1], fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_lex_sort_bed3() -> Result<()> { let input = "tests/datasets/sort/unsorted_named.bed"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd.arg("sort").arg("-i").arg(input).arg("-N").output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row .split('\t') .map(|field| field.replace("chr", "")) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(fields[0], fields[1], fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_sort_bed6() -> Result<()> { let input = "tests/datasets/sort/unsorted.bed6"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("--format") .arg("bed6") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 6); let numeric_fields = fields .iter() .take(3) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_par_sort_bed6() -> Result<()> { let input = "tests/datasets/sort/unsorted.bed6"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("-t") .arg("0") .arg("--format") .arg("bed6") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 6); let numeric_fields = fields .iter() .take(3) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_lex_sort_bed6() -> Result<()> { let input = "tests/datasets/sort/unsorted_named.bed6"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("--format") .arg("bed6") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 6); let numeric_fields = fields .iter() .take(3) .map(|field| field.replace("chr", "")) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_lex_sort_bed6_correct_name() -> Result<()> { let input = "tests/datasets/sort/unsorted_named.bed6"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("--format") .arg("bed6") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 6); let numeric_fields = fields .iter() .take(3) .map(|field| field.replace("chr", "")) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; assert_eq!(fields[3], "0"); assert_eq!(fields[4], "0.0"); assert_eq!(fields[5], "+"); } Ok(()) } #[test] fn test_sort_bed12() -> Result<()> { let input = "tests/datasets/sort/unsorted.bed12"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("--format") .arg("bed12") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 12); let numeric_fields = fields .iter() .take(3) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_par_sort_bed12() -> Result<()> { let input = "tests/datasets/sort/unsorted.bed12"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("-t") .arg("0") .arg("--format") .arg("bed12") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 12); let numeric_fields = fields .iter() .take(3) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_lex_sort_bed12() -> Result<()> { let input = "tests/datasets/sort/unsorted_named.bed12"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("--format") .arg("bed12") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 12); let numeric_fields = fields .iter() .take(3) .map(|field| field.replace("chr", "")) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; } Ok(()) } #[test] fn test_lex_sort_bed12_correct_name() -> Result<()> { let input = "tests/datasets/sort/unsorted_named.bed12"; let mut cmd = Command::cargo_bin("gia")?; let output = cmd .arg("sort") .arg("-i") .arg(input) .arg("--format") .arg("bed12") .output()?; let output_str = String::from_utf8(output.stdout)?; let rows = output_str .split('\n') .filter(|row| !row.is_empty()) .collect::>(); let mut last_interval = Bed3::new(0, 0, 0); for row in rows { let fields = row.split('\t').collect::>(); assert_eq!(fields.len(), 12); let numeric_fields = fields .iter() .take(3) .map(|field| field.replace("chr", "")) .map(|field| field.parse::().unwrap()) .collect::>(); let interval = Bed3::new(numeric_fields[0], numeric_fields[1], numeric_fields[2]); assert!(interval.gt(&last_interval) || interval.eq(&last_interval)); last_interval = interval; assert_eq!(fields[3], "0"); assert_eq!(fields[4], "0.0"); assert_eq!(fields[5], "+"); } Ok(()) } }