use crate::readstruct::Pathways;
use std::error::Error;
use std::fs::File;
use std::io::Write;
use std::io::{BufRead, BufReader};
#[tokio::main]
pub async fn path_analyze(pathname: &str, searchid: &str) -> Result<String, Box<dyn Error>> {
let file = File::open(pathname).expect("file not found");
let fileread = BufReader::new(file);
let mut pathvec: Vec<Pathways> = Vec::new();
for i in fileread.lines() {
let line = i.expect("line not present");
let linevec = line.split("\t").collect::<Vec<_>>();
pathvec.push(Pathways {
value: linevec[0].to_string(),
description: linevec[1].to_string(),
ensembl: linevec[2].to_string(),
});
}
let mut search_hp: Vec<Pathways> = Vec::new();
for i in pathvec.iter() {
if i.ensembl.contains(searchid) {
search_hp.push(Pathways {
value: i.value.clone(),
description: i.description.clone(),
ensembl: i.ensembl.clone(),
});
}
}
let mut filewrite = File::create("hp.txt").expect("file not present");
writeln!(filewrite, "The path ids for the ensembl ids are:").expect("file not preent");
for i in pathvec.iter() {
writeln!(filewrite, "{}\t{}\t{}", i.value, i.description, i.ensembl)
.expect("file not present");
}
Ok("The path id have been analyzed".to_string())
}