bio-grumpy 1.0.0__tar.gz → 1.0.1__tar.gz

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.
Files changed (31) hide show
  1. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/.gitignore +4 -1
  2. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/Cargo.lock +159 -29
  3. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/Cargo.toml +2 -1
  4. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/PKG-INFO +1 -1
  5. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/src/genome.rs +75 -0
  6. bio_grumpy-1.0.1/src/main.rs +146 -0
  7. bio_grumpy-1.0.0/src/main.rs +0 -122
  8. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/.github/workflows/release.yaml +0 -0
  9. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/.github/workflows/test.yaml +0 -0
  10. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/LICENSE +0 -0
  11. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/README-python.md +0 -0
  12. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/README.md +0 -0
  13. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/pyproject.toml +0 -0
  14. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/reference/MN908947.3.gb +0 -0
  15. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/reference/NC_000962.3.gbk +0 -0
  16. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/reference/TEST-DNA.gbk +0 -0
  17. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/src/common.rs +0 -0
  18. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/src/difference.rs +0 -0
  19. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/src/gene.rs +0 -0
  20. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/src/lib.rs +0 -0
  21. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/src/vcf.rs +0 -0
  22. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/TEST-DNA-4-minor.vcf +0 -0
  23. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/TEST-DNA-4.vcf +0 -0
  24. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/TEST-DNA-misc-indel.vcf +0 -0
  25. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/TEST-DNA.vcf +0 -0
  26. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/complex.vcf +0 -0
  27. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/dummy.vcf +0 -0
  28. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/minor-populations-revcomp-AD.vcf +0 -0
  29. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/minor-populations-revcomp.vcf +0 -0
  30. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/revcomp-del-first-pos.vcf +0 -0
  31. {bio_grumpy-1.0.0 → bio_grumpy-1.0.1}/test/tb-snp-after-del.vcf +0 -0
@@ -17,4 +17,7 @@ massif.out.*
17
17
  mprofile*
18
18
  perf.data*
19
19
  tarpaulin-*.html
20
- edge-cases.md
20
+ edge-cases.md
21
+
22
+ *.fasta
23
+ *.msh
@@ -2,6 +2,56 @@
2
2
  # It is not intended for manual editing.
3
3
  version = 4
4
4
 
5
+ [[package]]
6
+ name = "anstream"
7
+ version = "0.6.19"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933"
10
+ dependencies = [
11
+ "anstyle",
12
+ "anstyle-parse",
13
+ "anstyle-query",
14
+ "anstyle-wincon",
15
+ "colorchoice",
16
+ "is_terminal_polyfill",
17
+ "utf8parse",
18
+ ]
19
+
20
+ [[package]]
21
+ name = "anstyle"
22
+ version = "1.0.11"
23
+ source = "registry+https://github.com/rust-lang/crates.io-index"
24
+ checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd"
25
+
26
+ [[package]]
27
+ name = "anstyle-parse"
28
+ version = "0.2.7"
29
+ source = "registry+https://github.com/rust-lang/crates.io-index"
30
+ checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
31
+ dependencies = [
32
+ "utf8parse",
33
+ ]
34
+
35
+ [[package]]
36
+ name = "anstyle-query"
37
+ version = "1.1.3"
38
+ source = "registry+https://github.com/rust-lang/crates.io-index"
39
+ checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9"
40
+ dependencies = [
41
+ "windows-sys",
42
+ ]
43
+
44
+ [[package]]
45
+ name = "anstyle-wincon"
46
+ version = "3.0.9"
47
+ source = "registry+https://github.com/rust-lang/crates.io-index"
48
+ checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882"
49
+ dependencies = [
50
+ "anstyle",
51
+ "once_cell_polyfill",
52
+ "windows-sys",
53
+ ]
54
+
5
55
  [[package]]
6
56
  name = "autocfg"
7
57
  version = "1.4.0"
@@ -16,9 +66,9 @@ checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967"
16
66
 
17
67
  [[package]]
18
68
  name = "cfg-if"
19
- version = "1.0.0"
69
+ version = "1.0.1"
20
70
  source = "registry+https://github.com/rust-lang/crates.io-index"
