Skip to content

Instantly share code, notes, and snippets.

@necrolyte2
Last active February 9, 2016 20:07
Show Gist options
  • Select an option

  • Save necrolyte2/d8f62a337c9da9103fde to your computer and use it in GitHub Desktop.

Select an option

Save necrolyte2/d8f62a337c9da9103fde to your computer and use it in GitHub Desktop.
from Bio.SeqRecord import SeqRecord
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
"""
record = SeqRecord(
Seq("ATGC", IUPAC.ambiguous_dna),
id="id1",
name="id1name",
description="some description"
)
"""
from hypothesis import strategies as st
from hypothesis import find, note, given, assume
make_seqrec = lambda seq, quals: \
SeqRecord(Seq(seq, IUPAC.ambiguous_dna), id='id', description='', letter_annotations={'phred_quality':quals})
rec = make_seqrec('AAAA', [40,40,40,40])
assert rec.format('fastq') == '@id\nAAAA\n+\nIIII\n', rec.format('fastq')
recs = st.integers(min_value=10, max_value=50).flatmap(
lambda n:
st.builds(
lambda seq, quals:
SeqRecord(Seq(seq, IUPAC.ambiguous_dna), id='id', description='', letter_annotations={'phred_quality':quals}),
st.text(alphabet='ATGC', min_size=n, max_size=n),
st.lists(st.integers(min_value=0, max_value=40), min_size=n, max_size=n)
)
)
print recs.example()
@given(recs)
def test_records_work(rec):
#seq, qual = seqqual
seq = rec.seq
qual = rec.letter_annotations['phred_quality']
print 'Seq: %s\nQual: %s' % (seq, qual)
assume(set(seq) != set('A'))
assert False
test_records_work()
@necrolyte2
Copy link
Author

python hyprecord.py
ID: id
Name: <unknown name>
Number of features: 0
Per letter annotation for: phred_quality
Seq(u'GGGCGGCGCGGGCGGCGCGGCCGGGGCGCCCGCCGCCC', IUPACAmbiguousDNA())
Seq: AAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAA
Qual: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Seq: AAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAA
Qual: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Seq: AAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAA
Qual: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Seq: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Qual: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Falsifying example: test_records_work(rec=SeqRecord(seq=Seq(u'AAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAA', IUPACAmbiguousDNA()), id='id', name='<unknown name>', description='', dbxrefs=[]))
Seq: AAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAA
Qual: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Traceback (most recent call last):
  File "hyprecord.py", line 43, in <module>
    test_records_work()
  File "hyprecord.py", line 35, in test_records_work
    def test_records_work(rec):
  File "/home/tyghe/miniconda2/envs/bio/lib/python2.7/site-packages/hypothesis/core.py", line 713, in wrapped_test
    print_example=True, is_final=True
  File "/home/tyghe/miniconda2/envs/bio/lib/python2.7/site-packages/hypothesis/executors/executors.py", line 25, in default_executor
    return function()
  File "/home/tyghe/miniconda2/envs/bio/lib/python2.7/site-packages/hypothesis/core.py", line 376, in run
    return test(*args, **kwargs)
  File "hyprecord.py", line 41, in test_records_work
    assert False
AssertionError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment