# Provide a specific argument to a specific function from a series of functions from command line

**URL:** <https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777>\
**Category:** New to Julia\
**Tags:** question, argument\
**Created:** [January 25, 2020, 11:03am UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777 "2020-01-25T11:03:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![flalom](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@flalom](https://discourse.julialang.org/u/flalom)\
**Post date:** [January 25, 2020, 11:03am UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/1 "2020-01-25T11:03:37Z")

</div>

Hello everybody.

I would like to ask you: how to enter the argument(s) for only one specific function of the many ones I have in my script file from command line?

In more details: I am working on a training file, where I am writing many different functions, just to train myself…  
In one of the function (which translates dna into proteins) I would like to provide from the command line the dna sequence as function argument directly or even provide the file text directly (but I haven’t worked with files yet.

here my function:

```julia
function translator_from_rna(rna_seq :: AbstractString)
    traslation = []
    table = Dict(
        "AUA"::"I", "AUC"::"I", "AUU"::"I", "AUG"::"M", 
        "ACA"::"U", "ACC"::"T", "ACG"::"T", "ACU"::"T", 
        "AAC"::"N", "AAU"::"N", "AAA"::"K", "AAG"::"K", 
        "AGC"::"S", "AGU"::"S", "AGA"::"R", "AGG"::"R",                  
        "CUA"::"L", "CUC"::"L", "CUG"::"L", "CUU"::"L", 
        "CCA"::"P", "CCC"::"P", "CCG"::"P", "CCU"::"P", 
        "CAC"::"H", "CAU"::"H", "CAA"::"Q", "CAG"::"Q", 
        "CGA"::"R", "CGC"::"R", "CGG"::"R", "CGU"::"R", 
        "GUA"::"V", "GUC"::"V", "GUG"::"V", "GUU"::"V", 
        "GCA"::"A", "GCC"::"A", "GCG"::"A", "GCU"::"A", 
        "GAC"::"D", "GAU"::"D", "GAA"::"E", "GAG"::"E", 
        "GGA"::"G", "GGC"::"G", "GGG"::"G", "GGU"::"G", 
        "UCA"::"S", "UCC"::"S", "UCG"::"S", "UCU"::"S", 
        "UUC"::"F", "UUU"::"F", "UUA"::"L", "UUG"::"L", 
        "UAC"::"Y", "UAU"::"Y", "UAA"::"_", "UAG"::"_", 
        "UGC"::"C", "UGU"::"C", "UGA"::"_", "UGG"::"W" )
    
    start_translation = findfirst("AUG", uppercase(rna_seq))[2]
    triplets = 2
    for (num, sequence) in enumerate(start_translation:length(rna_seq))
        if num % 3 == 0 && num < length(rna_seq)
            triplents = rna_seq[sequence:sequence + triplets]
            println(triplents)
            append!(traslation, table[triplents])
        end
    end
    return join(traslation, "")
end

translator_from_rna("UUUAUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGAUUCACAUGUAAA")

```

Thank you!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 25, 2020, 11:23am UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/2 "2020-01-25T11:23:09Z")

</div>

The variables `ARGS` has the command line arguments. You can do something like

```julia
length(ARGS) == 1 || error("I need one command line argument")

translator_from_rna(ARGS[1])

```

(Julia 1.4 will have `only` which simplifies assertions like this)

---

<div class="post-metadata">

**Author:** ![flalom](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@flalom](https://discourse.julialang.org/u/flalom)\
**Post date:** [January 25, 2020, 4:51pm UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/3 "2020-01-25T16:51:58Z")

</div>

Thank you. I am having troubles with your solution.  
Did I implemented it right?

```julia

function translator_from_rna_v2((ARGS[1]) :: AbstractString)
    """This function provided a RNA sequence will generate the protein sequence starting from the first encountered AUG.
    However, in contrast to the previous function this one takes the function argument from the command line"""
    
    #This will throw an error in case the lenght of the argument is not correct
    length(ARGS) == 1 || error("I need one command line argument")
    traslation = []
    table = Dict(
        "AUA"::"I", "AUC"::"I", "AUU"::"I", "AUG"::"M", 
        "ACA"::"U", "ACC"::"T", "ACG"::"T", "ACU"::"T", 
        "AAC"::"N", "AAU"::"N", "AAA"::"K", "AAG"::"K", 
        "AGC"::"S", "AGU"::"S", "AGA"::"R", "AGG"::"R",                  
        "CUA"::"L", "CUC"::"L", "CUG"::"L", "CUU"::"L", 
        "CCA"::"P", "CCC"::"P", "CCG"::"P", "CCU"::"P", 
        "CAC"::"H", "CAU"::"H", "CAA"::"Q", "CAG"::"Q", 
        "CGA"::"R", "CGC"::"R", "CGG"::"R", "CGU"::"R", 
        "GUA"::"V", "GUC"::"V", "GUG"::"V", "GUU"::"V", 
        "GCA"::"A", "GCC"::"A", "GCG"::"A", "GCU"::"A", 
        "GAC"::"D", "GAU"::"D", "GAA"::"E", "GAG"::"E", 
        "GGA"::"G", "GGC"::"G", "GGG"::"G", "GGU"::"G", 
        "UCA"::"S", "UCC"::"S", "UCG"::"S", "UCU"::"S", 
        "UUC"::"F", "UUU"::"F", "UUA"::"L", "UUG"::"L", 
        "UAC"::"Y", "UAU"::"Y", "UAA"::"_", "UAG"::"_", 
        "UGC"::"C", "UGU"::"C", "UGA"::"_", "UGG"::"W" )
    
    start_translation = findfirst("AUG", uppercase(rna_seq))[2]
    triplets = 2
    for (num, sequence) in enumerate(start_translation:length(rna_seq))
        if num % 3 == 0 && num < length(rna_seq)
            triplents = rna_seq[sequence:sequence + triplets]
            println(triplents)
            append!(traslation, table[triplents])
        end
    end
    return join(traslation, "")
end

```

I also tried to write the function like this:

```julia

function translator_from_rna_v2(ARGS :: AbstractString)
    """This function provided a RNA sequence will generate the protein sequence starting from the first encountered AUG.
    However, in contrast to the previous function this one takes the function argument from the command line"""
    
    traslation = []
    table = Dict(
        "AUA"::"I", "AUC"::"I", "AUU"::"I", "AUG"::"M", 
        "ACA"::"U", "ACC"::"T", "ACG"::"T", "ACU"::"T", 
        "AAC"::"N", "AAU"::"N", "AAA"::"K", "AAG"::"K", 
        "AGC"::"S", "AGU"::"S", "AGA"::"R", "AGG"::"R",                  
        "CUA"::"L", "CUC"::"L", "CUG"::"L", "CUU"::"L", 
        "CCA"::"P", "CCC"::"P", "CCG"::"P", "CCU"::"P", 
        "CAC"::"H", "CAU"::"H", "CAA"::"Q", "CAG"::"Q", 
        "CGA"::"R", "CGC"::"R", "CGG"::"R", "CGU"::"R", 
        "GUA"::"V", "GUC"::"V", "GUG"::"V", "GUU"::"V", 
        "GCA"::"A", "GCC"::"A", "GCG"::"A", "GCU"::"A", 
        "GAC"::"D", "GAU"::"D", "GAA"::"E", "GAG"::"E", 
        "GGA"::"G", "GGC"::"G", "GGG"::"G", "GGU"::"G", 
        "UCA"::"S", "UCC"::"S", "UCG"::"S", "UCU"::"S", 
        "UUC"::"F", "UUU"::"F", "UUA"::"L", "UUG"::"L", 
        "UAC"::"Y", "UAU"::"Y", "UAA"::"_", "UAG"::"_", 
        "UGC"::"C", "UGU"::"C", "UGA"::"_", "UGG"::"W" )
    
    start_translation = findfirst("AUG", uppercase(rna_seq))[2]
    triplets = 2
    for (num, sequence) in enumerate(start_translation:length(rna_seq))
        if num % 3 == 0 && num < length(rna_seq)
            triplents = rna_seq[sequence:sequence + triplets]
            println(triplents)
            append!(traslation, table[triplents])
        end
    end
    return join(traslation, "")
end

#This will throw an error in case the lenght of the argument is not correct
length(ARGS) == 1 || error("I need one command line argument")
translator_from_rna_v2(ARGS[1])

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 25, 2020, 5:25pm UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/4 "2020-01-25T17:25:42Z")

</div>

This particular part should work, but I don’t know about the rest of the code, or how you are calling it from the command line. Eg

```nohighlight
$ cat /tmp/tmp.jl
length(ARGS) == 1 || error("I need one command line argument")
println(ARGS[1])
$ julia /tmp/tmp.jl "something"
something

```

---

<div class="post-metadata">

**Author:** ![flalom](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@flalom](https://discourse.julialang.org/u/flalom)\
**Post date:** [January 25, 2020, 5:37pm UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/5 "2020-01-25T17:37:50Z")

</div>

I also tried to keep the same function argument rna\_seq and call the function from the ARGS argument that you suggested, but it does not work.

``ERROR: LoadError: TypeError: in typeassert, expected Type, got String  
Stacktrace:```

---

<div class="post-metadata">

**Author:** ![flalom](https://avatars.discourse-cdn.com/v4/letter/f/e5b9ba/32.png) [@flalom](https://discourse.julialang.org/u/flalom)\
**Post date:** [January 26, 2020, 9:09pm UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/6 "2020-01-26T21:09:19Z")

</div>

Do you have some suggestions on how can I solve this?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 27, 2020, 7:35am UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/7 "2020-01-27T07:35:40Z")

</div>

Not without more information: a self-contained example that I can run, including how you call it from the command line, and the exact error message you get. Please read

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [July 16, 2020, 4:41pm UTC](https://discourse.julialang.org/t/provide-a-specific-argument-to-a-specific-function-from-a-series-of-functions-from-command-line/33777/8 "2020-07-16T16:41:32Z")

</div>

I think it has to do with your dictionary inside the function.

`Dict("A" :: "B")` is NOT the correct syntax. You should use `Dict("A" => "B")` instead. When you are trying to fix a problem it is better in isolation, this way other unrelated errors do not introduce noise.
