gtf_count/
gtf_count.rs

1//! Counts the number of records in a GTF file.
2//!
3//! The result matches the output of `grep --count --invert-match "^#" <src>`.
4
5use std::{
6    env,
7    fs::File,
8    io::{self, BufReader},
9};
10
11use noodles_gtf as gtf;
12
13fn main() -> io::Result<()> {
14    let src = env::args().nth(1).expect("missing src");
15
16    let mut reader = File::open(src)
17        .map(BufReader::new)
18        .map(gtf::io::Reader::new)?;
19
20    let mut line = gtf::Line::default();
21    let mut n = 0;
22
23    while reader.read_line(&mut line)? != 0 {
24        if line.as_record().is_some() {
25            n += 1;
26        }
27    }
28
29    println!("{n}");
30
31    Ok(())
32}