1use std::path::PathBuf;
2use bio::io::fasta;
3use bio::io::gff::GffType;
4use crate::utils;
5
6pub trait InfoOutput {
9 fn by_file(paths: Vec<PathBuf>);
10 fn by_println(paths: Vec<PathBuf>);
11}
12
13pub struct InfoFa;
14impl InfoOutput for InfoFa {
15 fn by_file(paths: Vec<PathBuf>) {
16 info_fa(paths);
17 }
18
19 fn by_println(paths: Vec<PathBuf>) {
20 info_fa(paths);
21 }
22}
23
24pub struct InfoFq;
25impl InfoOutput for InfoFq {
26 fn by_file(paths: Vec<PathBuf>) {
27 info_fastq(paths);
28 }
29
30 fn by_println(paths: Vec<PathBuf>) {
31 info_fastq(paths);
32 }
33}
34
35pub struct InfoGff;
36impl InfoOutput for InfoGff {
37 fn by_file(paths: Vec<PathBuf>) {
38 info_gff(paths, GffType::GFF3);
39 }
40
41 fn by_println(paths: Vec<PathBuf>) {
42 info_gff(paths, GffType::GFF3);
43 }
44}
45
46
47fn info_fa(paths: Vec<PathBuf>) -> String {
48 for path in paths {
49 let reader = fasta::Reader::from_file(path).unwrap();
50 for record in reader.records() {
51 let record = record.unwrap();
52 println!("Seq Type: {}", utils::try_seq_type_seq(record.seq()).unwrap());
53 println!("ID: {}", record.id());
54 println!("Description: {}", record.desc().unwrap_or("None"));
55 println!("Sequence: {}", String::from_utf8(record.seq().to_vec()).unwrap());
56 println!("Length: {}", record.seq().len());
57 println!("GC content: {:.2}%", bio::seq_analysis::gc::gc_content(&*record.seq()));
58 }
59 }
60
61 "Done".to_string()
62
63}
64
65
66pub fn info_fastq(paths: Vec<PathBuf>) {
67 for path in paths {
68 let reader = bio::io::fastq::Reader::from_file(path).unwrap();
69 for record in reader.records() {
70 let record = record.unwrap();
71 println!("ID: {}", record.id());
72 println!("Description: {}", record.desc().unwrap());
73 println!("Sequence: {}", String::from_utf8(record.seq().to_vec()).unwrap());
74 println!("Quality: {}", String::from_utf8(record.qual().to_vec()).unwrap());
75 }
76 }
77
78}
79
80pub fn info_gff(paths: Vec<PathBuf>, gff_type: GffType) {
81 for path in paths {
82 let mut reader = bio::io::gff::Reader::from_file(path, gff_type).unwrap();
83 for record in reader.records() {
84 let record = record.unwrap();
85 println!("Source: {}", record.source());
87 println!("Type: {}", record.feature_type());
88 println!("Start: {}", record.start());
89 println!("End: {}", record.end());
90 println!("Attributes: {:?}", record.attributes());
94 }
95 }
96
97}