Skip to content

Commit

Permalink
ADD: from sites into sequences
Browse files Browse the repository at this point in the history
  • Loading branch information
tcztzy committed Feb 26, 2024
1 parent a483e21 commit 265c005
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ pub mod ffi {
// model.h
generate!("argweaver::ArgModel")
// sequences.h
generate!("argweaver::Sequences")
generate!("argweaver::Sites")
generate!("argweaver::read_sites")
generate!("argweaver::read_sites1")
generate!("argweaver::make_sequences_from_sites")
}
pub use ffi::{argweaver::*, spidir::*, *};
}
Expand Down
21 changes: 21 additions & 0 deletions src/sites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ fn parse_locs(input: &str) -> IResult<&str, (Vec<u32>, Vec<Vec<u32>>)> {
Ok((input, (pos, seqs)))
}

impl TryInto<UniquePtr<ffi::Sequences>> for Sites {
type Error = Box<dyn std::error::Error>;

fn try_into(self) -> Result<UniquePtr<ffi::Sequences>> {
let mut sites: UniquePtr<ffi::Sites> = self.try_into()?;
let mut sequences = ffi::Sequences::new(c_int(0)).within_unique_ptr();
unsafe {
ffi::make_sequences_from_sites(
std::pin::Pin::<&mut ffi::Sites>::into_inner_unchecked(sites.pin_mut()),
std::pin::Pin::<&mut ffi::Sequences>::into_inner_unchecked(sequences.pin_mut()),
'A' as i8,
)
};
Ok(sequences)
}
}

impl Sites {
pub fn from_path(path: &std::path::PathBuf) -> Result<Self> {
let content = read_to_string(path)?;
Expand Down Expand Up @@ -351,6 +368,10 @@ impl Sites {
.collect();
self.data.hstack_mut(&columns).unwrap();
}

pub fn set_samples(&mut self, samples: &[&str]) {
self.data = self.data.select(&samples.to_vec()).unwrap();
}
}

#[cfg(feature = "extension-module")]
Expand Down

0 comments on commit 265c005

Please sign in to comment.