21
- checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
71
+ checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268"
22
72
 
23
73
  [[package]]
24
74
  name = "circular"
@@ -26,6 +76,52 @@ version = "0.3.0"
26
76
  source = "registry+https://github.com/rust-lang/crates.io-index"
27
77
  checksum = "b0fc239e0f6cb375d2402d48afb92f76f5404fd1df208a41930ec81eda078bea"
28
78
 
79
+ [[package]]
80
+ name = "clap"
81
+ version = "4.5.40"
82
+ source = "registry+https://github.com/rust-lang/crates.io-index"
83
+ checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f"
84
+ dependencies = [
85
+ "clap_builder",
86
+ "clap_derive",
87
+ ]
88
+
89
+ [[package]]
90
+ name = "clap_builder"
91
+ version = "4.5.40"
92
+ source = "registry+https://github.com/rust-lang/crates.io-index"
93
+ checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e"
94
+ dependencies = [
95
+ "anstream",
96
+ "anstyle",
97
+ "clap_lex",
98
+ "strsim",
99
+ ]
100
+
101
+ [[package]]
102
+ name = "clap_derive"
103
+ version = "4.5.40"
104
+ source = "registry+https://github.com/rust-lang/crates.io-index"
105
+ checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce"
106
+ dependencies = [
107
+ "heck",
108
+ "proc-macro2",
109
+ "quote",
110
+ "syn 2.0.103",
111
+ ]
112
+
113
+ [[package]]
114
+ name = "clap_lex"
115
+ version = "0.7.5"
116
+ source = "registry+https://github.com/rust-lang/crates.io-index"
117
+ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
118
+
119
+ [[package]]
120
+ name = "colorchoice"
121
+ version = "1.0.4"
122
+ source = "registry+https://github.com/rust-lang/crates.io-index"
123
+ checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
124
+
29
125
  [[package]]
30
126
  name = "crossbeam-deque"
31
127
  version = "0.8.6"
