Ejemplo n.º 1
0
def bet(record):
    import nipype
    from nipype.interfaces.fsl import BET
    from nipype.utils.filemanip import hash_infile

    nipype.config.enable_provenance()

    in_file_uri = record['t1_uri']
    os.chdir('/tmp')
    fname = 'anatomy.nii.gz'

    with open(fname, 'wb') as fd:
        response = requests.get(in_file_uri, stream=True)
        if not response.ok:
            response.raise_for_status()
        for chunk in response.iter_content(1024):
            fd.write(chunk)

    # Check if interface has run with this input before
    sha = hash_infile(os.path.abspath(fname), crypto=hashlib.sha512)
    select = SelectQuery(config=app.config)
    res = select.execute_select('E0921842-1EDB-49F8-A4B3-BA51B85AD407')
    sha_recs = res[res.sha512.str.contains(sha)]
    bet_recs = res[res.interface.str.contains('BET')]
    results = dict()
    if sha_recs.empty or \
            (not sha_recs.empty and bet_recs.empty):
        better = BET()
        better.inputs.in_file = os.path.abspath(fname)
        result = better.run()
        prov = result.provenance.rdf().serialize(format='json-ld')
        results.update({'prov': prov})
    else:
        results.update({'prov': res.to_json(orient='records')})
    return results
Ejemplo n.º 2
0
 def post(self):
     args = parser.parse_args()
     result = []
     select = SelectQuery()
     df = select.execute_select(args['query_uuid'],
                                turtle_str=args['turtle_file'])
     for record in df.to_dict(outtype='records'):
         task_id = record['task']
         task = celery.tasks[task_id]
         res = task.apply_async([record])
         record.update({"task_id": res.task_id})
         result.append(record)
     return result
Ejemplo n.º 3
0
class SelectQueryTestCase(unittest.TestCase):

    def setUp(self):
        self.query = SelectQuery()

    def test_init(self):
        self.assertIsInstance(self.query, SelectQuery)
        self.assertGreater(len(self.query.sparql_meta), 0)

    def test_execute_select(self):
        res = self.query.execute_select(0)
        self.assertIsInstance(res, pd.DataFrame)
Ejemplo n.º 4
0
 def setUp(self):
     self.query = SelectQuery()