Skip to content

Commit 2034e0d

Browse files
committed
chloe_main
1 parent 79e298b commit 2034e0d

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = [
44
"Ian Small <[email protected]>",
55
"Ian Castleden <[email protected]>",
66
]
7-
version = "0.1.12"
7+
version = "0.1.14"
88

99
[deps]
1010
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"

RECIPES.md

+55-16
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,90 @@
11
# Recipies
22

3-
## Creating a Project
3+
## Creating a Julia Project
44

55
```bash
6-
julia -e 'using Pkg; Pkg.generate("myproject")' \
7-
&& cd myproject \
8-
&& julia --project=. -e 'using Pkg; Pkg.add("https://github.com/ian-small/chloe.git")'
6+
# create a Julia project in directory myproject
7+
julia -e 'using Pkg; Pkg.generate("myproject")'
8+
cd myproject
9+
# add Chloe to the project
10+
julia --project=. -e 'using Pkg; Pkg.add("https://github.com/ian-small/chloe.git")'
11+
# get Chloe database (This can be placed anywhere you want really)
12+
git clone https://github.com/ian-small/chloe_references
13+
```
14+
15+
## CommandLine
16+
17+
Annotate a fasta file from the command line.
18+
19+
```bash
20+
# note the '--'
21+
julia --project=. -e 'using Chloe; chloe_main()' -- annotate NC_011032.1.fa
922
```
1023

1124
## Simple
1225

13-
Annotate a single FASTA file
26+
Annotate a single FASTA file.
1427

1528
```julia
1629
import Chloe
17-
import Logging
18-
30+
# to quieten Chloe set the logging level:
31+
# import Logging
1932
# Logging.disable_logging(Logging.Info) # Disable debug and info
2033

21-
# cd && git clone https://github.com/ian-small/chloe_references
22-
db = Chloe.ReferenceDbFromDir("~/chloe_references")
34+
references = Chloe.ReferenceDbFromDir("chloe_references")
2335

24-
outfile, uid = Chloe.annotate(db, "NC_011032.1.fa")
36+
outfile, uid = Chloe.annotate(references, "NC_011032.1.fa")
2537

2638
println(outfile)
2739
```
40+
41+
Write to buffer instead of to a file.
42+
43+
```julia
44+
import Chloe
45+
references = Chloe.ReferenceDbFromDir("chloe_references")
46+
io, uid = Chloe.annotate(references, "NC_011032.1.fa", nothing, IOBuffer())
47+
# show .sff content
48+
println(String(take!(io)))
49+
```
50+
51+
Read from an already open fasta file.
52+
53+
54+
```julia
55+
import Chloe
56+
references = Chloe.ReferenceDbFromDir("chloe_references")
57+
outfile, uid = open("NC_011032.1.fa", "r") do io
58+
Chloe.annotate(references, io)
59+
end
60+
```
2861
## Distributed
2962

63+
It's easy to annotate multiple fasta files in parallel
64+
3065
```julia
3166
using Distributed
3267
# add workers
3368
addprocs(2)
3469

3570
@everywhere begin
3671
import Chloe
72+
# to quieten Chloe set the logging level:
3773
# import Logging
3874
# Logging.disable_logging(Logging.Info) # Disable debug and info
39-
references = Chloe.ReferenceDbFromDir("~/chloe_references")
75+
references = Chloe.ReferenceDbFromDir("chloe_references")
4076
end
4177

4278
fasta_directory = "fastas"
4379

4480
pmap = f -> l -> map(f, l)
81+
# find all fasta files in a directory
4582
fastas = readdir(dir) |> filter(f -> endswith(f, r"\.fa")) |> pmap(f -> joinpath(fasta_directory, f))
46-
outputs = @distributed (vcat) for fname = fastas
47-
# note that references in on a worker process
48-
output, uid = Chloe.annotate(references, fname, nothing, fname * ".sff")
83+
84+
# outputs is the list of output files
85+
outputs = @distributed (vcat) for fasta = fastas
86+
# note that `references` in on the worker process
87+
output, uid = Chloe.annotate(references, fasta, nothing, fasta * ".sff")
4988
[output]
5089
end
5190
```
@@ -55,8 +94,8 @@ using Distributed
5594
addprocs(4)
5695
@everywhere begin
5796
using Chloe
58-
db = ReferenceDbFromDir("~/chloe_references")
97+
references = ReferenceDbFromDir("~/chloe_references")
5998
end
60-
r = fetch(@spawnat :any annotate(db, "NC_011032.1.fa"))
99+
r = fetch(@spawnat :any annotate(references, "NC_011032.1.fa"))
61100
println(r)
62101
```

src/Chloe.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Chloe
22

33
export annotate, annotate_batch, ReferenceDbFromDir, ReferenceDb, ChloeConfig, AbstractReferenceDb
44
# export MayBeIO, MayBeString
5-
export cmd_main
5+
export chloe_main
66
export distributed_main, chloe_distributed, run_broker, broker_main, get_distributed_args, maybe_launch_broker
77
export set_global_logger
88
export annotate_one_task
@@ -19,7 +19,7 @@ include("dist/chloe_distributed.jl")
1919

2020
# import .ChloeDistributed: distributed_main, chloe_distributed, run_broker, get_distributed_args, maybe_launch_broker
2121
import .Annotator: annotate_batch, annotate, ReferenceDb, ReferenceDbFromDir, AbstractReferenceDb, ChloeConfig
22-
import .CmdLine: cmd_main
22+
import .CmdLine: chloe_main
2323
import .Broker: broker_main
2424
import .ZMQLogging: set_global_logger
2525
end

src/dist/chloe_cmd.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
module CmdLine
3-
export cmd_main
3+
export chloe_main
44

55
import ArgParse: ArgParseSettings, @add_arg_table!, parse_args
66
import Logging
@@ -150,7 +150,7 @@ function getargs(args::Vector{String}=ARGS)
150150
parse_args(args, cmd_args; as_symbols=true)
151151
end
152152

153-
function cmd_main(args::Vector{String} = ARGS)
153+
function chloe_main(args::Vector{String} = ARGS)
154154
parsed_args = getargs(args)
155155
level = lowercase(parsed_args[:level])
156156
Logging.with_logger(Logging.ConsoleLogger(stderr,

0 commit comments

Comments
 (0)