huget 0.1.0

gProfiler for human genomics
use crate::readstruct::HP;
use std::error::Error;
use std::fs::File;
use std::io::Write;
use std::io::{BufRead, BufReader};

/*
Gaurav Sablok
codeprog@icloud.com
*/

#[tokio::main]
pub async fn hpanalyze(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 hpvec: Vec<HP> = Vec::new();

    for i in fileread.lines() {
        let line = i.expect("line not present");
        let linevec = line.split("\t").collect::<Vec<_>>();
        hpvec.push(HP {
            value: linevec[0].to_string(),
            description: linevec[1].to_string(),
            ensembl: linevec[2].to_string(),
        });
    }

    let mut search_hp: Vec<HP> = Vec::new();

    for i in hpvec.iter() {
        if i.ensembl.contains(searchid) {
            search_hp.push(HP {
                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 HP ids for the ensembl ids are:").expect("file not preent");

    for i in hpvec.iter() {
        writeln!(filewrite, "{}\t{}\t{}", i.value, i.description, i.ensembl)
            .expect("file not present");
    }

    Ok("The hp id have been analyzed".to_string())
}