@@ -96,8 +192,9 @@ dependencies = [
96
192
 
97
193
  [[package]]
98
194
  name = "grumpy"
99
- version = "1.0.0"
195
+ version = "1.0.1"
100
196
  dependencies = [
197
+ "clap",
101
198
  "gb-io",
102
199
  "ordered-float",
103
200
  "pretty_assertions",
@@ -119,6 +216,12 @@ version = "2.0.6"
119
216
  source = "registry+https://github.com/rust-lang/crates.io-index"
120
217
  checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
121
218
 
219
+ [[package]]
220
+ name = "is_terminal_polyfill"
221
+ version = "1.70.1"
222
+ source = "registry+https://github.com/rust-lang/crates.io-index"
223
+ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
224
+
122
225
  [[package]]
123
226
  name = "itertools"
124
227
  version = "0.10.5"
@@ -130,9 +233,9 @@ dependencies = [
130
233
 
131
234
  [[package]]
132
235
  name = "libc"
133
- version = "0.2.172"
236
+ version = "0.2.173"
134
237
  source = "registry+https://github.com/rust-lang/crates.io-index"
135
- checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
238
+ checksum = "d8cfeafaffdbc32176b64fb251369d52ea9f0a8fbc6f8759edffef7b525d64bb"
136
239
 
137
240
  [[package]]
138
241
  name = "lock_api"
@@ -152,9 +255,9 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
152
255
 
153
256
  [[package]]
154
257
  name = "memchr"
155
- version = "2.7.4"
258
+ version = "2.7.5"
156
259
  source = "registry+https://github.com/rust-lang/crates.io-index"
157
- checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
260
+ checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
158
261
 
159
262
  [[package]]
160
263
  name = "memoffset"
@@ -212,6 +315,12 @@ version = "1.21.3"
212
315
  source = "registry+https://github.com/rust-lang/crates.io-index"
213
316
  checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
214
317
 
318
+ [[package]]
319
+ name = "once_cell_polyfill"
320
+ version = "1.70.1"
321
+ source = "registry+https://github.com/rust-lang/crates.io-index"
322
+ checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
323
+
215
324
  [[package]]
216
325
  name = "ordered-float"
217
326
  version = "4.6.0"
@@ -265,9 +374,9 @@ dependencies = [
265
374
 
266
375
  [[package]]
267
376
  name = "portable-atomic"
268
- version = "1.11.0"
377
+ version = "1.11.1"
269
378
  source = "registry+https://github.com/rust-lang/crates.io-index"
270
- checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
379
+ checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
271
380
 
272
381
  [[package]]
273
382
  name = "precomputed-hash"
@@ -320,9 +429,9 @@ dependencies = [
320
429
 
321
430
  [[package]]
322
431
  name = "pyo3"
323
- version = "0.25.0"
432
+ version = "0.25.1"
324
433
  source = "registry+https://github.com/rust-lang/crates.io-index"
325
- checksum = "f239d656363bcee73afef85277f1b281e8ac6212a1d42aa90e55b90ed43c47a4"
434
+ checksum = "8970a78afe0628a3e3430376fc5fd76b6b45c4d43360ffd6cdd40bdde72b682a"
326
435
  dependencies = [
327
436
  "indoc",
328
437
  "libc",
@@ -337,9 +446,9 @@ dependencies = [
337
446
 
338
447
  [[package]]
339
448
  name = "pyo3-build-config"
340
- version = "0.25.0"
449
+ version = "0.25.1"
341
450
  source = "registry+https://github.com/rust-lang/crates.io-index"
342
- checksum = "755ea671a1c34044fa165247aaf6f419ca39caa6003aee791a0df2713d8f1b6d"
451
+ checksum = "458eb0c55e7ece017adeba38f2248ff3ac615e53660d7c71a238d7d2a01c7598"
343
452
  dependencies = [
344
453
  "once_cell",
345
454
  "target-lexicon",
@@ -347,9 +456,9 @@ dependencies = [
347
456
 
348
457
  [[package]]
349
458
  name = "pyo3-ffi"
350
- version = "0.25.0"
459
+ version = "0.25.1"
351
460
  source = "registry+https://github.com/rust-lang/crates.io-index"
352
- checksum = "fc95a2e67091e44791d4ea300ff744be5293f394f1bafd9f78c080814d35956e"
461
+ checksum = "7114fe5457c61b276ab77c5055f206295b812608083644a5c5b2640c3102565c"
353
462
  dependencies = [
354
463
  "libc",
355
464
  "pyo3-build-config",
@@ -357,27 +466,27 @@ dependencies = [
357
466
 
358
467
  [[package]]
359
468
  name = "pyo3-macros"
360
- version = "0.25.0"
469
+ version = "0.25.1"
361
470
  source = "registry+https://github.com/rust-lang/crates.io-index"
362
- checksum = "a179641d1b93920829a62f15e87c0ed791b6c8db2271ba0fd7c2686090510214"
471
+ checksum = "a8725c0a622b374d6cb051d11a0983786448f7785336139c3c94f5aa6bef7e50"
363
472
  dependencies = [
364
473
  "proc-macro2",
365
474
  "pyo3-macros-backend",
366
475
  "quote",
367
- "syn 2.0.101",
476
+ "syn 2.0.103",
368
477
  ]
369
478
 
370
479
  [[package]]
371
480
  name = "pyo3-macros-backend"
372
- version = "0.25.0"
481
+ version = "0.25.1"
373
482
  source = "registry+https://github.com/rust-lang/crates.io-index"
374
- checksum = "9dff85ebcaab8c441b0e3f7ae40a6963ecea8a9f5e74f647e33fcf5ec9a1e89e"
483
+ checksum = "4109984c22491085343c05b0dbc54ddc405c3cf7b4374fc533f5c3313a572ccc"
375
484
  dependencies = [
376
485
  "heck",
377
486
  "proc-macro2",
378
487
  "pyo3-build-config",
379
488
  "quote",
380
- "syn 2.0.101",
489
+ "syn 2.0.103",
381
490
  ]
382
491
 
383
492
  [[package]]
@@ -426,9 +535,9 @@ dependencies = [
426
535
 
427
536
  [[package]]
428
537
  name = "redox_syscall"
429
- version = "0.5.12"
538
+ version = "0.5.13"
430
539
  source = "registry+https://github.com/rust-lang/crates.io-index"
431
- checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af"
540
+ checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
432
541
  dependencies = [
433
542
  "bitflags",
434
543
  ]
@@ -471,7 +580,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
471
580
  dependencies = [
472
581
  "proc-macro2",
473
582
  "quote",
474
- "syn 2.0.101",
583
+ "syn 2.0.103",
475
584
  ]
476
585
 
477
586
  [[package]]
@@ -482,9 +591,9 @@ checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
482
591
 
483
592
  [[package]]
484
593
  name = "smallvec"
485
- version = "1.15.0"
594
+ version = "1.15.1"
486
595
  source = "registry+https://github.com/rust-lang/crates.io-index"
487
- checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9"
596
+ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
488
597
 
489
598
  [[package]]
490
599
  name = "string_cache"
@@ -511,6 +620,12 @@ dependencies = [
511
620
  "quote",
512
621
  ]
513
622
 
623
+ [[package]]
624
+ name = "strsim"
625
+ version = "0.11.1"
626
+ source = "registry+https://github.com/rust-lang/crates.io-index"
627
+ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
628
+
514
629
  [[package]]
515
630
  name = "syn"
516
631
  version = "1.0.109"
@@ -524,9 +639,9 @@ dependencies = [
524
639
 
525
640
  [[package]]
526
641
  name = "syn"
527
- version = "2.0.101"
642
+ version = "2.0.103"
528
643
  source = "registry+https://github.com/rust-lang/crates.io-index"
529
- checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
644
+ checksum = "e4307e30089d6fd6aff212f2da3a1f9e32f3223b1f010fb09b7c95f90f3ca1e8"
530
645
  dependencies = [
531
646
  "proc-macro2",
532
647
  "quote",
@@ -568,7 +683,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
568
683
  dependencies = [
569
684
  "proc-macro2",
570
685
  "quote",
571
- "syn 2.0.101",
686
+ "syn 2.0.103",
572
687
  ]
573
688
 
574
689
  [[package]]
@@ -589,6 +704,12 @@ version = "0.2.4"
589
704
  source = "registry+https://github.com/rust-lang/crates.io-index"
590
705
  checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
591
706
 
707
+ [[package]]
708
+ name = "utf8parse"
709
+ version = "0.2.2"
710
+ source = "registry+https://github.com/rust-lang/crates.io-index"
711
+ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
712
+
592
713
  [[package]]
593
714
  name = "vcf"
594
715
  version = "0.6.1"
@@ -612,6 +733,15 @@ version = "0.9.5"
612
733
  source = "registry+https://github.com/rust-lang/crates.io-index"
613
734
  checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
614
735
 
736
+ [[package]]
737
+ name = "windows-sys"
738
+ version = "0.59.0"
739
+ source = "registry+https://github.com/rust-lang/crates.io-index"
740
+ checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
741
+ dependencies = [
742
+ "windows-targets",
743
+ ]
744
+
615
745
  [[package]]
616
746
  name = "windows-targets"
617
747
  version = "0.52.6"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "grumpy"
3
- version = "1.0.0"
3
+ version = "1.0.1"
4
4
  edition = "2021"
5
5
  description = "Genetic analysis in Rust."
6
6
  license-file = "LICENSE"
@@ -16,6 +16,7 @@ vcf = "0.6.1"
16
16
  pyo3 = { version = "0.25.0", features = ["extension-module"] }
17
17
  pretty_assertions = "1.4.0"
18
18
  rayon = "1.10.0"
19
+ clap = { version = "4.5.40", features = ["derive"] }
19
20
 
20
21
  [profile.dev]
21
22
  opt-level = 3
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bio-grumpy
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: Implementation :: CPython
@@ -3,6 +3,7 @@ use pyo3::prelude::*;
3
3
 
4
4
  use std::collections::{HashMap, HashSet};
5
5
  use std::fs::File;
6
+ use std::io::Write;
6
7
 
7
8
  use gb_io::reader::SeqReader;
8
9
  use gb_io::seq::Location::Complement;
@@ -410,6 +411,80 @@ impl Genome {
410
411
  }
411
412
  self.vcf_records.as_ref().unwrap()[index].clone()
412
413
  }
414
+
415
+ /// Write the genome (including indels) to a FASTA file
416
+ ///
417
+ /// # Arguments
418
+ /// - `filename` - Name of the file to write to
419
+ pub fn write_fasta(&self, filename: &str) {
420
+ let mut nc_sequence = String::new();
421
+ for position in self.genome_positions.iter() {
422
+ if position.is_deleted {
423
+ // Position deleted, so skip it
424
+ continue;
425
+ }
426
+ // Only alts we care about now are SNPs, nulls and ins
427
+ // It's possible that we have both a SNP/null and an ins at a given position
428
+ // So check for both
429
+
430
+ let alts = position
431
+ .alts
432
+ .iter()
433
+ .filter(|alt| {
434
+ alt.alt_type == AltType::SNP
435
+ || alt.alt_type == AltType::NULL
436
+ || alt.alt_type == AltType::INS
437
+ })
438
+ .cloned()
439
+ .collect::<Vec<Alt>>();
440
+
441
+ if alts.is_empty() {
442
+ // No mutations at this position, so just add the reference base
443
+ nc_sequence.push(position.reference);
444
+ } else {
445
+ let snps = alts
446
+ .iter()
447
+ .filter(|alt| alt.alt_type == AltType::SNP || alt.alt_type == AltType::NULL)
448
+ .collect::<Vec<&Alt>>();
449
+
450
+ if snps.len() != 1 {
451
+ // No SNPs or het here so reference base
452
+ nc_sequence.push(position.reference);
453
+ } else {
454
+ // Only one SNP, so use that
455
+ let mut snp = snps[0].base.chars().next().unwrap();
456
+ if snp == 'x' {
457
+ // We use X internally for null calls, but N is the valid character in fastas
458
+ snp = 'n';
459
+ }
460
+ nc_sequence.push(snp);
461
+ }
462
+
463
+ let ins = alts
464
+ .iter()
465
+ .filter(|alt| alt.alt_type == AltType::INS)
466
+ .collect::<Vec<&Alt>>();
467
+ if ins.len() == 1 {
468
+ // Insertions are a bit more complex, we need to insert the bases
469
+ // at this position
470
+ // We only want to do this in cases of a clear, single alt's insertion
471
+ nc_sequence.push_str(&ins[0].base);
472
+ }
473
+ }
474
+ }
475
+
476
+ // Write the sequence to a FASTA file
477
+ let mut fasta_file = File::create(filename).expect("Unable to create FASTA file");
478
+ writeln!(fasta_file, ">{}", self.name).expect("Unable to write to FASTA file");
479
+ for (idx, c) in nc_sequence.chars().enumerate() {
480
+ let idx = idx + 1;
481
+ write!(fasta_file, "{}", c.to_uppercase()).expect("Unable to write to FASTA file");
482
+ if idx % 80 == 0 {
483
+ // Add a newline every 80 characters
484
+ writeln!(fasta_file).expect("Unable to write to FASTA file");
485
+ }
486
+ }
487
+ }
413
488
  }
414
489
 
415
490
  #[pyfunction]
@@ -0,0 +1,146 @@
1
+ use std::time::SystemTime;
2
+
3
+ use clap::Parser;
4
+
5
+ pub mod common;
6
+ pub mod difference;
7
+ pub mod gene;
8
+ pub mod genome;
9
+ pub mod vcf;
10
+
11
+ use common::MinorType;
12
+ use difference::GeneDifference;
13
+ use difference::GenomeDifference;
14
+ use genome::mutate;
15
+ use genome::Genome;
16
+ use vcf::VCFFile;
17
+
18
+ #[derive(Parser, Debug)]
19
+ #[command(version, about, long_about = None)]
20
+ struct Args {
21
+ /// Path to the reference genbank file
22
+ #[arg(long)]
23
+ reference: String,
24
+
25
+ /// Path to the VCF file
26
+ #[arg(long)]
27
+ vcf: String,
28
+
29
+ /// Target gene name. If given, pull out all variants and mutations within this gene
30
+ #[arg(long)]
31
+ gene: Option<String>,
32
+
33
+ /// Path to the output variable length FASTA file. If given, the sample genome will be written to this file
34
+ #[arg(long)]
35
+ fasta: Option<String>,
36
+ }
37
+
38
+ #[cfg(not(tarpaulin_include))]
39
+ fn main() {
40
+ let args = Args::parse();
41
+
42
+ let reference_path = args.reference;
43
+ let vcf_path = args.vcf;
44
+
45
+ let vcf_start = SystemTime::now();
46
+ let vcf = VCFFile::new(vcf_path.to_string(), false, 3);
47
+ let vcf_end = SystemTime::now();
48
+
49
+ let reference_start = SystemTime::now();
50
+ let mut reference = Genome::new(&reference_path);
51
+ let reference_end = SystemTime::now();
52
+
53
+ let sample_start = SystemTime::now();
54
+ let mut sample = mutate(&reference, vcf);
55
+ let sample_end = SystemTime::now();
56
+
57
+ // If given a gene name, pull out the genome and gene level differences
58
+ if let Some(target_gene) = args.gene {
59
+ let genome_start = SystemTime::now();
60
+ let mut difference =
61
+ GenomeDifference::new(reference.clone(), sample.clone(), MinorType::COV);
62
+ let genome_end = SystemTime::now();
63
+ for variant in difference.variants.iter_mut() {
64
+ if variant.gene_name.clone().is_none()
65
+ || (variant.gene_name.clone().is_some()
66
+ && variant.gene_name.clone().unwrap() != target_gene)
67
+ {
68
+ continue;
69
+ }
70
+ println!(
71
+ "{:?}@{:?} --> {:?}",
72
+ variant.gene_name,
73
+ variant.gene_position,
74
+ variant.variant.clone()
75
+ );
76
+ }
77
+ for variant in difference.minor_variants.iter_mut() {
78
+ if variant.gene_name.clone().is_none()
79
+ || (variant.gene_name.clone().is_some()
80
+ && variant.gene_name.clone().unwrap() != target_gene)
81
+ {
82
+ continue;
83
+ }
84
+ println!(
85
+ "{:?}@{:?} --> {:?}",
86
+ variant.gene_name,
87
+ variant.gene_position,
88
+ variant.variant.clone()
89
+ );
90
+ }
91
+
92
+ let gene_start = SystemTime::now();
93
+ for gene_name in sample.genes_with_mutations.clone().iter() {
94
+ if gene_name != &target_gene {
95
+ continue;
96
+ }
97
+ println!("{}", gene_name);
98
+ let gene_diff = GeneDifference::new(
99
+ reference.get_gene(gene_name.clone()),
100
+ sample.get_gene(gene_name.clone()),
101
+ MinorType::COV,
102
+ );
103
+ println!(
104
+ "{:?}",
105
+ gene_diff
106
+ .mutations
107
+ .iter()
108
+ .map(|mutation| mutation.mutation.clone())
109
+ .collect::<Vec<String>>()
110
+ );
111
+ println!(
112
+ "{:?}\n",
113
+ gene_diff
114
+ .minor_mutations
115
+ .iter()
116
+ .map(|mutation| mutation.mutation.clone())
117
+ .collect::<Vec<String>>()
118
+ );
119
+ }
120
+ let gene_end = SystemTime::now();
121
+
122
+ println!("\n-----------------------------------\n");
123
+ println!("VCF took {:?}", vcf_end.duration_since(vcf_start).unwrap());
124
+ println!(
125
+ "Reference took {:?}",
126
+ reference_end.duration_since(reference_start).unwrap()
127
+ );
128
+ println!(
129
+ "Sample took {:?}",
130
+ sample_end.duration_since(sample_start).unwrap()
131
+ );
132
+ println!(
133
+ "Genome diff took {:?}",
134
+ genome_end.duration_since(genome_start).unwrap()
135
+ );
136
+ println!(
137
+ "Gene diff took {:?}",
138
+ gene_end.duration_since(gene_start).unwrap()
139
+ );
140
+ }
141
+
142
+ // If a FASTA path is provided, write the sample genome to it
143
+ if let Some(fasta_path) = args.fasta {
144
+ sample.write_fasta(&fasta_path);
145
+ }
146
+ }
@@ -1,122 +0,0 @@
1
- use std::env;
2
- use std::time::SystemTime;
3
-
4
- pub mod common;
5
- pub mod difference;
6
- pub mod gene;
7
- pub mod genome;
8
- pub mod vcf;
9
-
10
- use common::MinorType;
11
- use difference::GeneDifference;
12
- use difference::GenomeDifference;
13
- use genome::mutate;
14
- use genome::Genome;
15
- use vcf::VCFFile;
16
-
17
- #[cfg(not(tarpaulin_include))]
18
- fn main() {
19
- let args: Vec<String> = env::args().collect();
20
- if args.len() != 3 {
21
- println!("Usage: grumpy <reference_genome> <vcf_file>");
22
- return;
23
- }
24
- let reference_path = &args[1];
25
- let vcf_path = &args[2];
26
-
27
- let vcf_start = SystemTime::now();
28
- let vcf = VCFFile::new(vcf_path.to_string(), false, 3);
29
- let vcf_end = SystemTime::now();
30
-
31
- let reference_start = SystemTime::now();
32
- let mut reference = Genome::new(reference_path);
33
- let reference_end = SystemTime::now();
34
-
35
- let sample_start = SystemTime::now();
36
- let mut sample = mutate(&reference, vcf);
37
- let sample_end = SystemTime::now();
38
-
39
- let target_gene = "yrbE3A";
40
-
41
- let genome_start = SystemTime::now();
42
- let mut difference = GenomeDifference::new(reference.clone(), sample.clone(), MinorType::COV);
43
- let genome_end = SystemTime::now();
44
- // println!("{:?}", difference.variants.iter().map(|variant| variant.variant.clone()).collect::<Vec<String>>());
45
- for variant in difference.variants.iter_mut() {
46
- if variant.gene_name.clone().is_none()
47
- || (variant.gene_name.clone().is_some()
48
- && variant.gene_name.clone().unwrap() != target_gene)
49
- {
50
- continue;
51
- }
52
- println!(
53
- "{:?}@{:?} --> {:?}",
54
- variant.gene_name,
55
- variant.gene_position,
56
- variant.variant.clone()
57
- );
58
- }
59
- for variant in difference.minor_variants.iter_mut() {
60
- if variant.gene_name.clone().is_none()
61
- || (variant.gene_name.clone().is_some()
62
- && variant.gene_name.clone().unwrap() != target_gene)
63
- {
64
- continue;
65
- }
66
- println!(
67
- "{:?}@{:?} --> {:?}",
68
- variant.gene_name,
69
- variant.gene_position,
70
- variant.variant.clone()
71
- );
72
- }
73
-
74
- let gene_start = SystemTime::now();
75
- for gene_name in sample.genes_with_mutations.clone().iter() {
76
- if gene_name != target_gene {
77
- continue;
78
- }
79
- println!("{}", gene_name);
80
- let gene_diff = GeneDifference::new(
81
- reference.get_gene(gene_name.clone()),
82
- sample.get_gene(gene_name.clone()),
83
- MinorType::COV,
84
- );
85
- println!(
86
- "{:?}",
87
- gene_diff
88
- .mutations
89
- .iter()
90
- .map(|mutation| mutation.mutation.clone())
91
- .collect::<Vec<String>>()
92
- );
93
- println!(
94
- "{:?}\n",
95
- gene_diff
96
- .minor_mutations
97
- .iter()
98
- .map(|mutation| mutation.mutation.clone())
99
- .collect::<Vec<String>>()
100
- );
101
- }
102
- let gene_end = SystemTime::now();
103
-
104
- println!("\n-----------------------------------\n");
105
- println!("VCF took {:?}", vcf_end.duration_since(vcf_start).unwrap());
106
- println!(
107
- "Reference took {:?}",
108
- reference_end.duration_since(reference_start).unwrap()
109
- );
110
- println!(
111
- "Sample took {:?}",
112
- sample_end.duration_since(sample_start).unwrap()
113
- );
114
- println!(
115
- "Genome diff took {:?}",
116
- genome_end.duration_since(genome_start).unwrap()
117
- );
118
- println!(
119
- "Gene diff took {:?}",
120
- gene_end.duration_since(gene_start).unwrap()
121
- );
122
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes