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
To address this issue, I do think it would be helpful to know what we plan to do about integer site positions. Do we have a consensus here? E.g. we could make a derived class, e.g. FiniteSitesTreeSequence as suggested by @petrelharp. If so we could store the site positions as true integers, or simply as floating point (and report them as integers). Alternatively, we could keep the same class, and have a flag in the metadata that tells us to interpret the existing floating point positions as integers. Other suggestions welcome too.
I'm hoping to get @dianalir to have a go at thinking about this soon, so comments very welcome, @jeromekelleher
I think the semantics are: if there is no reference sequence present (which there never is, right now; see #146 for discussion) we output the haplotypes as computed by the haplotypes() method. If there is a reference sequence, we use this to fill in the gaps between the variant sites.
But for now, I think it's clear: we just output the haplotypes.
OK. For the record, I think that it is quite misleading to concatenate together non-adjacent sites as adjacent letters in a FASTA file. The FASTA convention is (AFAIK) for letters to represent adjacent bases, and for potential gaps (of any length) to be represented by a -. So my eventual preference would be to output a set of non-adjacent sites something like:
A-T-T-C-G-... etc.
I do think that would be the least misleading and most standards-conformant output. Of course, once we have integer sites (and/or reference sequences: I don't think they are mutually dependent), then in some circumstances we could omit the - character between sites.
With non-integer site positions then there's no real meaning to 'between' them. We can add the padding behaviour later as an option, but I think the only reasonable thing to do for now is just output the haplotypes. It's up to the user to put in intermediate sites if they want them.
Hmmm, reading the fasta "specifications" available I'm coming around to @hyanwong's point of view. A "-" character does indicate a "gap of indeterminate length" in these, so it would be a good choice to (as Yan puts it) indicate that this is weird fasta data. I've definitely seen alignment programs that use "-" to indicate a gap of length exactly one though, so I wonder how well this is supported/interpreted.
It might be a good exercise to see what various libraries do when they are fed with fastas containing these characters. For example, what would Pysam and BioPython make of a FASTA string "-A-T-"?
It is common to allow both . and - for these sort of gaps, and the A2M format uses these to distinguish - as character to represent a missing state (i.e. used as an "alignment column"), and a period (.) to "represent insertion positions between alignment columns". The A2M docs also state that "The ... periods ... are only for human readability, and may be omitted."
So my suggestion is as follows (happy to change anything though)
The haplotypes() function is given an optional extra parameter, e.g. pad_sites, which, if true, inserts a single dot (not a dash) between sequence letters if the site positions are non-integer (and possibly if they are integer but are missing some integer positions). However, this parameter defaults to False, so that our current behaviour is unchanged. Since haplotypes() doesn't claim to be FASTA format, this is fine.
The write_fasta() function by default calls haplotypes(pad_sites=True), so that unlike haplotypes(), the default FASTA output does have dots between letters if the site positions are non-integer. We probably want the ability to turn this off, however - perhaps by having the function definition something like write_fasta(omit_site_padding=False).
Either way, we still indicate samples that have missing data at a particular site with a -, in both haplotypes() and write_fasta(). There is an argument that users of haplotypes() might want to turn this off, if they only want a single sample haplotype, and don't care about aligning. This is a bit of an edge-case, however, and could be incorporated later if indeed there is any call for it.
p.s. I'm happy to implement my suggestion above (or whatever modification of it we agree upon), if I get the go ahead, @jeromekelleher. I can do this today, tomorrow, or Fri.
Right, well this is looking like rather a lot more work than just quickly popping out a point release. I think we'll just have to undocument the fasta functionality for now, since it's controversial.
Yes, happy to work on this is there's agreement, with the understanding that it's pushed to 0.2.4. I think it's better to wait a little and get the format right, rather than end up having to support something that's not quite what we want.
With msprime 1.0 @igronau though, tree sequences with non-integer positions are going to become much rarer as by default everything will be done on a discrete genome (like most people expect, I think). No other program generates tree sequences with floating point positions AFAIK, so I think the simplest and most robust thing to do is just not bother with continuous coordinates and wrestling with what the semantics should be.
I'm happy to write a quick function to do what you're looking for on the current msprime output, if that would be helpful?
importmsprimeimportnumpyasnpts=msprime.simulate(10, length=20, mutation_rate=0.1)
encoding="ascii"S=np.zeros((ts.num_samples, int(ts.sequence_length)), dtype=np.int8)
pad_value=ord("-".encode(encoding))
S[:] =pad_valueforvariantints.variants():
assertlen(variant.alleles) ==2alleles=np.array(
[ord(allele.encode(encoding)) foralleleinvariant.alleles],
dtype=np.int8)
coord=int(variant.site.position)
ifS[0, coord] ==pad_value:
# This sites hasn't been seen before, so initialise it to the# ancestral stateS[:, coord] =alleles[0]
# Update the site with any derived statesderived_samples=variant.genotypes>0S[derived_samples, coord] =alleles[variant.genotypes[derived_samples]]
# print out the sequencesforsinS:
print(s.tobytes().decode(encoding))
I think we can probably resurrect this one now that discrete genome tree sequences are pretty common. My take is that we should
raise an exception if the tree sequence is not on a discrete genome
pad missing sites with some value.
I guess we need to make some decision about whether these are zero-or-one based coordinates too. I guess the best thing to do is see if we can round-trip the data from some fasta readers and do whatever padding we need to get this. Probably we'll have to add an option though, since I guess our coordinates are inherently zero based (since we can have a position at 0).
Activity
hyanwong commentedon Nov 19, 2019
To address this issue, I do think it would be helpful to know what we plan to do about integer site positions. Do we have a consensus here? E.g. we could make a derived class, e.g.
FiniteSitesTreeSequenceas suggested by @petrelharp. If so we could store the site positions as true integers, or simply as floating point (and report them as integers). Alternatively, we could keep the same class, and have a flag in the metadata that tells us to interpret the existing floating point positions as integers. Other suggestions welcome too.I'm hoping to get @dianalir to have a go at thinking about this soon, so comments very welcome, @jeromekelleher
jeromekelleher commentedon Nov 20, 2019
Integer site positions aren't necessary, I think.
I think the semantics are: if there is no reference sequence present (which there never is, right now; see #146 for discussion) we output the haplotypes as computed by the
haplotypes()method. If there is a reference sequence, we use this to fill in the gaps between the variant sites.But for now, I think it's clear: we just output the haplotypes.
hyanwong commentedon Nov 20, 2019
OK. For the record, I think that it is quite misleading to concatenate together non-adjacent sites as adjacent letters in a FASTA file. The FASTA convention is (AFAIK) for letters to represent adjacent bases, and for potential gaps (of any length) to be represented by a
-. So my eventual preference would be to output a set of non-adjacent sites something like:A-T-T-C-G-... etc.I do think that would be the least misleading and most standards-conformant output. Of course, once we have integer sites (and/or reference sequences: I don't think they are mutually dependent), then in some circumstances we could omit the
-character between sites.Perhaps I'm being too pernicketty, though?
hyanwong commentedon Nov 20, 2019
(I forgot that I wrote up my thoughts on this in #326 (comment))
jeromekelleher commentedon Nov 20, 2019
With non-integer site positions then there's no real meaning to 'between' them. We can add the padding behaviour later as an option, but I think the only reasonable thing to do for now is just output the haplotypes. It's up to the user to put in intermediate sites if they want them.
jeromekelleher commentedon Nov 20, 2019
Hmmm, reading the fasta "specifications" available I'm coming around to @hyanwong's point of view. A "-" character does indicate a "gap of indeterminate length" in these, so it would be a good choice to (as Yan puts it) indicate that this is weird fasta data. I've definitely seen alignment programs that use "-" to indicate a gap of length exactly one though, so I wonder how well this is supported/interpreted.
It might be a good exercise to see what various libraries do when they are fed with fastas containing these characters. For example, what would Pysam and BioPython make of a FASTA string "-A-T-"?
hyanwong commentedon Nov 20, 2019
It is common to allow both
.and-for these sort of gaps, and the A2M format uses these to distinguish-as character to represent a missing state (i.e. used as an "alignment column"), and a period (.) to "represent insertion positions between alignment columns". The A2M docs also state that "The ... periods ... are only for human readability, and may be omitted."So my suggestion is as follows (happy to change anything though)
The
haplotypes()function is given an optional extra parameter, e.g.pad_sites, which, if true, inserts a single dot (not a dash) between sequence letters if the site positions are non-integer (and possibly if they are integer but are missing some integer positions). However, this parameter defaults toFalse, so that our current behaviour is unchanged. Sincehaplotypes()doesn't claim to be FASTA format, this is fine.The
write_fasta()function by default callshaplotypes(pad_sites=True), so that unlikehaplotypes(), the default FASTA output does have dots between letters if the site positions are non-integer. We probably want the ability to turn this off, however - perhaps by having the function definition something likewrite_fasta(omit_site_padding=False).Either way, we still indicate samples that have missing data at a particular site with a
-, in bothhaplotypes()andwrite_fasta(). There is an argument that users ofhaplotypes()might want to turn this off, if they only want a single sample haplotype, and don't care about aligning. This is a bit of an edge-case, however, and could be incorporated later if indeed there is any call for it.hyanwong commentedon Nov 20, 2019
p.s. I'm happy to implement my suggestion above (or whatever modification of it we agree upon), if I get the go ahead, @jeromekelleher. I can do this today, tomorrow, or Fri.
jeromekelleher commentedon Nov 20, 2019
Right, well this is looking like rather a lot more work than just quickly popping out a point release. I think we'll just have to undocument the
fastafunctionality for now, since it's controversial.hyanwong commentedon Nov 21, 2019
Yes, happy to work on this is there's agreement, with the understanding that it's pushed to 0.2.4. I think it's better to wait a little and get the format right, rather than end up having to support something that's not quite what we want.
6 remaining items
jeromekelleher commentedon Dec 15, 2020
With msprime 1.0 @igronau though, tree sequences with non-integer positions are going to become much rarer as by default everything will be done on a discrete genome (like most people expect, I think). No other program generates tree sequences with floating point positions AFAIK, so I think the simplest and most robust thing to do is just not bother with continuous coordinates and wrestling with what the semantics should be.
I'm happy to write a quick function to do what you're looking for on the current msprime output, if that would be helpful?
igronau commentedon Dec 15, 2020
Yes @jeromekelleher , this would be very helpful.
jeromekelleher commentedon Dec 15, 2020
How's this @igronau?
gives:
It's easy enough to adapt to ACGT alleles, if you like. It's completely untested, so health warnings appy!
igronau commentedon Dec 15, 2020
Looks great! Thanks, @jeromekelleher.
jeromekelleher commentedon Oct 18, 2021
I think we can probably resurrect this one now that discrete genome tree sequences are pretty common. My take is that we should
I guess we need to make some decision about whether these are zero-or-one based coordinates too. I guess the best thing to do is see if we can round-trip the data from some fasta readers and do whatever padding we need to get this. Probably we'll have to add an option though, since I guess our coordinates are inherently zero based (since we can have a position at 0).
Update fasta implementation
Update fasta implementation
Update fasta implementation
Update fasta implementation
Update fasta implementation