Rust program to generate all gene pairs

This commit is contained in:
Samuel Ortion 2024-12-22 19:15:58 +01:00
parent 13f872cf10
commit f766ebcc4a
Signed by: sortion
GPG Key ID: 9B02406F8C4FB765
3 changed files with 51 additions and 0 deletions

6
rust/pairs/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "pairs"
version = "0.1.0"
edition = "2021"
[dependencies]

31
rust/pairs/src/main.rs Normal file
View File

@ -0,0 +1,31 @@
fn print_gene_pairs(genes: &Vec<String>) {
for i in 0..(genes.len()-1) {
for j in (i+1)..(genes.len()) {
println!("{}\t{}", genes[i], genes[j]);
}
}
}
fn main() {
let mut family_index: String = "".to_string();
let mut family_genes: Vec<String> = Vec::new();
for line in std::io::stdin().lines() {
let line = line.unwrap();
let mut parts = line.split("\t");
let gene = parts.next().unwrap().to_string();
let family = parts.next().unwrap().to_string();
println!("{}", family);
if family != family_index {
family_index = family;
if family_genes.len() > 1 {
print_gene_pairs(&family_genes);
}
family_genes.clear();
}
family_genes.push(gene);
}
if family_genes.len() > 1 {
print_gene_pairs(&family_genes);
}
}

14
rust/tagfinder/.gitignore vendored Normal file
View File

@ -0,0 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb