Skip to content

Commit

Permalink
Update io.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-q committed Sep 19, 2024
1 parent 8d9560d commit 0f4fcdb
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/libs/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use phylotree::tree::Tree;
use std::io::Read;
use std::{fmt, io, str};

pub fn read_newick(infile: &str) -> Tree {
let mut reader = intspan::reader(infile);
Expand All @@ -25,3 +26,71 @@ pub fn read_newick(infile: &str) -> Tree {

tree
}

#[derive(Default, Clone)]
pub struct AsmEntry {
name: String,
vector: Vec<i32>,
}

impl AsmEntry {
// Immutable accessors
pub fn name(&self) -> &String {
&self.name
}
pub fn vector(&self) -> &Vec<i32> {
&self.vector
}

pub fn new() -> Self {
Self {
name: String::new(),
vector: vec![],
}
}

/// Constructed from range and seq
///
/// ```
/// # use nwr::AsmEntry;
/// let name = "Es_coli_005008_GCF_013426115_1".to_string();
/// let vector : Vec<i32> = vec![1,5,2,7,6,6];
/// let entry = AsmEntry::from(&name, &vector);
/// # assert_eq!(*entry.name(), "Es_coli_005008_GCF_013426115_1");
/// # assert_eq!(*entry.vector().get(1).unwrap(), 5i32);
/// ```
pub fn from(name: &String, vector: &[i32]) -> Self {
Self {
name: name.clone(),
vector: Vec::from(vector),
}
}
}

impl fmt::Display for AsmEntry {
/// To string
///
/// ```
/// # use nwr::AsmEntry;
/// let name = "Es_coli_005008_GCF_013426115_1".to_string();
/// let vector : Vec<i32> = vec![1,5,2,7,6,6];
/// let entry = AsmEntry::from(&name, &vector);
/// assert_eq!(entry.to_string(), "Es_coli_005008_GCF_013426115_1\t1,5,2,7,6,6\n");
/// ```
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}\t{}\n",
self.name(),
self.vector.iter().map(|e| e.to_string()).collect::<Vec<_>>().join(","),
)?;
Ok(())
}
}

pub fn parse_asm_line(line: &str) -> AsmEntry {

}


// https://www.maartengrootendorst.com/blog/distances/

0 comments on commit 0f4fcdb

Please sign in to comment.