Пример #1
0
def get_L1_templates(L1_cols, step_choose, template_path, model_path):
    '''
    descript:
        将词列数据和分词列数据组合使用,按不同的特征函数的数量创建L1模板,
        对不同的模板用 template_L1_w:i_s:j 命名
        上面的 :i = 5|7|10, 对应特征函数数量
        上面的 :j = 0|5|7|10, 对应特征函数数量

    return:
        返回模板名列表
    '''
    time = 0
    template_list = []  #存储模板文件名的列表

    # 只用word,没用分词
    for i in step_choose:
        type = 'L1_w' + str(i) + '_s0'
        time += 1
        name = 'template_' + type + '_' + str(time)
        unigram = [(0, i)]
        create_template.create_template(type, time, unigram)  #创建模板
        template_list.append(name)

    # 用word和分词的数据
    for i in step_choose:
        for j in step_choose:
            type = 'L1_w' + str(i) + '_s' + str(j)
            time += 1
            name = 'template_' + type + '_' + str(time)
            unigram = [(0, i), (1, j), (2, j)]
            create_template.create_template(type, time, unigram)  #创建模板
            template_list.append(name)

    return template_list
Пример #2
0
    def templates(self):

        plates = raw_input('Do you need to create templates? (y/n): ')
        if plates == 'y':
            create_template()
        else:
            pass
Пример #3
0
def main():
  # parse args
  opts = parse_args()
  
  # get current absolute path
  wd = make_abs_path(opts.project_name)

  # insert template
  create_template(opts)

  # chnage directory
  os.chdir(wd)

  # # make virtual environment
  # mkvirtualenv(opts.project_name)

  # initialize git repository
  git_init()
  #workon(opts.project_name)
  print "DONE: Your new python project and git repo have been created in '%s/'" % opts.project_name
Пример #4
0
def setup_template(templates_link,
                   template_file_path,
                   template_name='Untitled template'):
    template, headers = create_template(templates_link,
                                        template_file_path.split('.')[-1],
                                        template_name)
    template_link = template['links']['self']
    image_link = headers['Location']
    print(f'Successfully created template at {template_link}')
    upload_image(image_link, template_file_path)
    print(f'Successfully uploaded image {template_file_path} at {image_link}')

    return template
Пример #5
0
def main(variant_alias_file, output, images, xlsx, sheet, pdf):
    ''' For each variant alias, extract the approriate variant and mutation
        information and export as a variant confirmation report.
        
        variant_alias_file: should be in a text file where each new line
                            contains a different variant alias or a single
                            variant alias.
    '''
    
    # intialise 2 objects using All_Variants & Mutation ID sheets
    extract = ExtractInfo(xlsx, sheet, 2)    

    # open the All_Variants and Mutation ID sheet
    variant_sheet = extract.open_spreadsheets()

    # use the headers of the above workbooks to create a header dicts
    create_variant_dict = extract.create_header_dicts(variant_sheet)

    # create a template report
    create_template(output)
    
    # for each variant alias...

    variant_list = [var_alias for var_alias in open(variant_alias_file, "r")]

    for var_alias in tqdm.tqdm(variant_list):
        var_alias = var_alias.rstrip("\n")
        
        # Open template every iteration, otherwise information leftover from last 
        # iter in cells
        template = openpyxl.load_workbook("test_template.xlsx")
        template_sheet = template.worksheets[0]
    
        # extract variant information from spreadsheet
        variant_row = extract.get_row(variant_sheet, var_alias)
        variant_info = extract.get_query_info(variant_row,variant_sheet)
        
        # get the completed header dictionarys
        variant_dict = extract.header_contents
        
        # with the collected information, fill out the template report. 
        Fill = FillReport(template, template_sheet, var_alias, variant_dict, images)
        Fill.fill_report()
       

        # insert sanger trace and IGV image into the report
        Fill.insert_image(var_alias+"_F", "B22", 600, 242)
        Fill.insert_image(var_alias+"_R", "B22", 600, 242)
        Fill.insert_image(var_alias+"_IGV", "B35", 600, 242)

        
        # get mutation information for the given variant alias if an ID is there
        Fill.pick_comment()

        #print("\t".join((var_alias,variant_dict.get("Category"),
                        # variant_dict.get("Mutation_ID"))))

        output_name = (output+str(variant_dict.get("Sample_Name"))+
                            "_"+str(variant_dict.get("Variant_Alias"))+"_"+
                            "VariantConfirmationReport"+".xlsx")

        # save the filled sheet and convert to PDF
        template.save(output_name)
        if pdf:
            Fill.convert2pdf(output_name)
        
        # clear the dicts items
        variant_dict = {key: "-" for key in variant_dict}
