Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 51 additions & 45 deletions mzio-rs/src/fasta/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Entry {
entry_name: String,
protein_name: String,
keyword_attributes: HashMap<String, String>,
sequence: String
sequence: String,
}

impl Entry {
Expand All @@ -20,54 +20,60 @@ impl Entry {
/// * `protein_name` - Protein name
/// * `keyword_attributes` - Additional keyword attributes, e.g. OX=381666
/// * `sequence` - Amino acid sequence
///
pub fn new(database: String, accession: String, entry_name: String, protein_name: String,
keyword_attributes: HashMap<String, String>, sequence: String) -> Self {
Self {
database,
accession,
entry_name,
protein_name,
keyword_attributes,
sequence
}
///
pub fn new(
database: String,
accession: String,
entry_name: String,
protein_name: String,
keyword_attributes: HashMap<String, String>,
sequence: String,
) -> Self {
Self {
database,
accession,
entry_name,
protein_name,
keyword_attributes,
sequence,
}
}

/// Returns the database type
///
pub fn get_database(&self) -> &str {
&self.database.as_str()
}
/// Returns the database type
///
pub fn get_database(&self) -> &str {
self.database.as_str()
}

/// Returns the accession
///
pub fn get_accession(&self) -> &str {
&self.accession
}
/// Returns the accession
///
pub fn get_accession(&self) -> &str {
&self.accession
}

/// Entry name
///
pub fn get_entry_name(&self) -> &str {
&self.entry_name
}
/// Entry name
///
pub fn get_entry_name(&self) -> &str {
&self.entry_name
}

/// Returns the protein name
///
pub fn get_protein_name(&self) -> &str {
&self.protein_name
}
/// Returns the protein name
///
pub fn get_protein_name(&self) -> &str {
&self.protein_name
}

/// Returns additional keyword attributes, e.g
/// * OX = 381666
/// * GN = acoX
///
pub fn get_keyword_attributes(&self) -> &HashMap<String, String> {
&self.keyword_attributes
}
/// Returns additional keyword attributes, e.g
/// * OX = 381666
/// * GN = acoX
///
pub fn get_keyword_attributes(&self) -> &HashMap<String, String> {
&self.keyword_attributes
}

/// Returns the amino acid sequence
///
pub fn get_sequence(&self) -> &str {
&self.sequence
}
}
/// Returns the amino acid sequence
///
pub fn get_sequence(&self) -> &str {
&self.sequence
}
}
18 changes: 8 additions & 10 deletions mzio-rs/src/fasta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ mod test {
use std::fs;
use std::path::Path;

const FASTA_FILE_PATH_STR: &'static str = "./test_files/fasta/partial_mouse.fasta";
const FASTA_FILE_PATH_STR: &str = "./test_files/fasta/partial_mouse.fasta";
const EXPECTED_NUM_PROTEINS: usize = 10;
const TEMP_FASTA_PATH_STR: &'static str = "./test_files/fasta/partial_mouse.fasta.tmp";
const TEMP_FASTA_PATH_STR: &str = "./test_files/fasta/partial_mouse.fasta.tmp";

#[test]
/// Reads a FASTA file, parses the proteins,
Expand All @@ -20,22 +20,20 @@ mod test {
let fasta_file_path = Path::new(FASTA_FILE_PATH_STR);
let tmp_fasta_file_path = Path::new(TEMP_FASTA_PATH_STR);

let reader = reader::Reader::new(
fasta_file_path,
1024
).unwrap();
let reader = reader::Reader::new(fasta_file_path, 1024).unwrap();

let entries: Vec<entry::Entry> = reader.into_iter().collect();
assert_eq!(entries.len(), EXPECTED_NUM_PROTEINS);

let mut writer = writer::Writer::new(
tmp_fasta_file_path
).unwrap();
let mut writer = writer::Writer::new(tmp_fasta_file_path).unwrap();

writer.write_all(entries.iter(), true).unwrap();
writer.flush().unwrap();

let tmp_fasta_content = fs::read_to_string(tmp_fasta_file_path).unwrap().trim().to_string();
let tmp_fasta_content = fs::read_to_string(tmp_fasta_file_path)
.unwrap()
.trim()
.to_string();
fs::remove_file(tmp_fasta_file_path).unwrap();

assert_eq!(
Expand Down
Loading