huget 0.1.0

gProfiler for human genomics
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 pdbfetch(pathname: &str, searchterm: &str) -> Result<String, Box<dyn Error>> {
    let file = File::open(pathname).expect("file not found");
    let fileread = BufReader::new(file);

    let mut pdbvec: Vec<(String, String)> = Vec::new();

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

    let mut searchstring: Vec<(String, String)> = Vec::new();

    for i in pdbvec.iter() {
        if i.0 == searchterm {
            searchstring.push((i.0.clone(), i.1.clone()))
        }
    }

    let mut filewrite = File::create("pdb.txt").expect("file not found");
    writeln!(filewrite, "The pdb searchd are as follows:").expect("file not found");
    for i in searchstring.iter() {
        writeln!(filewrite, "{}\t{}", i.0, i.1).expect("file not found");
    }

    Ok("The searhed pdb has been written".to_string())
}