gfatk/
fasta.rs

1use std::path::PathBuf;
2
3use crate::gfa::gfa::GFAtk;
4use crate::load::{load_gfa, load_gfa_stdin};
5use crate::utils;
6use anyhow::{bail, Result};
7
8/// Print a fasta representation of the sequences in a GFA.
9///
10/// For example:
11/// ```bash
12/// gfatk fasta in.gfa > out.fasta
13/// ```
14pub fn fasta(matches: &clap::ArgMatches) -> Result<()> {
15    // read in path and parse gfa
16    let gfa_file = matches.get_one::<PathBuf>("GFA");
17
18    let gfa: GFAtk = match gfa_file {
19        Some(f) => {
20            let ext = f.extension();
21            match ext {
22                Some(e) => {
23                    if e == "gfa" {
24                        GFAtk(load_gfa(f)?)
25                    } else {
26                        bail!("Input is not a GFA.")
27                    }
28                }
29                None => bail!("Could not read file."),
30            }
31        }
32        None => match utils::is_stdin() {
33            true => GFAtk(load_gfa_stdin(std::io::stdin().lock())?),
34            false => bail!("No input from STDIN. Run `gfatk extract -h` for help."),
35        },
36    };
37
38    // None here, as we aren't lookiing/care about
39    // subgraphs.
40    gfa.print_sequences(None)?;
41
42    Ok(())
43}