if __name__ == "__main__":
    
    (inputs, success) = read_inputs()
    num_subjects = len(inputs)
    if success:      
        print("Starting processing")
        for a, subject in enumerate(inputs):
            # print("Processing ", subject,"|| overall Progress -->  {0: >3} % done".format(((a+1)/num_subjects)*100))
            images = inputs[subject]["images"]
            results = inputs[subject]["results"]
            templates = inputs[subject]["templates"]
            templates = [cv.imread(template_path, 0) for template_path in templates]
            T = []
            for template in templates:
                T += create_template(template)
             
            for i, image_path in enumerate(images):
                print("Processing ", subject,"||  Progress -->  {0: >3} % done".format(((i+1)/len(images))*100))

                image = cv.imread(i age_path)
                img_gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
                probablity_maps = template_matching(img_gray, templates, threshold=0.7)
                points = []
                for temp_maps in probablity_maps:
                    for point in temp_maps:
                        points.append(point)
                points = NMS(points)
                for pt in points:
                    [xi, yi, ci, hi, wi] = pt
                    cv.rectangle(image, (xi, yi), (xi + wi, yi + hi), (0,0,255), 1)                
Пример #7
0
def main(variant_alias_file, output, images, xlsx, sheet, pdf):
    ''' For each variant alias, extract the approriate variant and mutation
        information and export as a variant confirmation report.
        
        variant_alias_file: should be in a text file where each new line
                            contains a different variant alias or a single
                            variant alias.
    '''

    # intialise 2 objects using All_Variants & Mutation ID sheets
    extract = ExtractInfo(xlsx, sheet, 2)

    # open the All_Variants and Mutation ID sheet
    variant_sheet = extract.open_spreadsheets()

    # use the headers of the above workbooks to create a header dicts
    create_variant_dict = extract.create_header_dicts(variant_sheet)

    # create a template report
    create_template(output)

    # for each variant alias...

    variant_list = [var_alias for var_alias in open(variant_alias_file, "r")]

    for var_alias in tqdm.tqdm(variant_list):
        var_alias = var_alias.rstrip("\n")

        # Open template every iteration, otherwise information leftover from last
        # iter in cells
        template = openpyxl.load_workbook("test_template.xlsx")
        template_sheet = template.worksheets[0]

        # extract variant information from spreadsheet
        variant_row = extract.get_row(variant_sheet, var_alias)
        variant_info = extract.get_query_info(variant_row, variant_sheet)

        # get the completed header dictionarys
        variant_dict = extract.header_contents

        # with the collected information, fill out the template report.
        Fill = FillReport(template, template_sheet, var_alias, variant_dict,
                          images)
        Fill.fill_report()

        # insert sanger trace and IGV image into the report
        Fill.insert_image(var_alias + "_F", "B22", 600, 242)
        Fill.insert_image(var_alias + "_R", "B22", 600, 242)
        Fill.insert_image(var_alias + "_IGV", "B35", 600, 242)

        # get mutation information for the given variant alias if an ID is there
        Fill.pick_comment()

        #print("\t".join((var_alias,variant_dict.get("Category"),
        # variant_dict.get("Mutation_ID"))))

        output_name = (output + str(variant_dict.get("Sample_Name")) + "_" +
                       str(variant_dict.get("Variant_Alias")) + "_" +
                       "VariantConfirmationReport" + ".xlsx")

        # save the filled sheet and convert to PDF
        template.save(output_name)
        if pdf:
            Fill.convert2pdf(output_name)

        # clear the dicts items
        variant_dict = {key: "-" for key in variant_dict}