[ANN] qtc.jl

qtc.jl is a small Julia script to calculate the length of corrected QT interval (QTc) using Bazett, Fridericia, Hodges Sagie formulas.

Thanks for sharing this. Could I suggest refactoring this into a function so that we can take advantage of compilation?

Also you may want to look into using GitHub - JuliaCI/PkgTemplates.jl: Create new Julia packages, the easy way to package this formally so that it is easier to reuse this as part of other projects.

It’s not particularly efficient use of Julia to run top-level scripts like this. Not only do we have not have a chance to compile much of the script since it’s not a function, but we also cannot cache the results any compilation since its not a module.

4 Likes

Thanks for the suggestion, it’s done and available as qtc() function.

Two things that strikes the eye while reading your code :

  • You could use explicit parameter names instead of this vector param, and even set default values using e.g.
function f(x,y; z = 3,t=4)
    return x + y + z + t
end
f(1,2)
f(1,2,t=1)

Note the ; separating args and kwargs.

For units, you might use Home · Unitful.jl, which is perfect for this (inputing units and converting them). It might reduce largely the complexity of your units handling :slight_smile:

The whole Default arguments + interpreting values + convertions is like 60 lines of code, while with what i propose it might be only 3 or 4 :slight_smile:

2 Likes

Thanks, I’m aware of this. The reason is that the function gets input arguments from the terminal script via ARGS, which are parsed within the function, not outside so explicit parameters would not work.

You could juste use

f(params) = f(params...)
f(x,y,z) = ...

to handle the fact that params are comming all together from the comand line. Then, even from the comand line, params could be in UnitFull.jl’s format :slight_smile:

2 Likes