コード例 #1
0
ファイル: align.py プロジェクト: Robbie1977/AlignmentPipe
def alignRec(record, template=template, bgfile='image_Ch1.nrrd', alignSet='', threshold=0.6):
    record = checkDir(record)
    record['last_host'] = host
    print 'Finalising alignment for: ' + record['name']
    # bgfile = record['original_nrrd'][('Ch' + str(record['background_channel']) + '_file')]
    record['aligned_bg'], r = cmtk.align(bgfile, template=template, settings=alignSet)
    record['aligned_avgslice_score'] = str(
        ci.rateOne(record['aligned_bg'], results=None, methord=slicescore.avgOverlapCoeff, template=template))
    record['aligned_slice_score'] = str(
        ci.rateOne(record['aligned_bg'], results=None, methord=slicescore.OverlapCoeff, template=template))
    record['aligned_score'] = str(
        np.mean([np.float128(record['aligned_avgslice_score']), np.float128(record['aligned_slice_score'])]))
    # Note: np.float128 array score converted to string as mongoDB only supports float(64/32 dependant on machine).
    record['aligned_bg'] = str(record['aligned_bg']).replace(tempfolder, '')
    print 'Result: ' + record['aligned_score']
    if record['aligned_score'] > threshold:
        record['alignment_stage'] = 6
        print 'Passed!'
    else:
        record['alignment_stage'] = 0
        print 'Failed!'
    if r > 0:
        print 'Error Code:' + str(r)
        record['alignment_stage'] = 0
    record['max_stage'] = 6
    return record
コード例 #2
0
ファイル: initial.py プロジェクト: Robbie1977/AlignmentPipe
def initialRec(record, template=template, init_threshold=0.3, bgfile='image_Ch1.nrrd', alignSet='',
               initialSet='--principal-axes'):
    start = datetime.datetime.now()
    record = checkDir(record)
    record['last_host'] = host
    print 'Staring initial alignment for: ' + record['name']
    # bgfile = record['original_nrrd'][('Ch' + str(record['background_channel']) + '_file')]
    record['temp_initial_nrrd'], r = cmtk.align(bgfile, cmtk.initial(bgfile, template=template, mode=initialSet)[0],
                                                imageOUT=tempfolder + record['name'] + '_initial.nrrd',
                                                template=template, settings=alignSet)
    record['temp_initial_score'] = str(ci.rateOne(record['temp_initial_nrrd'], results=None, template=template))
    # Note: np.float128 array score converted to string as mongoDB only supports float(64/32 dependant on machine).
    record['temp_initial_nrrd'] = str(record['temp_initial_nrrd']).replace(tempfolder, '')
    print 'Result: ' + record['temp_initial_score']
    totaltime = datetime.datetime.now() - start
    if record['temp_initial_score'] > init_threshold:
        record['alignment_stage'] = 3
    else:
        record['alignment_stage'] = 0
    if r > 0:
        record['alignment_stage'] = 1002
    else:
        if record['notes'] is None:
            record['notes'] = time.strftime(
                "%c") + ' Initial alignment performed by ' + host + ' in ' + str(totaltime) + ' scoring ' + record[
                                  'temp_initial_score'] + '/' + str(init_threshold)
        else:
            record['notes'] = record['notes'] + '\n' + time.strftime(
                "%c") + ' Initial alignment performed by ' + host + ' in ' + str(totaltime) + ' scoring ' + record[
                                  'temp_initial_score'] + '/' + str(init_threshold)
    record['max_stage'] = 3
    return record
コード例 #3
0
ファイル: align.py プロジェクト: Robbie1977/AlignmentPipe
def alignRem(record, template=template, chfile='image_Ch1.nrrd', alignSet=''):
    record = checkDir(record)
    print 'Aligning signal, etc. for: ' + record['name']
    record['last_host'] = host
    # bgfile = record['original_nrrd'][('Ch' + str(record['background_channel']) + '_file')]
    # sgfile = record['original_nrrd'][('Ch' + str(record['signal_channel']) + '_file')]
    # a=0
    # for i in range(1,6):
    # if not i == record['background_channel']:
    #   if i == record['signal_channel']:
    if record['ac1_channel'] < 1:
        for i in range(1, 4):
            print 'Checking for AC1 in channel ' + str(i)
            if not (i == int(record['signal_channel']) or i == int(record['background_channel'])):
                record['ac1_channel'] = i
                print 'Set AC1 Channel to ' + str(i)
    r = 0
    sgchan = '_Ch' + str(record['signal_channel'])
    bgchan = '_Ch' + str(record['background_channel'])
    acchan = '_Ch' + str(record['ac1_channel'])
    chfile = chfile.replace(bgchan, acchan).replace(acchan, sgchan)
    if os.path.isfile(chfile):
        record['aligned_sg'], r = cmtk.align(chfile, xform=chfile.replace(sgchan + '.nrrd', bgchan + '_warp.xform'),
                                             template=template, settings=alignSet)
        record['alignment_stage'] = 7
        record['max_stage'] = 7
        record['aligned_sg'] = str(record['aligned_sg']).replace(tempfolder, '')
    else:
        print chfile + ' not found'
        r = 5
    chfile = chfile.replace(sgchan, acchan)
    if os.path.isfile(chfile):
        record['aligned_ac1'], r = cmtk.align(chfile, xform=chfile.replace(acchan + '.nrrd', bgchan + '_warp.xform'),
                                              template=template, settings=alignSet)
        record['max_stage'] = 7
        record['aligned_ac1'] = str(record['aligned_ac1']).replace(tempfolder, '')
    else:
        print chfile + ' not found'

    if r > 0:
        print 'Error code:' + str(r)
        record['alignment_stage'] = 0
    return record