Skip to content

Commit 7a2402e

Browse files
IBCHgenomic
finished writing the code and debug started. Added asynchronous programming.
1 parent 6dd13d6 commit 7a2402e

File tree

8 files changed

+262
-157
lines changed

8 files changed

+262
-157
lines changed

Cargo.lock

Lines changed: 0 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ edition = "2024"
66
[dependencies]
77
async-std = "1.13.1"
88
clap = { version = "4.5.39", features = ["derive"] }
9-
tokio = "1.45.1"

src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ pub enum Commands {
3838
vcffile: String,
3939
/// alt allele
4040
altallel: String,
41-
}
41+
},
4242
}

src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
mod args;
22
mod store;
3-
mod variantlinker;
43
mod varaltannot;
4+
mod variantlinker;
55
mod varrefannot;
66
use crate::args::CommandParse;
77
use crate::args::Commands;
8-
use clap::Parser;
8+
use crate::varaltannot::varaltanno;
99
use crate::variantlinker::varlinker;
1010
use crate::varrefannot::varrefanno;
11-
use crate::varaltannot::varaltanno;
12-
11+
use clap::Parser;
12+
use async_std::task;
1313

1414
/*
1515
Authom GauravSablok
@@ -23,15 +23,15 @@ fn main() {
2323
let argsparse = CommandParse::parse();
2424
match &argsparse.command {
2525
Commands::VARIANTLINKER { vcfile } => {
26-
let command = varlinker(vcfile).unwrap();
26+
let command = task::block_on(varlinker(vcfile)).unwrap();
2727
println!("The command has been completed:{:?}", command);
2828
}
2929
Commands::VARIANTALTANNO { vcffile, altallel } => {
30-
let command = varaltanno(vcffile, altallel).unwrap();
30+
let command = task::block_on(varaltanno(vcffile, altallel)).unwrap();
3131
println!("The command has been completed:{:?}", command);
3232
}
3333
Commands::VARIANTREFANNO { vcffile, refallele } => {
34-
let command = varrefanno(vcffile, refallele).unwrap();
34+
let command = task::block_on(varrefanno(vcffile, refallele)).unwrap();
3535
println!("The command has been completed:{:?}", command);
3636
}
3737
}

src/store.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
#[derive(Debug, Clone, PartialOrd, PartialEq)]
22

33
pub struct VCF {
4-
pub chrom: String,
5-
pub pos: usize,
6-
pub id: String,
7-
pub refnuc: String,
8-
pub altnuc: String,
9-
pub qual: String,
4+
pub chrom: String,
5+
pub pos: usize,
6+
pub id: String,
7+
pub refnuc: String,
8+
pub altnuc: String,
9+
pub qual: String,
1010
}
1111

1212
#[derive(Debug, Clone, PartialOrd, PartialEq)]
1313

1414
pub struct GENCODE {
1515
pub chrom: String,
1616
pub typeannotate: String,
17+
pub start: usize,
18+
pub stop: usize,
19+
pub genename: String,
20+
}
21+
22+
pub struct OUTPUT {
23+
pub chrom: String,
24+
pub pos: String,
25+
pub id: String,
26+
pub refnuc: String,
27+
pub altnuc: String,
28+
pub typeannotate: String,
29+
pub genename: String,
1730
}

src/varaltannot.rs

100644100755
Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::fs::File;
2-
use std::io::{BufReader, BufRead};
1+
use crate::store::VCF;
2+
use crate::store::{GENCODE, OUTPUT};
33
use std::error::Error;
4+
use std::fs::File;
5+
use std::io::Write;
6+
use std::io::{BufRead, BufReader};
47
use std::process::Command;
5-
use crate::store::VCF;
6-
78

89
/*
910
Author Gaurav Sablok
@@ -13,40 +14,93 @@ use crate::store::VCF;
1314
Date: 2025-6-9
1415
*/
1516

