``bt.SampleIds.index`` is a list lookup and is O(n). Use ``bt.getSampleIndex``

Also, while dict and list comprehensions are cute, it is very easy to abuse them and make difficult to read code. Expand out these forloops. Remember that the comprehension are syntactic sugar, and are not a performance benefit. They can make code more succinct and improve readability, but also can make it much more challenging to read