I have a DNA sequence that I have via reading in from a fasta and it is as a &[u8]
variable. How can I most efficiently add in a $ at the end so that I can build a suffix array from it? I'm trying to mess around with pattern matching algorithms. Thanks in advance, I'm a bit new to this. I've tried simple +
and some concat macros, but when I try it says that b"$"
is &[u8; 1]
which I think it means that it has a specified length and therefore can't be added, but then it might just be adding the bits anyway. Thanks for all your help.
Here's what I try to run
use bio::data_structures::suffix_array::suffix_array;
use bio::io::fasta;
// use std::io;
use std::env;
use std::str;
fn main() {
let args: Vec<String> = env::args().collect();
let filename: &str = &args[1];
let reader = fasta::Reader::from_file(filename).unwrap();
let mut nb_reads = 0;
let mut nb_bases = 0;
for result in reader.records() {
let result_data = &result.unwrap();
let dol: u8 = b"$"[0];
nb_reads += 1;
nb_bases += result_data.seq().len();
let seq = result_data.seq() + b"$";
println!("seq id: {:?}",result_data.id());
let sa = suffix_array(seq);
println!("sa: {:#?}",sa);
}
println!("Number of reads: {}", nb_reads);
println!("Number of bases: {}", nb_bases);
}
I've figured out a bit more so that it doesn't complain, but it doesn't appear to work. I made it a vector and then pushed a variable into it, but then when I do that it results in a variable of unit type, in this instance seq_dol
fn main() {
let args: Vec<String> = env::args().collect();
let filename: &str = &args[1];
let reader = fasta::Reader::from_file(filename).unwrap();
let mut nb_reads = 0;
let mut nb_bases = 0;
for result in reader.records() {
let result_data = &result.unwrap();
let dol: u8 = b"$"[0];
nb_reads += 1;
nb_bases += result_data.seq().len();
let seq_vec = result_data.seq().to_vec();
let seq_dol = seq_vec.push(dol);
println!("seq id: {:?}",result_data.id());
let sa = suffix_array(seq_dol);
println!("sa: {:?}",sa);
}
println!("Number of reads: {}", nb_reads);
println!("Number of bases: {}", nb_bases);
}