@@ -49,6 +49,8 @@ const docstr_kwarg_constraints =
4949 parentheses.
5050 """
5151
52+ splitlines (str) = readlines (IOBuffer (str))
53+
5254function cmd_linearfold (; model:: Symbol = :vienna ,
5355 verbose:: Bool = false ,
5456 beamsize:: Int = 100 ,
193195
194196function parse_energy (str)
195197 s = split (str, ' :' )[2 ]
196- s = split (s, ' \n ' )[1 ]
198+ s = splitlines (s )[1 ]
197199 s = lstrip (s)
198200 s = split (s, ' ' )[1 ]
199201 dG = parse (Float64, s) * u " kcal/mol"
@@ -299,7 +301,7 @@ import .Private: cmd_linearfold, cmd_linearpartition,
299301 docstr_kwarg_constraints, docstr_kwarg_is_sharpturn,
300302 docstr_kwarg_model, docstr_kwarg_verbose, run_cmd,
301303 run_cmd_linearturbofold, parseline_structure_energy, parse_energy,
302- parse_bpseq_format, parse_ct_format
304+ parse_bpseq_format, parse_ct_format, splitlines
303305
304306"""
305307 energy(seq, structure; model, is_sharpturn, verbose)
@@ -320,7 +322,7 @@ function energy(seq::AbstractString, structure::AbstractString;
320322 is_eval = true
321323 cmd = cmd_linearfold (; model, verbose, is_sharpturn, is_eval)
322324 out, err = run_cmd (cmd, " $seq \n $structure " ; nlines= 2 , verbose)
323- line = split (out, ' \n ' )[end - 1 ]
325+ line = splitlines (out)[end ]
324326 _, en = parseline_structure_energy (line)
325327 return en
326328end
@@ -358,7 +360,7 @@ function mfe(seq::AbstractString;
358360 cmd = cmd_linearfold (; model, beamsize, is_sharpturn, verbose,
359361 is_constraints)
360362 out, err = run_cmd (cmd, input; nlines, verbose)
361- line = split (out, ' \n ' )[end - 1 ]
363+ line = splitlines (out)[end ]
362364 structure, en = parseline_structure_energy (line)
363365 return en, structure
364366end
@@ -506,7 +508,7 @@ function mea(seq::AbstractString;
506508 cmd = cmd_linearpartition (; model, verbose, beamsize,
507509 is_sharpturn, mea= true , gamma)
508510 out, err = run_cmd (cmd, seq; verbose)
509- structure = String (strip ( split ( out, ' \n ' )[2 ]) )
511+ structure = String (splitlines ( out)[2 ])
510512 dG_ensemble = parse_energy (err)
511513 return dG_ensemble, structure
512514end
@@ -539,7 +541,7 @@ function threshknot(seq::AbstractString;
539541 out, err = run_cmd (cmd, seq; verbose)
540542 if verbose
541543 # skip over first line of output in verbose mode
542- out = join (split (out, ' \n ' )[2 : end ], ' \n ' )
544+ out = join (splitlines (out)[2 : end ], ' \n ' )
543545 end
544546 _, pt = parse_bpseq_format (out)
545547 dG_ensemble = parse_energy (err)
@@ -573,13 +575,11 @@ function sample_structures(seq::AbstractString;
573575 cmd = cmd_linearsampling (; beamsize, sample_number= num_samples,
574576 is_nonsaving, is_sharpturn, verbose)
575577 out, err = run_cmd (cmd, seq; verbose)
578+ lines = splitlines (out)
579+ nlines = length (lines)
576580 # skip over output lines depending on verbosity setting
577- if verbose
578- out = join (split (out, ' \n ' )[4 : end - 3 ], ' \n ' )
579- else
580- out = join (split (out, ' \n ' )[2 : end - 1 ], ' \n ' )
581- end
582- samples = String .(split (out, ' \n ' ))
581+ idx_range = verbose ? (4 : nlines- 2 ) : (2 : nlines)
582+ samples = String .(@view lines[idx_range])
583583 return samples
584584end
585585
0 commit comments