You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For many applications, line-wrapped fasta files pose some complications.
It would be great to have the Bio.SeqIO.FastaIO.FastaWriter: "wrap=None" option exposed to SeqIO, to allow SeqIO.write(data, handle, wrap=None, format)
or
set "wrap=none" as the default.
Hi Colin. SeqIO is deliberately simple and avoids this. What would you expect the wrap argument to do with FASTQ (line wrapping is possible but strongly discouraged), GenBank (can sometimes be useful to disable line wrapping in breach of the spec), etc? I fear this is the thin end of the wedge...
[Out of interest, why do you need FASTA without line wrapping anyway? The default has rarely if ever caused me problems.]
The problem is, it's impossible to use a FASTA file with fixed wrapping like that, because the function parse() in the same module Bio.SeqIO is not even able to read that file !
Try it for yourself !
If I want wrapping I just turn on the wrapping on the text editor !
Let's not complicate matters: a FASTA file have two lines for every sequence: the first one with the identifiers and the second one with the proper sequence !
The problem I was having was that I was getting line wrapping as a default
with SeqIO.write . I don't want line wrapping.
I want a two line per record fasta file.
From your reply, it seems that this shouldn't be the case, so perhaps I am
missing something.
I recall opening files in gedit and seeing the lines were wrapped (also if
I 'head' the file in bash , the lines are wrapped).
I will double check my code and the output. Perhaps something else is going
on here?
On 18 Nov 2015 01:14, "digfish" [email protected] wrote:
The problem is, it's impossible to use a FASTA file with fixed wrapping
like that, because the function parse() in the same module Bio.SeqIO is not
even able to read that file !
Try it for yourself !
If I want wrapping I just turn on the wrapping on the text editor !
Let's not complicate matters: a FASTA file have two lines for every
sequence: the first one with the identifiers and the second one with the
proper sequence !
—
Reply to this email directly or view it on GitHub #666 (comment)
.
It seems @digfish has found a separate problem with the FASTA parser - it can usually read the FASTA files written by Biopython: Please file a separate bug for that.
In any case, the convention is very clear: FASTA sequence lines can be wrapped, and in most cases are wrapped. Remember the sequence can be millions (even billions) or letters long in the case of chromosomes - and singles lines of that length do not work well at the command line terminal nor in most editors.
However, as @ColinAnthony notes, there are times (when dealing with shorter sequences) that no-line-wrapping FASTA files with exactly two lines per record have advantages.
I'm working with reads with approximately 255 bp. I understand the motivation for having wrapping for reads with more than > 1000 bp.
I'm new in the Bioinformatics world, and I was thinking that the sequences (I'm talking on the specific case of FASTA) have the sequence length according to each model of sequencer. Yes, I'm doing downstream analysis, I have the need to select to filter out sequences and each time create a new FASTA file with only some sequences that I need and after I discovered this FASTA file formatting issued I started to avoid using the function SeqIO.write() for that and relying on a function made by me for writing the FASTA files.
I'm not against the wrapping: I just think that it does not have to be the default behaviour.
I'd like to avoid wrapping fasta output using the SeqIO.write method as well. Why not float a **kwargs in the SeqIO.write method that is then passed to the writer classes as specific options for that format?
@Zsailer this was a deliberate design choice to keep the main SeqIO API as simple and usable as possible. Would an output variant name of fasta-nowrap or similar be acceptable?
@peterjc I completely agree with the design decision to make the API simple and usable. And don't get me wrong, I think this API great!
I guess my point was that adding **kwargs to SeqIO.write and passing it to whatever _FormatToWriter the user specifies doesn't really add any extra complexity for the user or the API. Most users ignore it.
I went ahead and created a branch to show what I mean. You can see it here.
You can see I just added **kwargs to lines 449 and 492 in Bio.SeqIO.__init__.
449defwrite(sequences, handle, format, **kwargs):
.
.
.
488withas_handle(handle, mode) asfp:
489# Map the file format to a writer class490ifformatin_FormatToWriter:
491writer_class=_FormatToWriter[format]
492count=writer_class(fp, **kwargs).write_file(sequences)
With this API, the user can add options to the each format.
I agree the code change to enable **kwargs is trivial, it is the implication of doing this which worries me. It suddenly massively expands the public API - documentation alone would be a mass of work. So I'm again going to be stubborn on this.
Adding fasta-nowrap (or similar) as an output variant format would solve what seems to be a relatively common use case, within the current API and naming approach. Do you fancy working on that instead? Again, the code changes should be quite small.
Later we could also add this format-variant as an input format too (it would raise an exception if asked to parse multi-line FASTA files).
I started thinking about merging #1450 from @Zsailer and then how to implement the matching (strict) no-wrapping parser, and realised there is a choice here - do we really want a strict two-line-per-record FASTA variant here?
The distinction is about the corner case of zero-length records, which could be one line only (the > line) or two lines (the > line and a blank sequence line). As written, the code would produce the two-line form on output.
I think a strict two-line-per-record interpretation is much more useful as it allows more assumptions for high speed parsing and indexing.
If you agree, as part of adding a strict two-line-per-record FASTA parser, should I rename the proposed fasta-nowrap format variant to fasta-2line?
(Something to keep in mind: Separately we might introduce fastq-4line or fastq-nowrap as an optimised version of the FASTQ parser)
@peterjc, renaming fasta-nowrap to fasta-2line makes sense to me.
I agree, a strict interpretation is better. As a user, I'd expect fasta-2line to produce two-line output even in a zero-record scenario. The output from a fasta-nowrap syntax in that scenario feels ambiguous.
I benefitted a lot from @Zsailer's patch to expose fasta-2line but now I have a similar question: would it make sense to expose another option qual-2line to output qual files in strict 2-line format? I have a pipeline with tools, some of which expect 2-line qual files. I monkey-patched my BioPython to add a QualPhredTwoLineWriter along the lines of what was done in #1450, so for my use case I can get by, but if there's independent interest I (or someone else) can contribute this back.
Hi Joris - I'm surprised to here anyone is still using qual files - I used to with Roche 454 data but that was some years back - I'd be curious to here more about the use case, and if it justifies adding this extra code. Would you mind opening an new issue about this proposal? Thanks!
Also I am belatedly closing this issue, the fasta-2line support added in Biopython 1.71 addressed the original goal from Colin.
Activity
peterjc commentedon Nov 9, 2015
Hi Colin. SeqIO is deliberately simple and avoids this. What would you expect the wrap argument to do with FASTQ (line wrapping is possible but strongly discouraged), GenBank (can sometimes be useful to disable line wrapping in breach of the spec), etc? I fear this is the thin end of the wedge...
[Out of interest, why do you need FASTA without line wrapping anyway? The default has rarely if ever caused me problems.]
digfish commentedon Nov 17, 2015
The problem is, it's impossible to use a FASTA file with fixed wrapping like that, because the function parse() in the same module Bio.SeqIO is not even able to read that file !
Try it for yourself !
If I want wrapping I just turn on the wrapping on the text editor !
Let's not complicate matters: a FASTA file have two lines for every sequence: the first one with the identifiers and the second one with the proper sequence !
ColinAnthony commentedon Nov 18, 2015
The problem I was having was that I was getting line wrapping as a default
with SeqIO.write . I don't want line wrapping.
I want a two line per record fasta file.
From your reply, it seems that this shouldn't be the case, so perhaps I am
missing something.
I recall opening files in gedit and seeing the lines were wrapped (also if
I 'head' the file in bash , the lines are wrapped).
I will double check my code and the output. Perhaps something else is going
on here?
On 18 Nov 2015 01:14, "digfish" [email protected] wrote:
peterjc commentedon Nov 18, 2015
It seems @digfish has found a separate problem with the FASTA parser - it can usually read the FASTA files written by Biopython: Please file a separate bug for that.
In any case, the convention is very clear: FASTA sequence lines can be wrapped, and in most cases are wrapped. Remember the sequence can be millions (even billions) or letters long in the case of chromosomes - and singles lines of that length do not work well at the command line terminal nor in most editors.
However, as @ColinAnthony notes, there are times (when dealing with shorter sequences) that no-line-wrapping FASTA files with exactly two lines per record have advantages.
digfish commentedon Nov 18, 2015
I'm working with reads with approximately 255 bp. I understand the motivation for having wrapping for reads with more than > 1000 bp.
I'm new in the Bioinformatics world, and I was thinking that the sequences (I'm talking on the specific case of FASTA) have the sequence length according to each model of sequencer. Yes, I'm doing downstream analysis, I have the need to select to filter out sequences and each time create a new FASTA file with only some sequences that I need and after I discovered this FASTA file formatting issued I started to avoid using the function SeqIO.write() for that and relying on a function made by me for writing the FASTA files.
I'm not against the wrapping: I just think that it does not have to be the default behaviour.
peterjc commentedon Nov 18, 2015
@digfish - I'd like to know more about this FASTA output problem you've had with
Bio.SeqIO.write(), could you file a separate issue for that please.Zsailer commentedon Nov 8, 2017
I'd like to avoid wrapping fasta output using the
SeqIO.writemethod as well. Why not float a**kwargsin theSeqIO.writemethod that is then passed to the writer classes as specific options for that format?peterjc commentedon Nov 8, 2017
@Zsailer this was a deliberate design choice to keep the main SeqIO API as simple and usable as possible. Would an output variant name of
fasta-nowrapor similar be acceptable?Zsailer commentedon Nov 8, 2017
@peterjc I completely agree with the design decision to make the API simple and usable. And don't get me wrong, I think this API great!
I guess my point was that adding
**kwargstoSeqIO.writeand passing it to whatever_FormatToWriterthe user specifies doesn't really add any extra complexity for the user or the API. Most users ignore it.I went ahead and created a branch to show what I mean. You can see it here.
You can see I just added **kwargs to lines 449 and 492 in
Bio.SeqIO.__init__.With this API, the user can add options to the each format.
I won't be offended if this doesn't go in 😉 . I think
fasta-nowrapis a fine solution as well.peterjc commentedon Nov 9, 2017
I agree the code change to enable
**kwargsis trivial, it is the implication of doing this which worries me. It suddenly massively expands the public API - documentation alone would be a mass of work. So I'm again going to be stubborn on this.Adding
fasta-nowrap(or similar) as an output variant format would solve what seems to be a relatively common use case, within the current API and naming approach. Do you fancy working on that instead? Again, the code changes should be quite small.Later we could also add this format-variant as an input format too (it would raise an exception if asked to parse multi-line FASTA files).
Zsailer commentedon Nov 9, 2017
Fair enough 👍
I've submitted PR #1450 adding this variant. Let me know what you think.
Thanks for your thoughts on this, @peterjc!
peterjc commentedon Dec 11, 2017
I started thinking about merging #1450 from @Zsailer and then how to implement the matching (strict) no-wrapping parser, and realised there is a choice here - do we really want a strict two-line-per-record FASTA variant here?
The distinction is about the corner case of zero-length records, which could be one line only (the
>line) or two lines (the>line and a blank sequence line). As written, the code would produce the two-line form on output.I think a strict two-line-per-record interpretation is much more useful as it allows more assumptions for high speed parsing and indexing.
If you agree, as part of adding a strict two-line-per-record FASTA parser, should I rename the proposed
fasta-nowrapformat variant tofasta-2line?(Something to keep in mind: Separately we might introduce
fastq-4lineorfastq-nowrapas an optimised version of the FASTQ parser)Zsailer commentedon Dec 11, 2017
@peterjc, renaming
fasta-nowraptofasta-2linemakes sense to me.I agree, a strict interpretation is better. As a user, I'd expect
fasta-2lineto produce two-line output even in a zero-record scenario. The output from afasta-nowrapsyntax in that scenario feels ambiguous.peterjc commentedon Dec 11, 2017
@Zsailer Good, we are in agreement. I added a few commits along these lines to #1450.
jvkersch commentedon Oct 4, 2018
I benefitted a lot from @Zsailer's patch to expose
fasta-2linebut now I have a similar question: would it make sense to expose another optionqual-2lineto output qual files in strict 2-line format? I have a pipeline with tools, some of which expect 2-line qual files. I monkey-patched my BioPython to add aQualPhredTwoLineWriteralong the lines of what was done in #1450, so for my use case I can get by, but if there's independent interest I (or someone else) can contribute this back.peterjc commentedon Oct 4, 2018
Hi Joris - I'm surprised to here anyone is still using qual files - I used to with Roche 454 data but that was some years back - I'd be curious to here more about the use case, and if it justifies adding this extra code. Would you mind opening an new issue about this proposal? Thanks!
Also I am belatedly closing this issue, the
fasta-2linesupport added in Biopython 1.71 addressed the original goal from Colin.