Rust program to generate all gene pairs
This commit is contained in:
parent
13f872cf10
commit
f766ebcc4a
|
@ -0,0 +1,6 @@
|
||||||
|
[package]
|
||||||
|
name = "pairs"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
Loading…
Reference in New Issue