16-
pub fn varaltanno(pathfile : &str, variant: &str) -> Result<String, Box<dyn Error>>{
17-
17+
pub async fn varaltanno(pathfile: &str, variant: &str) -> Result<String, Box<dyn Error>> {
1818
let _ = Command::new("wegt").
1919
arg("https://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_48/gencode.v48.chr_patch_hapl_scaff.annotation.gtf.gz")
2020
.output()
2121
.expect("command failed");
22-
let _ = Command::new("gunzip").arg("gencode.v48.chr_patch_hapl_scaff.annotation.gtf.gz")
22+
let _ = Command::new("gunzip")
23+
.arg("gencode.v48.chr_patch_hapl_scaff.annotation.gtf.gz")
2324
.output()
2425
.expect("command failed");
2526
let fileopen = File::open(pathfile).expect("file not present");
2627
let fileread = BufReader::new(fileopen);
27-
let gtfopen = File::open("gencode.v48.chr_patch_hapl_scaff.annotation.gtf")
28-
.expect("file not present");
29-
let gtfread = BufReader::new(gtfopen);
30-
let exonvector:Vec<String> = Vec::new();
31-
let gene: Vec<String> = Vec::new();
28+
let gtfresults: Vec<GENCODE> =
29+
gtfread("gencode.v48.chr_patch_hapl_scaff.annotation.gtf").unwrap();
3230
let mut vcstring_file: Vec<VCF> = Vec::new();
33-
for i in fileread.lines(){
31+
for i in fileread.lines() {
3432
let linevcf = i.expect("file not present");
35-
let linevec:Vec<String> = linevcf.split("\t").
36-
map(|x|x.to_string())
33+
let linevec: Vec<String> = linevcf
34+
.split("\t")
35+
.map(|x| x.to_string())
3736
.collect::<Vec<_>>();
38-
vcstring_file.push(VCF{
39-
chrom: linevec[0].to_string(),
40-
pos: linevec[1].parse::<usize>().unwrap(),
41-
id: linevec[2].to_string(),
42-
refnuc: linevec[3].to_string(),
43-
altnuc: linevec[4].to_string(),
44-
qual: linevec[5].to_string(),
37+
vcstring_file.push(VCF {
38+
chrom: linevec[0].to_string(),
39+
pos: linevec[1].parse::<usize>().unwrap(),
40+
id: linevec[2].to_string(),
41+
refnuc: linevec[3].to_string(),
42+
altnuc: linevec[4].to_string(),
43+
qual: linevec[5].to_string(),
4544
});
4645
}
4746

47+
let mut output: Vec<OUTPUT> = Vec::new();
48+
for i in vcstring_file.iter() {
49+
for j in gtfresults.iter() {
50+
if i.pos > j.start && i.pos <= j.stop && j.typeannotate == variant {
51+
output.push(OUTPUT {
52+
chrom: i.chrom.clone(),
53+
pos: i.pos.clone().to_string(),
54+
id: i.id.clone(),
55+
refnuc: i.id.clone(),
56+
altnuc: i.altnuc.clone(),
57+
typeannotate: j.typeannotate.clone(),
58+
genename: j.genename.clone(),
59+
});
60+
}
61+
}
62+
}
4863

49-
50-
64+
let mut mutwrite = File::create("annotationfile.txt").expect("file not present");
65+
writeln!(
66+
mutwrite,
67+
"{}\t{}\t{}\t{}\t{}\t{}\t{}",
68+
"chrom", "pos", "id", "refnuc", "altnuc", "typeannotate", "genename"
69+
)
70+
.expect("file not found");
71+
for i in output.iter() {
72+
writeln!(
73+
mutwrite,
74+
"{}\t{}\t{}\t{}\t{}\t{}\t{}",
75+
i.chrom, i.pos, i.id, i.refnuc, i.altnuc, i.typeannotate, i.genename
76+
)
77+
.expect("line not found");
78+
}
5179
Ok("The regions have been annotated".to_string())
5280
}
81+
82+
pub fn gtfread(gtffile: &str) -> Result<Vec<GENCODE>, Box<dyn Error>> {
83+
let fileopen = File::open(gtffile).expect("file not found");
84+
let fileread = BufReader::new(fileopen);
85+
let mut gtf_vector: Vec<GENCODE> = Vec::new();
86+
for i in fileread.lines() {
87+
let linegtf = i.expect("line not found");
88+
let linevec: Vec<String> = linegtf
89+
.split("\t")
90+
.map(|x| x.to_string())
91+
.collect::<Vec<String>>();
92+
let linecollect: String = linevec[9].split(";").collect::<Vec<_>>()[2]
93+
.replace(" ", "-")
94+
.split("-")
95+
.collect::<Vec<_>>()[1]
96+
.to_string();
97+
gtf_vector.push(GENCODE {
98+
chrom: linevec[0].clone(),
99+
typeannotate: linevec[2].clone(),
100+
start: linevec[3].parse::<usize>().unwrap(),
101+
stop: linevec[4].parse::<usize>().unwrap(),
102+
genename: linecollect,
103+
})
104+
}
105+
Ok(gtf_vector)
106+
}

0 commit comments

Comments
 (0)