use crate::clue_errors::*;
use crate::signal::Signal;
use crate::structure::Structure;
pub mod adjacency;
pub mod build_adjacency_list;
pub mod connected_subgraphs;
pub mod find_clusters;
pub mod read_clusters;
pub mod get_subclusters;
pub mod methyl_clusters;
#[derive(Debug,Clone,PartialEq)]
pub struct Cluster{
vertices: Vec::<usize>,
pub signal: Result<Option<Signal>,CluEError>,
}
impl Cluster{
pub fn from(vertices: Vec::<usize>) -> Self{
Cluster{
vertices,
signal: Ok(None),
}
}
}
impl ToString for Cluster{
fn to_string(&self) -> String {
let cluster = &self.vertices;
if cluster.is_empty(){
return "[]".to_string();
}
let mut string = format!("[{}", cluster[0]);
for vertex in cluster.iter().skip(1){
string = format!("{},{}",string,vertex);
}
format!("{}]",string)
}
}
impl Cluster{
fn len(&self) -> usize{
self.vertices.len()
}
fn to_string_result(&self,structure: &Structure) -> Result<String,CluEError>{
let cluster = &self.vertices;
if cluster.is_empty(){
return Ok("[]".to_string());
}
let mut string = format!("[{}",
structure.get_reference_index_of_nth_active(cluster[0])?
);
for &vertex in cluster.iter().skip(1){
string = format!("{},{}",string,
structure.get_reference_index_of_nth_active(vertex)?
);
}
Ok(format!("{}]",string))
}
pub fn vertices(&self) -> &Vec::<usize>{
&self.vertices
}
pub fn to_header(&self, structure: &Structure) -> Result<String,CluEError> {
let cluster = &self.vertices;
if cluster.is_empty(){
return Ok("clu".to_string());
}
let mut string = format!("clu_{}",
structure.get_reference_index_of_nth_active(cluster[0])?
);
for &vertex in cluster.iter().skip(1){
string = format!("{}_{}",string,
structure.get_reference_index_of_nth_active(vertex)?
);
}
Ok(string)
}
}