()
| 7 | use std::str::FromStr; |
| 8 | |
| 9 | pub(crate) async fn wizard_mode() -> Result<Alignoth> { |
| 10 | println!("Welcome to Alignoth wizard mode 🪄 Let's build your plot interactively.\n"); |
| 11 | |
| 12 | let current_dir = std::env::current_dir()?; |
| 13 | let bam_files: Vec<_> = fs::read_dir(¤t_dir)? |
| 14 | .filter_map(|entry| entry.ok()) |
| 15 | .map(|e| e.path()) |
| 16 | .filter(|p| { |
| 17 | p.extension() |
| 18 | .is_some_and(|ext| ext == "bam" || ext == "sam" || ext == "cram") |
| 19 | }) |
| 20 | .collect(); |
| 21 | let fasta_files: Vec<_> = fs::read_dir(¤t_dir)? |
| 22 | .filter_map(|entry| entry.ok()) |
| 23 | .map(|e| e.path()) |
| 24 | .filter(|p| { |
| 25 | p.extension() |
| 26 | .is_some_and(|ext| ext == "fa" || ext == "fasta") |
| 27 | }) |
| 28 | .collect(); |
| 29 | let vcf_files: Vec<_> = fs::read_dir(¤t_dir)? |
| 30 | .filter_map(|entry| entry.ok()) |
| 31 | .map(|e| e.path()) |
| 32 | .filter(|p| { |
| 33 | p.file_name().and_then(|n| n.to_str()).is_some_and(|name| { |
| 34 | name.ends_with(".vcf.gz") || name.ends_with(".bcf") || name.ends_with(".vcf") |
| 35 | }) |
| 36 | }) |
| 37 | .collect(); |
| 38 | let bed_files: Vec<_> = fs::read_dir(¤t_dir)? |
| 39 | .filter_map(|entry| entry.ok()) |
| 40 | .map(|e| e.path()) |
| 41 | .filter(|p| p.extension().is_some_and(|ext| ext == "bed")) |
| 42 | .collect(); |
| 43 | |
| 44 | let bam_path = if bam_files.is_empty() { |
| 45 | Text::new("Path to BAM file:").prompt()? |
| 46 | } else { |
| 47 | let choices: Vec<_> = bam_files.iter().map(|p| p.display().to_string()).collect(); |
| 48 | Select::new("Select BAM file:", choices).prompt()? |
| 49 | }; |
| 50 | |
| 51 | let reference_path = if fasta_files.is_empty() { |
| 52 | Text::new("Path to reference FASTA file:").prompt()? |
| 53 | } else { |
| 54 | let choices: Vec<_> = fasta_files |
| 55 | .iter() |
| 56 | .map(|p| p.display().to_string()) |
| 57 | .collect(); |
| 58 | Select::new("Select reference FASTA file:", choices).prompt()? |
| 59 | }; |
| 60 | |
| 61 | let contigs = get_fasta_contigs(&PathBuf::from(reference_path.clone()))?; |
| 62 | let target = Select::new("Select target contig/chromosome:", contigs).prompt()?; |
| 63 | |
| 64 | let mut region = match Select::new( |
| 65 | "Do you want to visualize around a certain position or a specific region?", |
| 66 | vec!["Around a position", "Region"], |
no test coverage detected