(&mut self)
| 118 | |
| 119 | impl Preprocess for Alignoth { |
| 120 | fn preprocess(&mut self) -> anyhow::Result<()> { |
| 121 | if self.region.is_some() && self.around.is_some() && !self.plot_all { |
| 122 | return Err(anyhow!( |
| 123 | "You can only specify either a region or a base to plot around." |
| 124 | )); |
| 125 | } |
| 126 | if self.region.is_none() |
| 127 | && self.around.is_none() |
| 128 | && !self.plot_all |
| 129 | && self.around_vcf_record.is_none() |
| 130 | { |
| 131 | return Err(anyhow!( |
| 132 | "You have to specify either a region or a base to plot around or use the --plot-all or --around-vcf-record option." |
| 133 | )); |
| 134 | } |
| 135 | if self.bam_path.is_none() && self.reference.is_none() { |
| 136 | if let Some(files) = get_ref_and_bam_from_cwd()? { |
| 137 | self.reference = Some(files.0); |
| 138 | self.bam_path = Some(files.1); |
| 139 | } else { |
| 140 | return Err(anyhow!( |
| 141 | "Could not find single reference and single bam file in current working directory. Please use the -r and -b flags to specify the reference and bam file." |
| 142 | )); |
| 143 | } |
| 144 | } |
| 145 | if self.bam_path.is_none() { |
| 146 | return Err(anyhow!( |
| 147 | "Missing bam file. Please use the -b flag to specify the bam file." |
| 148 | )); |
| 149 | } |
| 150 | if self.reference.is_none() { |
| 151 | return Err(anyhow!( |
| 152 | "Missing reference file. Please use the -r flag to specify the reference file." |
| 153 | )); |
| 154 | } |
| 155 | if self.plot_all { |
| 156 | warn!("You are using the --plot-all option. This is not recommended for large bam files or files with multiple targets."); |
| 157 | self.region = Some(Region::from_bam(self.bam_path.as_ref().unwrap())?); |
| 158 | } |
| 159 | if let Some(around) = &self.around { |
| 160 | self.region = Some(Region::from_around(around)); |
| 161 | let target = self.region.as_ref().unwrap().target.clone(); |
| 162 | let target_length = |
| 163 | get_fasta_length(self.reference.as_ref().unwrap(), &target).unwrap() as i64; |
| 164 | let region = self.region.as_mut().unwrap(); |
| 165 | self.region = Some(region.clamp(0, target_length - 1)); |
| 166 | } else if let Some(vcf_record_index) = &self.around_vcf_record { |
| 167 | self.region = Some(Region::from_vcf_record( |
| 168 | *vcf_record_index, |
| 169 | self.vcf.as_ref().unwrap(), |
| 170 | )?); |
| 171 | let target = self.region.as_ref().unwrap().target.clone(); |
| 172 | let target_length = |
| 173 | get_fasta_length(self.reference.as_ref().unwrap(), &target).unwrap() as i64; |
| 174 | let region = self.region.as_mut().unwrap(); |
| 175 | self.region = Some(region.clamp(0, target_length - 1)); |
| 176 | } |
| 177 | Ok(()) |
no test coverage detected