from sklearn.preprocessing import OneHotEncoder import logging import numpy as np import pandas as pd import os import json import re import torch import collections # from models import reader from models.ScheduleOptimizer import ScheduledOptim print(os.path.dirname(__file__)) # ====================| some path |======================= global script_dir global data_dir global log_dir global pth_dir # global cell_lines global egfp_seq with open(os.path.join(os.path.dirname(__file__),"machine_configure.json"),'r') as f: config = json.load(f) script_dir = config['script_dir'] data_dir = config['data_dir'] log_dir = config['log_dir'] pth_dir = config['pth_dir'] # =====================| one hot encode |======================= class Seq_one_hot(object): def __init__(self,seq_type='nn',seq_len=100): """ initiate the sequence one hot encoder """ self.seq_len=seq_len self.seq_type =seq_type self.enable_encoder() def enable_encoder(self): if self.seq_type == 'nn': self.encoder = OneHotEncoder(sparse=False) self.encoder.drop_idx_ = None self.encoder.categories_ = [np.array(['A', 'C', 'G', 'T'], dtype='>>============== \t \t ') info(" \t"+popen.vae_pth_path) return model def get_config_cuda(config_file): with open(config_file,'r') as f: lines = f.read_lines() for line in lines: if "cuda_id =" in line: device = line.split("=")[1].strip() break device = int(device) if device.isdigit() else device return device def resume(popen,optimizer,logger): """ for a experiment, check whether it;s a new run, and create dir """ #run_name = model_stype + time.strftime("__%Y_%m_%d_%H:%M")) if popen.Resumable: checkpoint = torch.load(popen.vae_pth_path, map_location=torch.device('cpu')) # xx-model-best.pth previous_epoch = checkpoint['epoch'] previous_loss = checkpoint['validation_loss'] previous_acc = checkpoint['validation_acc'] # very important if (type(optimizer) == ScheduledOptim): optimizer.n_current_steps = popen.n_current_steps optimizer.delta = popen.delta logger.info(" \t \t ========================================================= \t \t ") logger.info(' \t \t ==============<<< Resume from checkpoint>>>============== \t \t \n') logger.info(" \t"+popen.vae_pth_path+'\n') logger.info(" \t \t ========================================================= \t \t \n") return previous_epoch,previous_loss,previous_acc egfp_seq = "atgggcgaattaagtaagggcgaggagctgttcaccggggtggtgcccatcctggtcgagctggacggcgacgtaaacggccacaagttcagcgtgtccggcgagggcgagggcgatgccacctacggcaagctgaccctgaagttcatctgcaccaccggcaagctgcccgtgccctggcccaccctcgtgaccaccctgacctacggcgtgcagtgcttcagccgctaccccgaccacatgaagcagcacgacttcttcaagtccgccatgcccgaaggctacgtccaggagcgcaccatcttct" eGFP_seq = egfp_seq.upper()