Skip to content

Commit

Permalink
Add tests for validate_fasta and validate_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieing committed Sep 17, 2024
1 parent 78ec274 commit 41cee45
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 37 deletions.
74 changes: 38 additions & 36 deletions src/yaml_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,20 @@ pub mod yaml_validator_mod {
}
}

#[derive(Debug, Serialize, Deserialize)]
struct TreeValYaml {
assembly: Assembly,
reference_file: String,
map_order: String,
assem_reads: AssemReads,
hic_data: HicReads,
kmer_profile: KmerProfile,
alignment: Alignment,
self_comp: SelfComp,
intron: Intron,
telomere: Telomere,
synteny: Synteny,
busco: Busco,
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct TreeValYaml {
pub assembly: Assembly,
pub reference_file: String,
pub map_order: String,
pub assem_reads: AssemReads,
pub hic_data: HicReads,
pub kmer_profile: KmerProfile,
pub alignment: Alignment,
pub self_comp: SelfComp,
pub intron: Intron,
pub telomere: Telomere,
pub synteny: Synteny,
pub busco: Busco,
}

/// Struct functions
Expand All @@ -229,7 +229,8 @@ pub mod yaml_validator_mod {

#[allow(dead_code)]
/// Validate that the input fasta is infact a fasta format and count records.
fn validate_fasta(&self) -> String {
/// is this checking it is a fasta format or just that it has records?
pub fn validate_fasta(&self) -> String {
let reader = fasta::reader::Builder.build_from_path(&self.reference_file);

let mut binding = reader.expect("NO VALID HEADER / SEQUENCE PAIRS");
Expand All @@ -242,7 +243,8 @@ pub mod yaml_validator_mod {
}
}

fn validate_csv(&self, csv_path: &String) -> String {
/// Are there standard functions to do this?
pub fn validate_csv(&self, csv_path: &String) -> String {
let file = File::open(csv_path);

match file {
Expand Down Expand Up @@ -352,16 +354,16 @@ pub mod yaml_validator_mod {
}
}

#[derive(Debug, Serialize, Deserialize)]
struct KmerProfile {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct KmerProfile {
kmer_length: u16,
dir: String,
}

impl KmerProfile {}

#[derive(Debug, Serialize, Deserialize)]
struct HicReads {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct HicReads {
hic_cram: String,
hic_aligner: String,
}
Expand Down Expand Up @@ -478,17 +480,17 @@ pub mod yaml_validator_mod {
}
}

#[derive(Debug, Serialize, Deserialize)]
struct Assembly {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Assembly {
sample_id: String, // Anything the user wants
latin_name: String, // Not in use but maybe in future, how to validate a latin name. Api call with a fallback to yes... it is alphabetical
defined_class: String,
assem_version: u8, // Any number
project_id: String, // Can be anything the user wants, not in use
}

#[derive(Debug, Serialize, Deserialize)]
struct AssemReads {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct AssemReads {
read_type: String,
read_data: String,
supplementary_data: String, // Not yet in use
Expand Down Expand Up @@ -523,26 +525,26 @@ pub mod yaml_validator_mod {
}
}

#[derive(Debug, Serialize, Deserialize)]
struct Alignment {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Alignment {
data_dir: String,
common_name: String, // Not yet in use
geneset_id: String,
}

#[derive(Debug, Serialize, Deserialize)]
struct SelfComp {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct SelfComp {
motif_len: u16,
mummer_chunk: u16,
}

#[derive(Debug, Serialize, Deserialize)]
struct Intron {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Intron {
size: String,
}

#[derive(Debug, Serialize, Deserialize)]
struct Telomere {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Telomere {
teloseq: String,
}

Expand All @@ -560,14 +562,14 @@ pub mod yaml_validator_mod {
}
}

#[derive(Debug, Serialize, Deserialize)]
struct Synteny {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Synteny {
synteny_path: String,
synteny_genomes: String,
}

#[derive(Debug, Serialize, Deserialize)]
struct Busco {
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct Busco {
lineages_path: String,
lineage: String,
}
Expand Down
Empty file.
2 changes: 2 additions & 0 deletions test_data/iyAndFlav1/tiny/valid_csv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a,b,c,d
1,2,3,4
36 changes: 35 additions & 1 deletion tests/yaml_validator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use fasta_manipulation::yaml_validator_mod::{
get_file_list, validate_paths, CRAMtags, YamlResults,
get_file_list, validate_paths, CRAMtags, TreeValYaml, YamlResults,
};
use std::path::PathBuf;

Expand Down Expand Up @@ -181,3 +181,37 @@ fn check_check_secondaries_for_fails_and_nos() {
assert_eq!(failures[1], "NO");
assert_eq!(*failures.last().unwrap(), "FAIL");
}

#[test]
fn check_validate_fasta() {
let tree_val_yaml = TreeValYaml {
reference_file: "test_data/iyAndFlav1/tiny/tiny_test.fa".to_string(),
..Default::default()
};

assert!(tree_val_yaml.validate_fasta().contains("PASS"));

let tree_val_yaml = TreeValYaml {
reference_file: "test_data/iyAndFlav1/tiny/empty_file.txt".to_string(),
..Default::default()
};
assert!(tree_val_yaml.validate_fasta().contains("FAIL"));
}

#[test]
fn check_validate_csv() {
let tree_val_yaml = TreeValYaml {
..Default::default()
};

assert!(tree_val_yaml
.validate_csv(&"test_data/iyAndFlav1/tiny/valid_csv.csv".to_string())
.contains("PASS"));

let tree_val_yaml = TreeValYaml {
..Default::default()
};
assert!(tree_val_yaml
.validate_csv(&"test_data/iyAndFlav1/tiny/empty_file.csv".to_string())
.contains("FAIL"));
}

0 comments on commit 41cee45

Please sign in to comment.