@sjcrh/proteinpaint-rust 2.31.0 → 2.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +31 -2
- package/package.json +1 -1
- package/src/gdcmaf.rs +14 -33
package/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const path = require('path'),
|
|
2
2
|
spawn = require('child_process').spawn,
|
|
3
|
-
Readable = require('stream').Readable
|
|
3
|
+
Readable = require('stream').Readable,
|
|
4
|
+
Transform = require('stream').Transform
|
|
4
5
|
|
|
5
|
-
exports.run_rust = function(binfile, input_data) {
|
|
6
|
+
exports.run_rust = function (binfile, input_data) {
|
|
6
7
|
return new Promise((resolve, reject) => {
|
|
7
8
|
const binpath = path.join(__dirname, '/target/release/', binfile)
|
|
8
9
|
const ps = spawn(binpath)
|
|
@@ -41,3 +42,31 @@ exports.run_rust = function(binfile, input_data) {
|
|
|
41
42
|
})
|
|
42
43
|
})
|
|
43
44
|
}
|
|
45
|
+
|
|
46
|
+
exports.run_rust_stream = function (binfile, input_data) {
|
|
47
|
+
const binpath = path.join(__dirname, '/target/release/', binfile)
|
|
48
|
+
const ps = spawn(binpath)
|
|
49
|
+
try {
|
|
50
|
+
Readable.from(input_data).pipe(ps.stdin)
|
|
51
|
+
} catch (error) {
|
|
52
|
+
ps.kill()
|
|
53
|
+
let errmsg = error
|
|
54
|
+
if (stderr.length) errmsg += `killed run_rust('${binfile}'), stderr: ${stderr.join('').trim()}`
|
|
55
|
+
reject(errmsg)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const childStream = new Transform({
|
|
59
|
+
transform(chunk, encoding, callback) {
|
|
60
|
+
this.push(chunk)
|
|
61
|
+
callback()
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
ps.stdout.pipe(childStream)
|
|
65
|
+
childStream.on('error', err => {
|
|
66
|
+
reject(err)
|
|
67
|
+
})
|
|
68
|
+
childStream.on('close', code => {
|
|
69
|
+
childStream.end()
|
|
70
|
+
})
|
|
71
|
+
return childStream
|
|
72
|
+
}
|
package/package.json
CHANGED
package/src/gdcmaf.rs
CHANGED
|
@@ -4,8 +4,7 @@ use flate2::Compression;
|
|
|
4
4
|
use serde_json::Value;
|
|
5
5
|
use std::path::Path;
|
|
6
6
|
use futures::StreamExt;
|
|
7
|
-
use std::io;
|
|
8
|
-
use std::io::{Read,Write};
|
|
7
|
+
use std::io::{self,Read,Write};
|
|
9
8
|
use std::sync::mpsc;
|
|
10
9
|
|
|
11
10
|
|
|
@@ -45,8 +44,7 @@ fn gen_vec(d:String) -> (Vec<String>,Vec<Vec<u8>>) {
|
|
|
45
44
|
}
|
|
46
45
|
};
|
|
47
46
|
maf_out_lst.push("\n".to_string());
|
|
48
|
-
|
|
49
|
-
maf_bit.push(maf_compress_data);
|
|
47
|
+
maf_bit.push(maf_out_lst.join("\t").as_bytes().to_vec());
|
|
50
48
|
lst_chrom_pos.push(chrom+"\t"+&pos);
|
|
51
49
|
}
|
|
52
50
|
};
|
|
@@ -62,14 +60,6 @@ fn get_sorted_indices(lst: &Vec<String>) -> Vec<usize>{
|
|
|
62
60
|
indices
|
|
63
61
|
}
|
|
64
62
|
|
|
65
|
-
// convert vector (maf row) to GZIP encoded format
|
|
66
|
-
fn gen_gzip_vec(s:Vec<String>) -> Vec<u8> {
|
|
67
|
-
let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
|
|
68
|
-
let _ = encoder.write_all(s.join("\t").as_bytes());
|
|
69
|
-
let compress_data = encoder.finish().unwrap();
|
|
70
|
-
compress_data
|
|
71
|
-
}
|
|
72
|
-
|
|
73
63
|
// GDC MAF columns (96)
|
|
74
64
|
const MAF_COL: [&str;96] = ["Hugo_Symbol", "Entrez_Gene_Id", "Center", "NCBI_Build", "Chromosome",
|
|
75
65
|
"Start_Position", "End_Position", "Strand", "Variant_Classification",
|
|
@@ -112,18 +102,15 @@ async fn main() -> Result<(),Box<dyn std::error::Error>> {
|
|
|
112
102
|
url.into_iter().map(|url|{
|
|
113
103
|
let txt = tx.clone();
|
|
114
104
|
async move {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
txt.send((lst_chrom_pos,maf_bit)).unwrap();
|
|
124
|
-
}
|
|
105
|
+
if let Ok(resp) = reqwest::get(&url).await {
|
|
106
|
+
let content = resp.bytes().await.unwrap();
|
|
107
|
+
let mut decoder = GzDecoder::new(&content[..]);
|
|
108
|
+
let mut decompressed_content = Vec::new();
|
|
109
|
+
if let Ok(_) = decoder.read_to_end(&mut decompressed_content) {
|
|
110
|
+
let text = String::from_utf8_lossy(&decompressed_content);
|
|
111
|
+
let (lst_chrom_pos,maf_bit) = gen_vec(text.to_string());
|
|
112
|
+
txt.send((lst_chrom_pos,maf_bit)).unwrap();
|
|
125
113
|
}
|
|
126
|
-
Err(_) => println!("ERROR downloading {}", url),
|
|
127
114
|
}
|
|
128
115
|
}
|
|
129
116
|
})
|
|
@@ -145,17 +132,11 @@ async fn main() -> Result<(),Box<dyn std::error::Error>> {
|
|
|
145
132
|
// output
|
|
146
133
|
// maf_out_bit: A vector of GZIPPED maf
|
|
147
134
|
// compress_header: output header
|
|
148
|
-
let mut
|
|
149
|
-
let
|
|
150
|
-
|
|
151
|
-
let compress_header_line_break = gen_gzip_vec(["\n".to_string()].to_vec());
|
|
152
|
-
maf_out_bit.extend(compress_header_line_break);
|
|
135
|
+
let mut encoder = GzEncoder::new(io::stdout(), Compression::default());
|
|
136
|
+
let _ = encoder.write_all(&MAF_COL.join("\t").as_bytes().to_vec()).expect("Failed to write header");
|
|
137
|
+
let _ = encoder.write_all(b"\n").expect("Failed to write newline");
|
|
153
138
|
for i in idx_sorted.iter() {
|
|
154
|
-
|
|
139
|
+
let _ = encoder.write_all(&maf_bit[*i]).expect("Failed to write file");
|
|
155
140
|
};
|
|
156
|
-
|
|
157
|
-
// standard output
|
|
158
|
-
println!("{:?}",maf_out_bit);
|
|
159
|
-
std::io::stdout().flush().expect("Failed to flush stdout");
|
|
160
141
|
Ok(())
|
|
161
142
|
}
|