@@ -307,14 +307,15 @@ mutable struct FastaWriter
307307 entry:: Int
308308 own_f:: Bool
309309 at_start:: Bool
310+ check_description:: Bool
310311 function FastaWriter (io:: IO )
311- fw = new (io, false , 0 , 0 , false , 0 , 1 , false , true )
312+ fw = new (io, false , 0 , 0 , false , 0 , 1 , false , true , true )
312313 finalizer (close, fw)
313314 return fw
314315 end
315316 function FastaWriter (filename:: AbstractString , mode:: AbstractString = " w" )
316317 fopen = endswith (filename, " .gz" ) ? gzopen : open
317- fw = new (fopen (filename, mode), false , 0 , 0 , false , 0 , 1 , true , true )
318+ fw = new (fopen (filename, mode), false , 0 , 0 , false , 0 , 1 , true , true , true )
318319 finalizer (close, fw)
319320 return fw
320321 end
@@ -351,6 +352,9 @@ file.
351352
352353The `FastaWriter` object has an `entry::Int` field which stores the number of the entry which is
353354currently being written.
355+
356+ After creating the object, you can set the `check_description` field to `false` to disable the warning
357+ given when description lines are too long.
354358"""
355359function FastaWriter (f:: Function , args... )
356360 fw = FastaWriter (args... )
@@ -442,7 +446,7 @@ function write(fw::FastaWriter, c)
442446 error (" character '>' not allowed in sequence data (entry $(fw. entry) of FASTA input)" )
443447 end
444448 if fw. pos == 80
445- if ! fw. in_seq
449+ if ! fw. in_seq && fw . check_description
446450 @warn (" description line longer than 80 characters (entry $(fw. entry) of FASTA input)" )
447451 else
448452 write (fw. f, ' \n ' )
@@ -553,11 +557,13 @@ function writefastaseq(io::IO, seq, entry::Int, nl::Bool = true)
553557end
554558
555559"""
556- writefasta([io::IO = stdout], data)
560+ writefasta([io::IO = stdout], data; check_description=true )
557561
558562This version of the function writes to an already opened `IO` stream, defaulting to `stdout`.
563+
564+ Set the keyword `check_description=false` to disable the warning message given when description lines are too long.
559565"""
560- function writefasta (io:: IO , data)
566+ function writefasta (io:: IO , data; check_description :: Bool = true )
561567 entry = 0
562568 for (desc, seq) in data
563569 entry += 1
@@ -567,18 +573,18 @@ function writefasta(io::IO, data)
567573 if findfirst (== (' \n ' ), desc) ≢ nothing
568574 error (" newlines are not allowed within description (entry $entry of FASTA input)" )
569575 end
570- if length (desc) > 79
576+ if length (desc) > 79 && check_description
571577 @warn (" description line longer than 80 characters (entry $entry of FASTA input)" )
572578 end
573579 println (io, " >" , desc)
574580 entry_chars = writefastaseq (io, seq, entry)
575581 entry_chars > 0 || error (" empty sequence data (entry $entry of FASTA input)" )
576582 end
577583end
578- writefasta (data) = writefasta (stdout , data)
584+ writefasta (data; kw ... ) = writefasta (stdout , data; kw ... )
579585
580586"""
581- writefasta(filename::String, data, [mode::String = "w"])
587+ writefasta(filename::String, data, [mode::String = "w"]; check_description=true )
582588
583589This function dumps data to a FASTA file, auto-formatting it so to follow the specifications detailed in
584590the section titled [The FASTA format](@ref). The `data` can be anything which is iterable and which produces
@@ -597,11 +603,13 @@ If the `filename` ends with `.gz`, the result will be a gzip-compressed file.
597603
598604The `mode` flag determines how the `filename` is open; use `"a"` to append the data to an existing
599605file.
606+
607+ Set the keyword `check_description=false` to disable the warning message given when description lines are too long.
600608"""
601- function writefasta (filename:: AbstractString , data, mode:: AbstractString = " w" )
609+ function writefasta (filename:: AbstractString , data, mode:: AbstractString = " w" ; check_description = true )
602610 fopen = endswith (filename, " .gz" ) ? gzopen : open
603611 fopen (filename, mode) do f
604- writefasta (f, data)
612+ writefasta (f, data; check_description )
605613 end
606614end
607615
0 commit comments