From f766ebcc4ae4ec02f756276ad2aba54026b76ac0 Mon Sep 17 00:00:00 2001 From: Samuel Ortion Date: Sun, 22 Dec 2024 19:15:58 +0100 Subject: [PATCH] Rust program to generate all gene pairs --- rust/pairs/Cargo.toml | 6 ++++++ rust/pairs/src/main.rs | 31 +++++++++++++++++++++++++++++++ rust/tagfinder/.gitignore | 14 ++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 rust/pairs/Cargo.toml create mode 100644 rust/pairs/src/main.rs create mode 100644 rust/tagfinder/.gitignore diff --git a/rust/pairs/Cargo.toml b/rust/pairs/Cargo.toml new file mode 100644 index 0000000..a74e3d3 --- /dev/null +++ b/rust/pairs/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "pairs" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/rust/pairs/src/main.rs b/rust/pairs/src/main.rs new file mode 100644 index 0000000..cc2d4ad --- /dev/null +++ b/rust/pairs/src/main.rs @@ -0,0 +1,31 @@ + +fn print_gene_pairs(genes: &Vec) { + 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 = 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); + } +} diff --git a/rust/tagfinder/.gitignore b/rust/tagfinder/.gitignore new file mode 100644 index 0000000..6985cf1 --- /dev/null +++ b/rust/tagfinder/.gitignore @@ -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