1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use super::{Attribute, GtfRecordRef};
use anyhow::Result;
#[derive(Debug, Default)]
pub struct GtfRecord {
pub seqname: Vec<u8>,
pub source: Vec<u8>,
pub feature: Vec<u8>,
pub start: Vec<u8>,
pub end: Vec<u8>,
pub score: Vec<u8>,
pub strand: Vec<u8>,
pub frame: Vec<u8>,
pub attribute: Attribute,
}
impl GtfRecord {
pub fn from_bytes(record: &[u8]) -> Result<Self> {
let ref_record = GtfRecordRef::from_bytes(record)?;
Ok(ref_record.to_owned())
}
}
#[cfg(test)]
mod testing {
use super::GtfRecord;
#[test]
fn test_gtf() {
let line: &[u8] = br#"1 ensembl_havana gene 1471765 1497848 . + . gene_id "ENSG00000160072"; gene_version "20"; gene_name "ATAD3B"; gene_source "ensembl_havana"; gene_biotype "protein_coding";"#;
let record = GtfRecord::from_bytes(line).unwrap();
assert_eq!(record.seqname, b"1");
assert_eq!(record.source, b"ensembl_havana");
assert_eq!(record.feature, b"gene");
assert_eq!(record.start, b"1471765");
assert_eq!(record.end, b"1497848");
assert_eq!(record.score, b".");
assert_eq!(record.strand, b"+");
assert_eq!(record.frame, b".");
assert_eq!(record.attribute.gene_name, Some(b"ATAD3B".to_vec()));
assert_eq!(record.attribute.transcript_id, None);
}
}