Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for tpf_fasta #31

Merged
merged 26 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e64a20a
Add tests for check_orientation and get_uniques. publicly expose thin…
stevieing Jun 18, 2024
44c1109
Refactor code to remove extra line and add indent in tests
stevieing Jun 18, 2024
1ebaa8d
Add test for get_subset_of_tpfs
stevieing Jun 18, 2024
8377ad2
Adding tests for tpf_fasta.parse_seq
dasunpubudumal Jul 2, 2024
20b024a
Add tests for tpf_fasta.parse_seq
dasunpubudumal Jul 2, 2024
6a93579
[skip ci] Test documentation
dasunpubudumal Jul 3, 2024
c73b30a
feat: Add test data files for iyAndFlav1 and yaml
dasunpubudumal Jul 9, 2024
29d3f0a
Refactor code to remove unused functions and improve code readability
dasunpubudumal Jul 9, 2024
94794e4
Remove unused test data files and update YAML configuration
dasunpubudumal Jul 9, 2024
4c2535c
Refactor code to remove unused functions and improve code readability
dasunpubudumal Jul 9, 2024
2ab60d3
Merge branch 'dev' into 22-create-tests-for-tpf_fasta
dasunpubudumal Jul 9, 2024
20082c5
Refactor code to remove unused functions and improve code readability
dasunpubudumal Jul 9, 2024
9b8f45d
Created test for parse_tpf.
stevieing Jul 9, 2024
ff4ac76
Updating test data files from dev branch
dasunpubudumal Jul 22, 2024
eb86c7f
Writing tests for save_to_fasta function (and creating an assertion f…
dasunpubudumal Jul 22, 2024
b4e31be
Starting off check_curate_fasta function
dasunpubudumal Jul 22, 2024
dca8720
Refactor code to remove unused functions and improve code readability
dasunpubudumal Jul 24, 2024
fc92fe3
Refactor code to use 'util' module for file comparison in tpf_fasta.r…
dasunpubudumal Jul 24, 2024
3d64a4f
[skip ci] Adding docstrings for the test utility function
dasunpubudumal Jul 24, 2024
318caa5
chore: Add pattern matching to extract bool result in are_files_ident…
dasunpubudumal Jul 24, 2024
2b040d9
Small changes to check_curate_fasta
DLBPointon Jul 24, 2024
2ff346d
Forgot to make it raw
DLBPointon Jul 24, 2024
7fbeea5
Changed structure of test and input strings
DLBPointon Jul 24, 2024
d6b4826
small changes
DLBPointon Jul 24, 2024
f5771f7
Merge pull request #41 from Rust-Wellcome/22-changes
stevieing Aug 6, 2024
46cd2ce
Merge remote-tracking branch 'origin/dev' into 22-create-tests-for-tp…
dasunpubudumal Aug 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.idea
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ serde = { version = "1.0.188", features = ["derive"] }
serde_yaml = "0.9.25"
stacker = "0.1.15"
walkdir = "2.5.0"
assert_cmd = "2.0.14"
tempfile = "3.10.1"
42 changes: 23 additions & 19 deletions src/tpf_fasta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ pub mod tpf_fasta_mod {
use crate::generics::validate_fasta;

#[derive(Debug, Clone, PartialEq, Eq)]
struct Tpf {
ori_scaffold: String,
start_coord: usize,
end_coord: usize,
new_scaffold: String,
orientation: String,
pub struct Tpf {
pub ori_scaffold: String,
pub start_coord: usize,
pub end_coord: usize,
pub new_scaffold: String,
pub orientation: String,
}

impl std::fmt::Display for Tpf {
Expand All @@ -31,9 +31,9 @@ pub mod tpf_fasta_mod {
}

#[derive(Debug, PartialEq, Eq)]
struct NewFasta {
tpf: Tpf,
sequence: String,
pub struct NewFasta {
pub tpf: Tpf,
pub sequence: String,
}

#[derive(Debug)]
Expand All @@ -42,7 +42,7 @@ pub mod tpf_fasta_mod {
sequence: Vec<String>,
}

fn parse_tpf(path: &String) -> Vec<Tpf> {
pub fn parse_tpf(path: &String) -> Vec<Tpf> {
// Instantiate a List of Tpf objects
let mut all_tpf: Vec<Tpf> = Vec::new();
for line in read_to_string(path).unwrap().lines() {
Expand All @@ -67,7 +67,7 @@ pub mod tpf_fasta_mod {
all_tpf
}

fn subset_vec_tpf<'a>(
pub fn subset_vec_tpf<'a>(
tpf: &'a Vec<Tpf>,
fasta: (&std::string::String, &usize),
) -> Vec<&'a Tpf> {
Expand All @@ -83,14 +83,14 @@ pub mod tpf_fasta_mod {
subset_tpf
}

fn check_orientation(
// The TPF will contain data in both PLUS (normal) and
// MINUS (inverted), if MINUS then we need to invert again
// and get the complement sequence
// We then return the sequence of the record.
pub fn check_orientation(
parsed: std::option::Option<noodles::fasta::record::Sequence>,
orientation: String,
) -> String {
// The TPF will contain data in both PLUS (normal) and
// MINUS (inverted), if MINUS then we need to invert again
// and get thr complement sequence
// We then return the sequence of the record.
if orientation == "MINUS" {
let start = Position::try_from(1).unwrap();
let parse_orientation = parsed.unwrap();
Expand All @@ -108,7 +108,7 @@ pub mod tpf_fasta_mod {
}
}

fn parse_seq(
pub fn parse_seq(
sequence: std::option::Option<noodles::fasta::record::Sequence>,
tpf: Vec<&Tpf>,
) -> Vec<NewFasta> {
Expand Down Expand Up @@ -139,7 +139,7 @@ pub mod tpf_fasta_mod {
subset_tpf
}

fn get_uniques(tpf_list: &Vec<Tpf>) -> Vec<String> {
pub fn get_uniques(tpf_list: &Vec<Tpf>) -> Vec<String> {
// Get a Vec of the uniques names in the TPF Vec
let mut uniques: Vec<String> = Vec::new();

Expand All @@ -151,7 +151,8 @@ pub mod tpf_fasta_mod {
uniques
}

fn save_to_fasta(
// The function could take in a path where the output files are stored.
pub fn save_to_fasta(
fasta_data: Vec<NewFasta>,
tpf_data: Vec<Tpf>,
output: &String,
Expand Down Expand Up @@ -183,6 +184,7 @@ pub mod tpf_fasta_mod {
// This is inefficient as we are scanning through the fasta_data, uniques
// ( equal to number of scaffolds) number of times
// If uniques is 10 long and fasta is 100, then this is 1000 scans through in total.
// we need to change x to something more descriptive
for x in uniques {
println!("NOW WRITING DATA FOR: {:?}", &x);
// X = "SUPER_1"
Expand All @@ -197,12 +199,14 @@ pub mod tpf_fasta_mod {
.expect("Unable to write to file");

let mut data: MyRecord = MyRecord {
// would it be better to use x.clone()
name: "".to_string(),
sequence: Vec::new(),
};

x.clone_into(&mut data.name);
for tpf in &tpf_data {
// x should be data.name and we should probably transfer ownership?
if tpf.new_scaffold == x {
for fasta in &fasta_data {
if fasta.tpf == *tpf {
Expand Down
1 change: 1 addition & 0 deletions src/yaml_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ 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 {
let reader = fasta::reader::Builder.build_from_path(&self.reference_file);
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions test_data/iyAndFlav1/tiny/tiny_test.debug.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
>SUPER_1
SCAFFOLD_1 -- 1 -- 9
>SUPER_2
SCAFFOLD_3 -- 1 -- 5
Loading
Loading