|
| 1 | +use flatgfa::ops::gaf::ChunkEvent; |
1 | 2 | use flatgfa::pool::Id; |
2 | 3 | use flatgfa::{self, file, memfile, print, FlatGFA, HeapGFAStore}; |
3 | 4 | use pyo3::exceptions::PyIndexError; |
@@ -126,6 +127,93 @@ impl PyFlatGFA { |
126 | 127 | mmap.flush()?; |
127 | 128 | Ok(()) |
128 | 129 | } |
| 130 | + |
| 131 | + #[getter] |
| 132 | + fn size(&self) -> usize { |
| 133 | + let gfa = self.0.view(); |
| 134 | + file::size(&gfa) |
| 135 | + } |
| 136 | + |
| 137 | + fn print_gaf_lookup(&self, gaf: &str) { |
| 138 | + let gfa = self.0.view(); |
| 139 | + |
| 140 | + let name_map = flatgfa::namemap::NameMap::build(&gfa); |
| 141 | + |
| 142 | + let gaf_buf = flatgfa::memfile::map_file(&gaf); |
| 143 | + let parser = flatgfa::ops::gaf::GAFParser::new(&gaf_buf); |
| 144 | + |
| 145 | + // Print the actual sequences for each chunk in the GAF. |
| 146 | + for read in parser { |
| 147 | + print!("{}\t", read.name); |
| 148 | + for event in flatgfa::ops::gaf::PathChunker::new(&gfa, &name_map, read) { |
| 149 | + event.print_seq(&gfa); |
| 150 | + } |
| 151 | + println!(); |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + fn test_gaf(&self, gaf: &str) -> Vec<Vec<PyChunkEvent>> { |
| 156 | + let gfa = self.0.view(); |
| 157 | + |
| 158 | + let name_map = flatgfa::namemap::NameMap::build(&gfa); |
| 159 | + |
| 160 | + let gaf_buf = flatgfa::memfile::map_file(&gaf); |
| 161 | + let parser = flatgfa::ops::gaf::GAFParser::new(&gaf_buf); |
| 162 | + |
| 163 | + let r: Vec<Vec<PyChunkEvent>> = parser.into_iter().map( |
| 164 | + |x| flatgfa::ops::gaf::PathChunker::new(&gfa, &name_map, x) |
| 165 | + .into_iter() |
| 166 | + .map(|c| PyChunkEvent { chunk_event: c.into() }) |
| 167 | + .collect() |
| 168 | + ).collect(); |
| 169 | + |
| 170 | + r |
| 171 | + } |
| 172 | +} |
| 173 | + |
| 174 | +#[pyclass(frozen)] |
| 175 | +#[pyo3(name = "ChunkEvent", module = "flatgfa")] |
| 176 | +struct PyChunkEvent { |
| 177 | + chunk_event: Arc<ChunkEvent>, |
| 178 | +} |
| 179 | + |
| 180 | +#[pymethods] |
| 181 | +impl PyChunkEvent { |
| 182 | + fn __str__(&self) -> String { |
| 183 | + "".to_string() |
| 184 | + } |
| 185 | + |
| 186 | + #[getter] |
| 187 | + fn handle(&self) -> String { |
| 188 | + let seg_num: u32 = self.chunk_event.handle.segment().into(); |
| 189 | + format!("{}, {}", &self.chunk_event.handle.orient(), seg_num) |
| 190 | + } |
| 191 | + |
| 192 | + #[getter] |
| 193 | + fn range(&self) -> String { |
| 194 | + match self.chunk_event.range { |
| 195 | + flatgfa::ops::gaf::ChunkRange::None => { "".to_string() }, |
| 196 | + flatgfa::ops::gaf::ChunkRange::All => { "all".to_string() }, |
| 197 | + flatgfa::ops::gaf::ChunkRange::Partial(start, end) => { |
| 198 | + format!("[{}, {})", start, end) |
| 199 | + } |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + fn get_seq(&self, gfa: &PyFlatGFA) -> String { |
| 204 | + let inner_gfa = gfa.0.view(); |
| 205 | + let seq = inner_gfa.get_seq_oriented(self.chunk_event.handle); |
| 206 | + |
| 207 | + match self.chunk_event.range { |
| 208 | + flatgfa::ops::gaf::ChunkRange::Partial(start, end) => { |
| 209 | + seq.slice(start..end).to_string() |
| 210 | + } |
| 211 | + flatgfa::ops::gaf::ChunkRange::All => { |
| 212 | + seq.to_string() |
| 213 | + } |
| 214 | + flatgfa::ops::gaf::ChunkRange::None => {"".to_string()} |
| 215 | + } |
| 216 | + } |
129 | 217 | } |
130 | 218 |
|
131 | 219 | /// A reference to a list of *any* type within a FlatGFA. |
|
0 commit comments