fn read_variants_from_zip(filename: &str) -> Result<(String, HashMap<String, VariantEntry>)> {
    let mut zip = zip::ZipArchive::new(File::open(filename)?)?;
    let mut variants = HashMap::new();
    let mut strand_file_name: String = String::new();

    let mut var: VariantEntry = VariantEntry {
        chromosome: 0,
        position: 0,
        alleles: ('X', 'X'),
        strand: 'X',
    };

    for i in 0..zip.len() {
        let file = zip.by_index(i).unwrap();
        if file.name().ends_with(".strand") {
            strand_file_name = file.name().to_string();
            for line in BufReader::new(file).lines() {
                let line = line?;
                let mut l = line.split_whitespace();

                let name = l.next().unwrap().to_string();
                var.chromosome = chromosome_to_number(l.next().unwrap());
                var.position = u64::from_str_radix(l.next().unwrap(), 10).unwrap_or(0);
                l.next().unwrap_or("*");
                var.strand = l.next().unwrap().chars().next().unwrap();
                //                println!("{} {} {}", var.chromosome, var.position, var.strand);

                // Not all strand files carry allele information
                let mut alleles = l.next().unwrap_or("XX").chars();
                var.alleles.0 = alleles.next().unwrap();
                var.alleles.1 = alleles.next().unwrap();
                variants.insert(name, var.clone());
            }
            // We don't need more than one strand file
            break;
        }
    }

    Ok((strand_file_name, variants))
}
/// Find the strand file within a ZIP archive and extract the variant/position pairs
Find the strand file within a ZIP archive and extract the variant/position pairs
Find the strand file within a ZIP archive and extract the variant / position pairs
fn read_variants_from_zip(filename: &str) -> Result<(String, HashMap<String, VariantEntry>)> {
    let mut zip = zip::ZipArchive::new(File::open(filename)?)?;
    let mut variants = HashMap::new();
    let mut strand_file_name: String = String::new();
    let mut var: VariantEntry = VariantEntry {
        chromosome: 0,
        position: 0,
        alleles: ('X', 'X'),
        strand: 'X',
    };
    for i in 0..zip.len() {
        let file = zip.by_index(i).unwrap();
        if file.name().ends_with(".strand") {
            strand_file_name = file.name().to_string();
            for line in BufReader::new(file).lines() {
                let line = line?;
                let mut l = line.split_whitespace();
                let name = l.next().unwrap().to_string();
                var.chromosome = chromosome_to_number(l.next().unwrap());
                var.position = u64::from_str_radix(l.next().unwrap(), 10).unwrap_or(0);
                l.next().unwrap_or("*");
                var.strand = l.next().unwrap().chars().next().unwrap();
                //                println!("{} {} {}", var.chromosome, var.position, var.strand);
                // Not all strand files carry allele information
                let mut alleles = l.next().unwrap_or("XX").chars();
                var.alleles.0 = alleles.next().unwrap();
                var.alleles.1 = alleles.next().unwrap();
                variants.insert(name, var.clone());
            }
            // We don't need more than one strand file
            break;
        }
    }
    Ok((strand_file_name, variants))
}
fn read_variants_from_zip ( filename : & str ) -> Result < ( String , HashMap < String , VariantEntry > ) > { let mut zip = zip :: ZipArchive :: new ( File :: open ( filename ) ? ) ? ; let mut variants = HashMap :: new ( ) ; let mut strand_file_name : String = String :: new ( ) ; let mut var : VariantEntry = VariantEntry { chromosome : 0 , position : 0 , alleles : ( 'X' , 'X' ) , strand : 'X' , } ; for i in 0 .. zip . len ( ) { let file = zip . by_index ( i ) . unwrap ( ) ; if file . name ( ) . ends_with ( " " ) { strand_file_name = file . name ( ) . to_string ( ) ; for line in BufReader :: new ( file ) . lines ( ) { let line = line ? ; let mut l = line . split_whitespace ( ) ; let name = l . next ( ) . unwrap ( ) . to_string ( ) ; var . chromosome = chromosome_to_number ( l . next ( ) . unwrap ( ) ) ; var . position = u64 :: from_str_radix ( l . next ( ) . unwrap ( ) , 10 ) . unwrap_or ( 0 ) ; l . next ( ) . unwrap_or ( " " ) ; var . strand = l . next ( ) . unwrap ( ) . chars ( ) . next ( ) . unwrap ( ) ; //                println!("{} {} {}", var.chromosome, var.position, var.strand); // Not all strand files carry allele information let mut alleles = l . next ( ) . unwrap_or ( " " ) . chars ( ) ; var . alleles . 0 = alleles . next ( ) . unwrap ( ) ; var . alleles . 1 = alleles . next ( ) . unwrap ( ) ; variants . insert ( name , var . clone ( ) ) ; } // We don't need more than one strand file break ; } } Ok ( ( strand_file_name , variants ) ) }
Find the strand file within a ZIP archive and extract the variant/position pairs
Find the strand file within a ZIP archive and extract the variant / position pairs
filename
&str