def test_compile_dna_rvd_mix(self): """ Compile DNA and RVD mixture. """ text = pfusx.compile('NI NN NN NN HD NG NI NI NG NN NI NG NI NN NG', 'ATACCGTCTTATTTT') json.loads(text)
def compile(text=None): """ Send provided code to the designated compiler and outputs a JSON object detailing success or failure. Success looks like: { "success": true, "compiled_url": "http://example.com/rendered/foo.json", "return_data": {"description":"A1: atcgtactgatc"} } Failure looks like: { "success": false, "errors": ["First input should be different."] } Errors can be output to the user and vary by compiler. They're often related to specific Mix.Bio form fields. """ text = request.args.get('input').strip().split('\n') if not text: return "handle_response(" + json.dumps({ 'success': False, 'errors': ["No input provided."] }) + ")" # Compile the protocol, return any errors. try: protocol = pfusx.compile(*text) except Exception as e: return "handle_response(" + json.dumps({ 'success': False, 'errors': [str(e)] }) + ")" description = json.loads(protocol)["info"]["description"] # Save the data as a hash in the public dir where it can be downloaded. content_hash = hashlib.sha224(protocol.encode('utf-8')).hexdigest() fpath = os.path.dirname(os.path.realpath(__file__)) + "/static/protocols/" fname = "ot_one_" + content_hash + ".json" with open(fpath + fname, 'w') as f: f.write(protocol) output = { "success": True, "filename": 'https://api.mix.bio/static/protocols/' + fname, "return_data": { "description": description } } return "handle_response(" + json.dumps(output) + ")"
def test_compile_dna_rvd_mix(self): """ Compile DNA and RVD mixture. """ text = pfusx.compile( 'NI NN NN NN HD NG NI NI NG NN NI NG NI NN NG', 'ATACCGTCTTATTTT' ) json.loads(text)
def test_compile_invalid_sequence(self): """ Compiler validates input. """ with self.assertRaises(ValueError): pfusx.compile("Cats with laser eyes.")
def test_compile_short_dna_input(self): """ Compiler should return error on short input. """ with self.assertRaises(ValueError): pfusx.compile('GATTACA')
def test_compile_multi_dna(self): """ Should compile multiple DNA sequences. """ text = pfusx.compile('ATACCGTCTTATTTT', 'ATACCGTCTTATTTA') json.loads(text)
def test_compile_dna(self): """ Should compile single DNA sequence. """ text = pfusx.compile('ATACCGTCTTATTTT') json.loads(text)