├── .github └── workflows │ └── ci.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md └── src └── main.rs /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | on: [push, pull_request] 2 | 3 | name: CI 4 | 5 | jobs: 6 | check: 7 | name: Check 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout sources 11 | uses: actions/checkout@v2 12 | 13 | - name: Install stable toolchain 14 | uses: actions-rs/toolchain@v1 15 | with: 16 | profile: minimal 17 | toolchain: stable 18 | override: true 19 | 20 | - name: Run cargo check 21 | uses: actions-rs/cargo@v1 22 | with: 23 | command: check 24 | 25 | test: 26 | name: Test Suite 27 | runs-on: ${{ matrix.os }} 28 | strategy: 29 | fail-fast: false 30 | matrix: 31 | build: [beta, stable, windows, macos] 32 | include: 33 | - build: macos 34 | os: macos-latest 35 | rust: stable 36 | - build: windows 37 | os: windows-latest 38 | rust: stable 39 | - build: beta 40 | os: ubuntu-latest 41 | rust: beta 42 | - build: stable 43 | os: ubuntu-latest 44 | rust: stable 45 | steps: 46 | - name: Checkout sources 47 | uses: actions/checkout@v2 48 | 49 | - name: Install stable toolchain 50 | uses: actions-rs/toolchain@v1 51 | with: 52 | toolchain: ${{ matrix.rust }} 53 | profile: minimal 54 | override: true 55 | 56 | - name: Run cargo test 57 | uses: actions-rs/cargo@v1 58 | with: 59 | command: test 60 | args: --no-fail-fast 61 | 62 | lints: 63 | name: Lints 64 | runs-on: ubuntu-latest 65 | steps: 66 | - name: Checkout sources 67 | uses: actions/checkout@v2 68 | 69 | - name: Install stable toolchain 70 | uses: actions-rs/toolchain@v1 71 | with: 72 | profile: minimal 73 | toolchain: stable 74 | override: true 75 | components: rustfmt, clippy 76 | 77 | - name: Run cargo fmt 78 | uses: actions-rs/cargo@v1 79 | with: 80 | command: fmt 81 | args: --all -- --check 82 | 83 | - name: Run cargo clippy 84 | uses: actions-rs/cargo@v1 85 | with: 86 | command: clippy 87 | args: -- -D warnings 88 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | *~ 3 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "aho-corasick" 5 | version = "0.7.15" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" 8 | dependencies = [ 9 | "memchr", 10 | ] 11 | 12 | [[package]] 13 | name = "ansi_term" 14 | version = "0.11.0" 15 | source = "registry+https://github.com/rust-lang/crates.io-index" 16 | checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" 17 | dependencies = [ 18 | "winapi", 19 | ] 20 | 21 | [[package]] 22 | name = "assert_cmd" 23 | version = "0.12.2" 24 | source = "registry+https://github.com/rust-lang/crates.io-index" 25 | checksum = "936fcf2c692b37c696cd0002c57752b2d9478402450c9ca4a463f6afae16d6f5" 26 | dependencies = [ 27 | "doc-comment", 28 | "escargot", 29 | "predicates", 30 | "predicates-core", 31 | "predicates-tree", 32 | "wait-timeout", 33 | ] 34 | 35 | [[package]] 36 | name = "atty" 37 | version = "0.2.14" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" 40 | dependencies = [ 41 | "hermit-abi", 42 | "libc", 43 | "winapi", 44 | ] 45 | 46 | [[package]] 47 | name = "autocfg" 48 | version = "1.0.1" 49 | source = "registry+https://github.com/rust-lang/crates.io-index" 50 | checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" 51 | 52 | [[package]] 53 | name = "bitflags" 54 | version = "1.2.1" 55 | source = "registry+https://github.com/rust-lang/crates.io-index" 56 | checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" 57 | 58 | [[package]] 59 | name = "buf_redux" 60 | version = "0.8.4" 61 | source = "registry+https://github.com/rust-lang/crates.io-index" 62 | checksum = "b953a6887648bb07a535631f2bc00fbdb2a2216f135552cb3f534ed136b9c07f" 63 | dependencies = [ 64 | "memchr", 65 | "safemem", 66 | ] 67 | 68 | [[package]] 69 | name = "cfg-if" 70 | version = "1.0.0" 71 | source = "registry+https://github.com/rust-lang/crates.io-index" 72 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 73 | 74 | [[package]] 75 | name = "clap" 76 | version = "2.33.3" 77 | source = "registry+https://github.com/rust-lang/crates.io-index" 78 | checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" 79 | dependencies = [ 80 | "ansi_term", 81 | "atty", 82 | "bitflags", 83 | "strsim", 84 | "textwrap", 85 | "unicode-width", 86 | "vec_map", 87 | ] 88 | 89 | [[package]] 90 | name = "const_fn" 91 | version = "0.4.5" 92 | source = "registry+https://github.com/rust-lang/crates.io-index" 93 | checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" 94 | 95 | [[package]] 96 | name = "crossbeam" 97 | version = "0.8.0" 98 | source = "registry+https://github.com/rust-lang/crates.io-index" 99 | checksum = "fd01a6eb3daaafa260f6fc94c3a6c36390abc2080e38e3e34ced87393fb77d80" 100 | dependencies = [ 101 | "cfg-if", 102 | "crossbeam-channel", 103 | "crossbeam-deque", 104 | "crossbeam-epoch", 105 | "crossbeam-queue", 106 | "crossbeam-utils", 107 | ] 108 | 109 | [[package]] 110 | name = "crossbeam-channel" 111 | version = "0.5.0" 112 | source = "registry+https://github.com/rust-lang/crates.io-index" 113 | checksum = "dca26ee1f8d361640700bde38b2c37d8c22b3ce2d360e1fc1c74ea4b0aa7d775" 114 | dependencies = [ 115 | "cfg-if", 116 | "crossbeam-utils", 117 | ] 118 | 119 | [[package]] 120 | name = "crossbeam-deque" 121 | version = "0.8.0" 122 | source = "registry+https://github.com/rust-lang/crates.io-index" 123 | checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9" 124 | dependencies = [ 125 | "cfg-if", 126 | "crossbeam-epoch", 127 | "crossbeam-utils", 128 | ] 129 | 130 | [[package]] 131 | name = "crossbeam-epoch" 132 | version = "0.9.1" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" 135 | dependencies = [ 136 | "cfg-if", 137 | "const_fn", 138 | "crossbeam-utils", 139 | "lazy_static", 140 | "memoffset", 141 | "scopeguard", 142 | ] 143 | 144 | [[package]] 145 | name = "crossbeam-queue" 146 | version = "0.3.1" 147 | source = "registry+https://github.com/rust-lang/crates.io-index" 148 | checksum = "0f6cb3c7f5b8e51bc3ebb73a2327ad4abdbd119dc13223f14f961d2f38486756" 149 | dependencies = [ 150 | "cfg-if", 151 | "crossbeam-utils", 152 | ] 153 | 154 | [[package]] 155 | name = "crossbeam-utils" 156 | version = "0.8.1" 157 | source = "registry+https://github.com/rust-lang/crates.io-index" 158 | checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" 159 | dependencies = [ 160 | "autocfg", 161 | "cfg-if", 162 | "lazy_static", 163 | ] 164 | 165 | [[package]] 166 | name = "difference" 167 | version = "2.0.0" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" 170 | 171 | [[package]] 172 | name = "doc-comment" 173 | version = "0.3.3" 174 | source = "registry+https://github.com/rust-lang/crates.io-index" 175 | checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" 176 | 177 | [[package]] 178 | name = "escargot" 179 | version = "0.5.1" 180 | source = "registry+https://github.com/rust-lang/crates.io-index" 181 | checksum = "ab01c2450bed354679e78bedbff1484e02910ef1be96755086a36cadd1247efa" 182 | dependencies = [ 183 | "log", 184 | "once_cell", 185 | "serde", 186 | "serde_json", 187 | ] 188 | 189 | [[package]] 190 | name = "float-cmp" 191 | version = "0.8.0" 192 | source = "registry+https://github.com/rust-lang/crates.io-index" 193 | checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4" 194 | dependencies = [ 195 | "num-traits", 196 | ] 197 | 198 | [[package]] 199 | name = "hermit-abi" 200 | version = "0.1.18" 201 | source = "registry+https://github.com/rust-lang/crates.io-index" 202 | checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" 203 | dependencies = [ 204 | "libc", 205 | ] 206 | 207 | [[package]] 208 | name = "itoa" 209 | version = "0.4.7" 210 | source = "registry+https://github.com/rust-lang/crates.io-index" 211 | checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" 212 | 213 | [[package]] 214 | name = "lazy_static" 215 | version = "1.4.0" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 218 | 219 | [[package]] 220 | name = "libc" 221 | version = "0.2.85" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | checksum = "7ccac4b00700875e6a07c6cde370d44d32fa01c5a65cdd2fca6858c479d28bb3" 224 | 225 | [[package]] 226 | name = "log" 227 | version = "0.4.14" 228 | source = "registry+https://github.com/rust-lang/crates.io-index" 229 | checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" 230 | dependencies = [ 231 | "cfg-if", 232 | ] 233 | 234 | [[package]] 235 | name = "memchr" 236 | version = "2.3.4" 237 | source = "registry+https://github.com/rust-lang/crates.io-index" 238 | checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" 239 | 240 | [[package]] 241 | name = "memoffset" 242 | version = "0.6.1" 243 | source = "registry+https://github.com/rust-lang/crates.io-index" 244 | checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" 245 | dependencies = [ 246 | "autocfg", 247 | ] 248 | 249 | [[package]] 250 | name = "normalize-line-endings" 251 | version = "0.3.0" 252 | source = "registry+https://github.com/rust-lang/crates.io-index" 253 | checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" 254 | 255 | [[package]] 256 | name = "num-traits" 257 | version = "0.2.14" 258 | source = "registry+https://github.com/rust-lang/crates.io-index" 259 | checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" 260 | dependencies = [ 261 | "autocfg", 262 | ] 263 | 264 | [[package]] 265 | name = "once_cell" 266 | version = "1.5.2" 267 | source = "registry+https://github.com/rust-lang/crates.io-index" 268 | checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" 269 | 270 | [[package]] 271 | name = "predicates" 272 | version = "1.0.7" 273 | source = "registry+https://github.com/rust-lang/crates.io-index" 274 | checksum = "eeb433456c1a57cc93554dea3ce40b4c19c4057e41c55d4a0f3d84ea71c325aa" 275 | dependencies = [ 276 | "difference", 277 | "float-cmp", 278 | "normalize-line-endings", 279 | "predicates-core", 280 | "regex", 281 | ] 282 | 283 | [[package]] 284 | name = "predicates-core" 285 | version = "1.0.2" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" 288 | 289 | [[package]] 290 | name = "predicates-tree" 291 | version = "1.0.2" 292 | source = "registry+https://github.com/rust-lang/crates.io-index" 293 | checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2" 294 | dependencies = [ 295 | "predicates-core", 296 | "treeline", 297 | ] 298 | 299 | [[package]] 300 | name = "proc-macro2" 301 | version = "1.0.24" 302 | source = "registry+https://github.com/rust-lang/crates.io-index" 303 | checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" 304 | dependencies = [ 305 | "unicode-xid", 306 | ] 307 | 308 | [[package]] 309 | name = "quote" 310 | version = "1.0.8" 311 | source = "registry+https://github.com/rust-lang/crates.io-index" 312 | checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" 313 | dependencies = [ 314 | "proc-macro2", 315 | ] 316 | 317 | [[package]] 318 | name = "regex" 319 | version = "1.4.3" 320 | source = "registry+https://github.com/rust-lang/crates.io-index" 321 | checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" 322 | dependencies = [ 323 | "aho-corasick", 324 | "memchr", 325 | "regex-syntax", 326 | "thread_local", 327 | ] 328 | 329 | [[package]] 330 | name = "regex-syntax" 331 | version = "0.6.22" 332 | source = "registry+https://github.com/rust-lang/crates.io-index" 333 | checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" 334 | 335 | [[package]] 336 | name = "ryu" 337 | version = "1.0.5" 338 | source = "registry+https://github.com/rust-lang/crates.io-index" 339 | checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" 340 | 341 | [[package]] 342 | name = "safemem" 343 | version = "0.3.3" 344 | source = "registry+https://github.com/rust-lang/crates.io-index" 345 | checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072" 346 | 347 | [[package]] 348 | name = "scoped_threadpool" 349 | version = "0.1.9" 350 | source = "registry+https://github.com/rust-lang/crates.io-index" 351 | checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" 352 | 353 | [[package]] 354 | name = "scopeguard" 355 | version = "1.1.0" 356 | source = "registry+https://github.com/rust-lang/crates.io-index" 357 | checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" 358 | 359 | [[package]] 360 | name = "seq_io" 361 | version = "0.3.1" 362 | source = "registry+https://github.com/rust-lang/crates.io-index" 363 | checksum = "c6fd8c16e3bbea801215d58ea15624defd37feaf05015af2dac2a8e5611cc4e4" 364 | dependencies = [ 365 | "buf_redux", 366 | "crossbeam", 367 | "memchr", 368 | "scoped_threadpool", 369 | "serde", 370 | "serde_derive", 371 | ] 372 | 373 | [[package]] 374 | name = "serde" 375 | version = "1.0.123" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" 378 | dependencies = [ 379 | "serde_derive", 380 | ] 381 | 382 | [[package]] 383 | name = "serde_derive" 384 | version = "1.0.123" 385 | source = "registry+https://github.com/rust-lang/crates.io-index" 386 | checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" 387 | dependencies = [ 388 | "proc-macro2", 389 | "quote", 390 | "syn", 391 | ] 392 | 393 | [[package]] 394 | name = "serde_json" 395 | version = "1.0.61" 396 | source = "registry+https://github.com/rust-lang/crates.io-index" 397 | checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" 398 | dependencies = [ 399 | "itoa", 400 | "ryu", 401 | "serde", 402 | ] 403 | 404 | [[package]] 405 | name = "splitfa" 406 | version = "0.1.0" 407 | dependencies = [ 408 | "assert_cmd", 409 | "clap", 410 | "predicates", 411 | "seq_io", 412 | ] 413 | 414 | [[package]] 415 | name = "strsim" 416 | version = "0.8.0" 417 | source = "registry+https://github.com/rust-lang/crates.io-index" 418 | checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" 419 | 420 | [[package]] 421 | name = "syn" 422 | version = "1.0.60" 423 | source = "registry+https://github.com/rust-lang/crates.io-index" 424 | checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" 425 | dependencies = [ 426 | "proc-macro2", 427 | "quote", 428 | "unicode-xid", 429 | ] 430 | 431 | [[package]] 432 | name = "textwrap" 433 | version = "0.11.0" 434 | source = "registry+https://github.com/rust-lang/crates.io-index" 435 | checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" 436 | dependencies = [ 437 | "unicode-width", 438 | ] 439 | 440 | [[package]] 441 | name = "thread_local" 442 | version = "1.1.3" 443 | source = "registry+https://github.com/rust-lang/crates.io-index" 444 | checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" 445 | dependencies = [ 446 | "once_cell", 447 | ] 448 | 449 | [[package]] 450 | name = "treeline" 451 | version = "0.1.0" 452 | source = "registry+https://github.com/rust-lang/crates.io-index" 453 | checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" 454 | 455 | [[package]] 456 | name = "unicode-width" 457 | version = "0.1.8" 458 | source = "registry+https://github.com/rust-lang/crates.io-index" 459 | checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" 460 | 461 | [[package]] 462 | name = "unicode-xid" 463 | version = "0.2.1" 464 | source = "registry+https://github.com/rust-lang/crates.io-index" 465 | checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" 466 | 467 | [[package]] 468 | name = "vec_map" 469 | version = "0.8.2" 470 | source = "registry+https://github.com/rust-lang/crates.io-index" 471 | checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" 472 | 473 | [[package]] 474 | name = "wait-timeout" 475 | version = "0.2.0" 476 | source = "registry+https://github.com/rust-lang/crates.io-index" 477 | checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" 478 | dependencies = [ 479 | "libc", 480 | ] 481 | 482 | [[package]] 483 | name = "winapi" 484 | version = "0.3.9" 485 | source = "registry+https://github.com/rust-lang/crates.io-index" 486 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 487 | dependencies = [ 488 | "winapi-i686-pc-windows-gnu", 489 | "winapi-x86_64-pc-windows-gnu", 490 | ] 491 | 492 | [[package]] 493 | name = "winapi-i686-pc-windows-gnu" 494 | version = "0.4.0" 495 | source = "registry+https://github.com/rust-lang/crates.io-index" 496 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 497 | 498 | [[package]] 499 | name = "winapi-x86_64-pc-windows-gnu" 500 | version = "0.4.0" 501 | source = "registry+https://github.com/rust-lang/crates.io-index" 502 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 503 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "splitfa" 3 | version = "0.1.0" 4 | authors = ["Erik Garrison "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | clap = "2.33.0" 11 | seq_io = "0.3.1" 12 | 13 | [dev-dependencies] 14 | assert_cmd = "0.12.0" 15 | predicates = "1.0.2" 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Erik Garrison 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # splitfa 2 | 3 | Splits a FASTA file into segments of the given length with a defined step size between segment starts. 4 | 5 | ## usage 6 | 7 | This would write all 2kbp sequences starting every 1kbp: 8 | 9 | ``` 10 | splitfa seqs.fa -l 2000 -s 1000 >splits.fa 11 | ``` 12 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::too_many_arguments)] 2 | 3 | use std::io::{self}; 4 | use seq_io::fasta::{Reader, Record}; 5 | //use substring::Substring; 6 | use std::str; 7 | 8 | extern crate clap; 9 | use clap::{App, Arg}; 10 | 11 | fn split_fasta(input: &str, seg_length: usize, step: usize) { 12 | let mut reader = Reader::from_path(input).unwrap(); 13 | while let Some(result) = reader.next() { 14 | let record = result.unwrap(); 15 | let seq = record.full_seq(); 16 | let name = record.id().unwrap(); 17 | let mut start: usize = 0; 18 | let total_length: usize = seq.len(); 19 | if total_length < seg_length { 20 | println!(">{}:{}-{}", name, 0, total_length); 21 | println!("{}", str::from_utf8(&seq[0..total_length]).unwrap()); 22 | } else { 23 | while start + seg_length <= total_length { 24 | println!(">{}:{}-{}", name, start, start + seg_length); 25 | println!("{}", str::from_utf8(&seq[start..(start + seg_length)]).unwrap()); 26 | start += step; 27 | } 28 | if start < total_length { 29 | start = total_length - seg_length; 30 | println!(">{}:{}-{}", name, start, start + seg_length); 31 | println!("{}", str::from_utf8(&seq[start..(start + seg_length)]).unwrap()); 32 | } 33 | } 34 | } 35 | } 36 | 37 | fn main() -> io::Result<()> { 38 | let matches = App::new("splitfa") 39 | .version("0.1.0") 40 | .author("Erik Garrison ") 41 | .about("Split a FASTA file into subsequences of a given length and overlap length") 42 | .arg( 43 | Arg::with_name("INPUT") 44 | .required(true) 45 | .takes_value(true) 46 | .index(1) 47 | .help("input FASTA file"), 48 | ) 49 | .arg( 50 | Arg::with_name("seg-length") 51 | .short("l") 52 | .long("seg-length") 53 | .takes_value(true) 54 | .help("Length of the splits"), 55 | ) 56 | .arg( 57 | Arg::with_name("step") 58 | .short("s") 59 | .long("step") 60 | .takes_value(true) 61 | .help("Step size between splits"), 62 | ) 63 | .get_matches(); 64 | 65 | let filename = matches.value_of("INPUT").unwrap(); 66 | 67 | let seg_length = matches.value_of("seg-length").unwrap().parse::().unwrap(); 68 | 69 | let step = matches.value_of("step").unwrap().parse::().unwrap(); 70 | 71 | split_fasta(filename, seg_length, step); 72 | 73 | Ok(()) 74 | } 75 | --------------------------------------------------------------------------------