-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98e73af
commit e88441b
Showing
17 changed files
with
451 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::io::Cursor; | ||
use std::path::PathBuf; | ||
use csv::ReaderBuilder; | ||
use tokio::fs; | ||
|
||
pub struct Calculation { | ||
pub protein: String, | ||
pub peptide: String, | ||
pub neh: String, | ||
pub charge: String, | ||
pub mean: String, | ||
pub n_ret_1: String, | ||
pub mpe_0: String, | ||
pub mpe_1: String, | ||
pub two_sd_minus: String, | ||
pub n_ret_2: String, | ||
pub two_sd_plus: String, | ||
pub n_ret_3: String, | ||
pub samples_omitted: u64, | ||
} | ||
|
||
pub async fn aggregate(spreadsheets: &Vec<(PathBuf, u64)>) -> Result<Vec<Calculation>, String> { | ||
let mut calculations = vec![]; | ||
|
||
for spreadsheet in spreadsheets { | ||
let mut spreadsheet_calculations = parse_calculations(spreadsheet).await?; | ||
calculations.append(&mut spreadsheet_calculations); | ||
} | ||
|
||
Ok(calculations) | ||
} | ||
|
||
async fn parse_calculations(spreadsheet: &(PathBuf, u64)) -> Result<Vec<Calculation>, String> { | ||
let contents = fs::read(&spreadsheet.0).await.map_err(|err| format!("Error reading calculations file: {}", err))?; | ||
let mut rdr = ReaderBuilder::new() | ||
.from_reader(Cursor::new(contents)); | ||
|
||
let mut calculations = vec![]; | ||
|
||
for result in rdr.records() { | ||
let record = result.map_err(|err| format!("Error reading record: {}", err))?; | ||
let calculation = Calculation { | ||
protein: record[0].to_string(), | ||
peptide: record[1].trim().to_string(), | ||
neh: record[2].to_string(), | ||
charge: record[3].to_string(), | ||
mean: record[4].to_string(), | ||
n_ret_1: record[5].to_string(), | ||
mpe_0: record[6].to_string(), | ||
mpe_1: record[7].to_string(), | ||
two_sd_minus: record[8].to_string(), | ||
n_ret_2: record[9].to_string(), | ||
two_sd_plus: record[10].to_string(), | ||
n_ret_3: record[11].to_string(), | ||
samples_omitted: spreadsheet.1, | ||
}; | ||
calculations.push(calculation); | ||
} | ||
|
||
Ok(calculations) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::path::{Path, PathBuf}; | ||
use tokio::process::Command; | ||
use crate::serializer::Dataset; | ||
|
||
|
||
pub async fn analyze(deps_dir: &Path, data_dir: &Path, datasets: &Vec<Dataset>) -> Result<Vec<(PathBuf, u64)>, String> { | ||
let mut results = vec![]; | ||
|
||
for dataset in datasets { | ||
let result = analyze_single(deps_dir, data_dir, dataset).await?; | ||
results.push(result); | ||
} | ||
|
||
Ok(results) | ||
} | ||
|
||
async fn analyze_single(deps_dir: &Path, data_dir: &Path, dataset: &Dataset) -> Result<(PathBuf, u64), String> { | ||
let mut command = Command::new(deps_dir.join("SRM_Rate.exe")); // TODO: figure out lifetimes here | ||
|
||
command.arg(dataset.heavy_water.to_str().unwrap()) | ||
.arg(dataset.spreadsheet.to_str().unwrap()); | ||
|
||
let input_file_name = dataset.spreadsheet.file_stem().unwrap().to_str().unwrap(); | ||
|
||
let output = command | ||
.output() | ||
.await | ||
.map_err(|err| format!("Command couldn't run: {err}"))?; | ||
|
||
if output.status.success() { | ||
Ok((data_dir.join(format!("{input_file_name}.RateConst.csv")), dataset.samples_removed)) | ||
} else { | ||
Err(format!("The command didn't complete successfully: {}", String::from_utf8_lossy(&output.stderr))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
pub mod commands; | ||
pub mod processor; | ||
pub mod processor; | ||
pub mod parser; | ||
pub mod grouper; | ||
pub mod serializer; | ||
pub mod analyzer; | ||
pub mod aggregator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.