onecodex / needletail

Fast FASTX parsing and k-mer methods in Rust
MIT License
174 stars 20 forks source link

just print sequence #54

Closed colindaven closed 3 years ago

colindaven commented 3 years ago

I'm writing a very simple demultiplexer (based on custom barcodes, first 8chars of the read) but am struggling to get the sequence out.

I've tried

seqrec.normalize
seqrec.seq

yet only get numbers, not sequence (here FASTQ, ATGCN expected) out.

    while let Some(record) = reader.next() {
        let seqrec = record.expect("invalid record");

        // demultiplex 

        // get sequence
        let sequence = seqrec.normalize(false);

        println!("Seq: {:?}", &sequence );

Results in

Seq: [71, 65, 84, 65, 84, 84, 67, 65, 65, 65, 84, 65, 65, 67, 67, 67, 84, 71, 65, 65, 65, 67, 65, 65, 65, 84, 71, 67, 84, 84, 65, 71, 71, 71, 65, 84, 84, 84, 84, 65, 84, 84, 71, 71, 84, 65, 84, 67, 65, 71, 71, 71, 84, 84, 65, 65, 84, 67, 71, 84, 71, 67, 67, 65, 65, 71, 65, 65, 65, 65, 71, 67, 71, 71, 67, 65, 84, 71, 71, 84, 67, 65, 65, 84, 65, 84, 65, 65, 67, 67, 65, 71]

The FASTQ looks ok

@NB551160:355:H2NG7BGXH:1:11101:3879:1050 1:N:0:0
AATGTNCTTTGTGGAAAGGACGAAACACCGCTGCAGAGAAAGTCAGCGNNNANNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNANNNNGN
+
AAAAA#E6EEEAEAAEEEAEEAEEEAEEEAEEEEEEEEEEEEEEEEEE###E#################################A####E#

What am I missing? Thanks

Keats commented 3 years ago

It returns a byte slice. Use https://doc.rust-lang.org/std/str/fn.from_utf8.html if you want to print the actual string.

colindaven commented 3 years ago

Excellent, thanks. For others:

    while let Some(record) = reader.next() {
        let seqrec = record.expect("invalid record");

        // demultiplex 

        // get sequence
        let sequenceBytes = seqrec.normalize(false);

        let sequenceText = str::from_utf8(&sequenceBytes).unwrap();
        println!("Seq: {} ", &sequenceText);
}