El lunes, 6 de octubre de 2014 11:56:36 UTC-5, David P. Sanders escribió:
>
>
>
> El lunes, 6 de octubre de 2014 03:01:07 UTC-5, JVaz escribió:
>>
>> Hello, I am new in Julia and it's the first time I publish here, but I 
>> actually would find it useful to modify a string. For example, I want to do:
>>  
>>
> string = "ACTGACTG"
>> string[3] = A    --> (error)
>>
>
It turns out that there is in fact already a package to work with 
biological sequences:

https://github.com/diegozea/BioSeq.jl

David.
 

>
> There is no particular reason to treat the sequence as a string; it's just 
> a collection of symbols.
> So an option is to replace it with an array of characters:
>
> julia> sequence = "ACTGACTG"
> "ACTGACTG"
>
> julia> bases = [c for c in sequence]  
> 8-element Array{Any,1}:
>  'A'
>  'C'
>  'T'
>  'G'
>  'A'
>  'C'
>  'T'
>  'G'
>
> julia> 
>
> julia> bases[3] = 'A'
> 'A'
>
> julia> bases'
> 1x8 Array{Any,2}:
>  'A'  'C'  'A'  'G'  'A'  'C'  'T'  'G'
>
> (I put ' after bases just to save space in the output; it takes the 
> transpose of the array.)
>
> Note that since the entries of the array 'bases' are now characters, they 
> must be written with apostrophes / quotes instead of double quotes.
> Also note that the code is more legible since there are readable and 
> understandable names for the variables. 
>
> The definition of bases uses an 'array comprehension'.
>
>
> To get a bit more abstract, you could instead make an array of symbols:
>
> julia> sequence = "ACTGACTG"
> "ACTGACTG"
>
> julia> bases = [symbol(c) for c in sequence];
>
> julia> 
>
> julia> bases[3] = :A
> :A
>
> julia> bases'
> 1x8 Array{Any,2}:
>  :A  :C  :A  :G  :A  :C  :T  :G
>
> so that you really have abstract symbols, instead of characters.
> (:A means "the symbol with the name 'A' in Julia; see, for example, my 
> tutorial)
>
> The semicolon suppresses output.
>
>  
>
>>
>> And I cannot use replace because I don't wanna change all the T, I just 
>> wanna change the third character in the string.
>> For me, it is useful that they are trings because then "after a mutation" 
>> I can easily check if two strings are the same, e.g:
>>
>> How could I do that, then?
>> Thanks
>>
>

Reply via email to