Comments (6)
Since it's returning an iterator I don't think there's any point in trying to be clever, just a simple loop is the right way to go. From the stdpopsim perspective this is fine, because it wants to iterate over the intervals and do Python stuff to them.
from tskit.
Since it's returning an iterator I don't think there's any point in trying to be clever
I agree with this, but if you did want to be clever with numpy, here's how to pre-compute the relevant things:
rm1 = msprime.RateMap(position=[0, 10], rate=[1.0])
rm2 = msprime.RateMap(position=[0, 3, 10], rate=[4.0, 5])
rm_list = [rm1, rm2]
pos = np.unique(np.concatenate([rm.position for rm in rm_list]))
rates = np.array([rm.rate[np.searchsorted(rm.position[:-1], pos, side='right') - 1] for rm in rm_list])
for k in range(len(pos)-1):
print(f"segment {k}: {pos[k]} to {pos[k+1]} - rates {rates[:,k]}")
from tskit.
from tskit.
I would volunteer to implement this, except I can't think of a clever way to do this in numpy. I've run across this exact problem many times and always end up doing a dumb/slow for loop. If anyone has any ideas on how to use numpy vectorized tricks to do that let me know and I can implement it.
from tskit.
It would be nice to be able to define a RateMap with left and right intervals so that it automatically converts to the breakpoints representation. Or is this sth we want to do within stdpopsim?
from tskit.
It would be nice to be able to define a RateMap with left and right intervals so that it automatically converts to the breakpoints representation. Or is this sth we want to do within stdpopsim?]
This is a separate issue - can you open one to track with an example of what you'd like to see?
from tskit.
Related Issues (20)
- Add IO methods for RateMap
- Reinstate check for chromosome name in read_hapmap
- “Edit on GitHub” link missing from tskit docs
- Can I get a list of descendants of a branch (edge)? HOT 11
- extend edges misses some extendable edges
- Sample_sets incorrect in genetic_relatedness_matrix HOT 7
- Document genetic_relatedness_matrix
- Document divergence_matrix
- More flexible interpretation of mutation rate when getting emission probability when using `_tskit.lshmm` HOT 4
- C API for numpy 2.0 HOT 4
- Numpy 2.0 Python HOT 5
- Add support for MRCA based IBD HOT 2
- Documentation for IBD segments
- write_vcf should use the reference sequence for REF, if present
- Number of variable sites (not just num_sites) HOT 1
- Add 'mid' property to Interval class
- Simpler, more efficient interface for pair coalescence rates HOT 6
- clarity on use of tskit.union() HOT 4
- Should 2-locus ratio statistics return NaN on 0/0? HOT 4
- Installing tskit on Windows HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tskit.