@sjcrh/proteinpaint-rust 2.177.0 → 2.178.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 CHANGED
@@ -26,13 +26,30 @@ const binaryDir = path.join(__dirname, '/target/release/')
26
26
  if (!fs.existsSync(binaryDir)) throw `missing rust binary directory='${binaryDir}'`
27
27
  if (!fs.readdirSync(binaryDir).length) throw `empty rust binary directory='${binaryDir}'`
28
28
 
29
- export function run_rust(binfile, input_data, args = []) {
29
+ export function run_rust(binfile, input_data, args = [], { signal } = {}) {
30
30
  return new Promise((resolve, reject) => {
31
31
  const binpath = path.join(__dirname, '/target/release/', binfile)
32
+
33
+ if (signal?.aborted) {
34
+ reject(new Error(`run_rust('${binfile}'): aborted before start`))
35
+ return
36
+ }
37
+
32
38
  const ps = spawn(binpath, args)
33
39
  const stdout = []
34
40
  const stderr = []
35
41
 
42
+ if (signal) {
43
+ const onAbort = () => {
44
+ if (!ps.killed) {
45
+ ps.kill()
46
+ reject(new Error(`run_rust('${binfile}'): aborted`))
47
+ }
48
+ }
49
+ signal.addEventListener('abort', onAbort, { once: true })
50
+ ps.on('close', () => signal.removeEventListener('abort', onAbort))
51
+ }
52
+
36
53
  try {
37
54
  Readable.from(input_data).pipe(ps.stdin)
38
55
  } catch (error) {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.177.0",
2
+ "version": "2.178.0",
3
3
  "name": "@sjcrh/proteinpaint-rust",
4
4
  "type": "module",
5
5
  "description": "Rust-based utilities for proteinpaint",
@@ -1,7 +1,7 @@
1
1
  // syntax:
2
2
  // echo '{"hdf5_file":"/path/to/my/local/file.h5"}' | ./target/release/validateHDF5
3
3
 
4
- use hdf5::types::VarLenAscii;
4
+ use hdf5::types::{VarLenAscii, VarLenUnicode};
5
5
  use hdf5::{File, Result};
6
6
  use ndarray::Array1;
7
7
  use ndarray::Dim;
@@ -20,12 +20,17 @@ pub fn detect_hdf5_format(hdf5_filename: &str) -> Result<&'static str> {
20
20
  let has_data_group = file.group("data").is_ok();
21
21
  let has_sample_names = file.dataset("sample_names").is_ok();
22
22
 
23
+ // Check for promoter DNA methylation format (has meta/samples/names)
24
+ let has_meta_sample_names = file.dataset("meta/samples/names").is_ok();
25
+
23
26
  if has_counts && has_gene_names && has_samples {
24
27
  // eprintln!("Dense format detected");
25
28
  Ok("dense")
26
29
  } else if has_data_group && has_sample_names {
27
30
  // eprintln!("Sparse format detected");
28
31
  Ok("sparse")
32
+ } else if has_meta_sample_names {
33
+ Ok("dna_meth_promoter")
29
34
  } else {
30
35
  // eprintln!("Unknown format detected");
31
36
  Ok("unknown")
@@ -132,6 +137,27 @@ pub fn validate_hdf5_file(hdf5_filename: String) -> Result<()> {
132
137
  }
133
138
  })
134
139
  }
140
+ "dna_meth_promoter" => {
141
+ // For promoter DNA methylation format - only read sample names
142
+ let mut sample_names: Vec<String> = Vec::new();
143
+ if let Ok(ds_samples) = file.dataset("meta/samples/names") {
144
+ if let Ok(samples) = ds_samples.read_1d::<VarLenUnicode>() {
145
+ for sample in samples.iter() {
146
+ sample_names.push(sample.to_string());
147
+ }
148
+ } else {
149
+ eprintln!("Error reading meta/samples/names as VarLenUnicode");
150
+ }
151
+ }
152
+
153
+ serde_json::json!({
154
+ "status": "success",
155
+ "message": "HDF5 promoter DNA methylation file loaded successfully",
156
+ "file_path": hdf5_filename,
157
+ "format": "dna_meth_promoter",
158
+ "sampleNames": sample_names
159
+ })
160
+ }
135
161
  _ => {
136
162
  // For unknown format
137
163
  serde_json::json!({