“average length of the sequences in a fasta file”: Can you improve this Erlang code?

前端 未结 5 1346
无人共我
无人共我 2021-02-06 12:29

I\'m trying to get the mean length of fasta sequences using Erlang. A fasta file looks like this

>title1
ATGACTAGCTAGCAGCGATCGACCGTCGTACGC
AT         


        
5条回答
  •  感情败类
    2021-02-06 12:52

    The call string:len(string:strip(L)) traverses the list at least twice (I'm unaware of the string:strip implementation). Instead you could write a simple function to count the line length w/0 the spaces:

    stripped_len(L) ->
      stripped_len(L, 0).
    
    stripped_len([$ |L], Len) ->
      stripped_len(L, Len);
    
    stripped_len([_C|L], Len) ->
      stripped_len(L, Len + 1);
    
    stripped_len([], Len) ->
      Len.
    

    The same method can be applied to binaries as well.

提交回复
热议问题