Skip to content

Commit

Permalink
Address CR, add test for order, restyle
Browse files Browse the repository at this point in the history
  • Loading branch information
ihodes committed Dec 14, 2014
1 parent 2633498 commit e0a2c7e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
2 changes: 2 additions & 0 deletions common/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def order(lst, ordering, key=None):
lookup = lambda x: x
elif isinstance(key, basestring):
lookup = lambda x: x[key]
else: # the key is a function
lookup = key
ordering = {name: idx for idx, name in enumerate(ordering)}
lst.sort(key=lambda x: ordering[lookup(x)])
return lst
4 changes: 2 additions & 2 deletions common/relational_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def vcf_format(val):
if len(vals) <= 1:
return val
else: # It's a list.
assert v[0] == '['
assert v[-1] == ']'
assert val[0] == '['
assert val[-1] == ']'
return ','.join(v.strip() for v in vals)[1:-1]


Expand Down
24 changes: 9 additions & 15 deletions cycledash/genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ def spec(vcf_id):
ANNOTATIONS: {attrA: ...}}
"""
with tables(db, 'vcfs') as (con, vcfs):
q = select(
[vcfs.c.vcf_header, vcfs.c.extant_columns]
).where(vcfs.c.id == vcf_id)
q = (select([vcfs.c.vcf_header, vcfs.c.extant_columns])
.where(vcfs.c.id == vcf_id))
res = con.execute(q).fetchone()
return _header_spec(res['vcf_header'], res['extant_columns'])

Expand All @@ -50,13 +49,10 @@ def samples(vcf_id):
def contigs(vcf_id):
"""Return a sorted list of contig names found in the given vcf."""
with tables(db, 'genotypes') as (con, genotypes):
q = select(
[genotypes.c.contig]
).where(
genotypes.c.vcf_id == vcf_id
).group_by(
genotypes.c.contig
).order_by(func.length(genotypes.c.contig), genotypes.c.contig)
q = (select([genotypes.c.contig])
.where(genotypes.c.vcf_id == vcf_id)
.group_by(genotypes.c.contig)
.order_by(func.length(genotypes.c.contig), genotypes.c.contig))
results = con.execute(q).fetchall()
return [contig for (contig,) in results]

Expand Down Expand Up @@ -287,11 +283,9 @@ def vcf_type_to_sqla_type(column_type='integer'):

def derive_truth_vcf_id(dataset_name):
with tables(db, 'vcfs') as (con, vcfs):
truth_vcf_q = select(
[vcfs.c.id]
).where(
vcfs.c.validation_vcf == True
).where(vcfs.c.dataset_name == dataset_name)
truth_vcf_q = (select([vcfs.c.id])
.where(vcfs.c.validation_vcf == True)
.where(vcfs.c.dataset_name == dataset_name))
truth_vcf_rel = con.execute(truth_vcf_q).fetchone()
if truth_vcf_rel:
return truth_vcf_rel.id
Expand Down
4 changes: 2 additions & 2 deletions cycledash/static/css/examine.css
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ a.download-vcf {
color: #6d6d6d;
font-size: 0.92em;
text-decoration: none;
padding-left: 23px;
background: url(/static/img/noun_4501.svg) no-repeat 3px 2px;
padding-left: 38px;
background: url(/static/img/noun_4501.svg) no-repeat 11px 2px;
background-size: 15px 15px;
opacity: 0.55;
}
2 changes: 1 addition & 1 deletion cycledash/static/js/examine/components/Downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var Downloads = React.createClass({
query: React.PropTypes.object
},
render: function() {
var jsonQuery = JSON.stringify(this.props.query),
var jsonQuery = encodeURIComponent(JSON.stringify(this.props.query)),
link = `/runs/${this.props.run_id}/download?query=${jsonQuery}`;
return <a className='download-vcf' href={link}>Download VCF</a>;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/python/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nose

from common.helpers import order
from cycledash.helpers import underscorize
from common.relational_vcf import vcf_to_csv

Expand Down Expand Up @@ -29,3 +30,15 @@ def test_vcf_to_csv():
assert rows[0] == ['44', '', '81', 'True']
assert rows[-1] == ['40', '', '74', 'True']
assert len(rows) == 20


def test_order():
o1 = order([132, 99, 22], ordering=[99, 22, 44, 132])
o2 = order([{'thing': 'bathrobe'}, {'thing': 'toga'}],
['toga', 'bathrobe'], key='thing')
o3 = order([2,4,1,4],
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16], key=lambda x: x * x)

assert o1 == [99, 22, 132]
assert o2 == [{'thing': 'toga'}, {'thing': 'bathrobe'}]
assert o3 == [1, 2, 4, 4]

0 comments on commit e0a2c7e

Please sign in to comment.