forked from primasanjaya/muat-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
672 lines (521 loc) · 30.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
# make deterministic
from models.utils import set_seed
set_seed(42)
#frompc
import numpy as np
import torch
import torch.nn as nn
from torch.nn import functional as F
import math
from torch.utils.data import Dataset
from models.model import *
from models.trainer import *
from models.predict import *
from models.utils import sample
import logging
logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
datefmt="%m/%d/%Y %H:%M:%S",
level=logging.INFO,
)
import pdb
from dataset.pcawgtcga_dataloader import TCGAPCAWG_Dataloader
from dataset.singlepredictvcf import SinglePredictVCF
from dataset.predictfolder_dataset import *
from preprocessing.dmm.dmm import *
from preprocessing.fromvcffiles import *
from preprocessing.dmm.preprocess3 import *
from preprocessing.dmm.annotate_mutations_all import *
from preprocessing.dmm.annotate_mutations_all_modified import *
from models.utils import *
import argparse
import os
import pandas as pd
import subprocess
def get_args():
parser = argparse.ArgumentParser(description='PCAWG / TCGA experiment')
# DATASET
parser.add_argument('--cwd', type=str,help='project dir')
parser.add_argument('--dataloader', type=str, default='pcawg',
help='dataloader setup, option: pcawg or tcga')
# MODEL
parser.add_argument('--arch', type=str, default=None,
help='architecture')
# DIRECTORY
#INPUT DATA
parser.add_argument('--input-data-dir', type=str, default=None,
help='input data directory')
parser.add_argument('--input-crossdata-dir', type=str, default=None,
help='output data directory')
parser.add_argument('--input-newdata-dir', type=str, default=None,
help='input new data directory')
parser.add_argument('--gx-dir', type=str, default=None,
help='input gene expression data')
parser.add_argument('--predict-filepath', type=str, default=None,
help='all samples paths that will be predicted')
parser.add_argument('--predict-inputlist', type=list)
#OUTPUT DATA
parser.add_argument('--output-train-dir', type=str, default=None,
help='output data directory')
parser.add_argument('--output-crossdata-dir', type=str, default=None,
help='output cross data directory')
parser.add_argument('--output-newdata-dir', type=str, default=None,
help='output new data directory')
parser.add_argument('--tmp-dir', type=str, default=None,
help='temporary data directory')
parser.add_argument('--output-prefix', type=str, default=None,
help='prefix of output data')
parser.add_argument('--output-pred-dir', type=str, default=None,
help='output of prediction directory')
parser.add_argument('--output-pred-file', type=str, default=None,
help='output prediction file')
parser.add_argument('--output-pred-filename', type=str, default=None,
help='output prediction filename')
# FILENAMES
parser.add_argument('--input-filename', type=str, default=None,
help='input filename')
parser.add_argument('--input-file', type=str, default=None,
help='input file')
parser.add_argument('--output-filename', type=str, default=None,
help='output filename')
parser.add_argument('--output-file', type=str, default=None,
help='output file')
parser.add_argument('--trainsplit-file', type=str, default=None,
help='train and validation file split')
parser.add_argument('--valsplit-file', type=str, default=None,
help='train and validation file split')
parser.add_argument('--classinfo-file', type=str, default=None,
help='class info file')
#CKPT SAVE
parser.add_argument('--save-ckpt-dir', type=str, default=None,
help='save checkpoint dir')
parser.add_argument('--save-ckpt-filename', type=str, default=None,
help='save checkpoint filename')
#CKPT LOAD
parser.add_argument('--load-ckpt-dir', type=str, default=None,
help='load checkpoint dir')
parser.add_argument('--load-ckpt-filename', type=str, default=None,
help='load checkpoint filename')
parser.add_argument('--load-ckpt-file', type=str, default=None,
help='load checkpoint complete path file')
# HYPER PARAMS
parser.add_argument('--epoch', type=int, default=1,
help='number of epoch')
parser.add_argument('--l-rate', type=float, default=6e-4,
help='learning rate')
parser.add_argument('--n-class', type=int, default=None,
help='number of class')
parser.add_argument('--batch-size', type=int, default=1,
help='batch size')
parser.add_argument('--block-size', type=int, default=1000,
help='block of sequence')
parser.add_argument('--context-length', type=int, default=3,
help='length of sequence')
parser.add_argument('--n-layer', type=int, default=1,
help='attention layer')
parser.add_argument('--n-head', type=int, default=8,
help='attention head')
parser.add_argument('--n-emb', type=int, default=128,
help='embedding dimension')
parser.add_argument('--tag', type=str, default='myexperiment',
help='tensorboardX tag')
parser.add_argument('--fold', type=int, default=1,
help='fold')
parser.add_argument('--epi-emb', type=int, default=2,
help='epigenetic embedding')
#EXECUTION
parser.add_argument('--train', action='store_true', default=False,
help='execute training')
parser.add_argument('--generative', action='store_true', default=False,
help='execute generative training (dimensional reduction)')
parser.add_argument('--predict', action='store_true', default=False,
help='execute prediction')
parser.add_argument('--predict-new-data', action='store_true', default=False,
help='execute prediction from new data (PCAWG training-ready format)')
parser.add_argument('--single-pred-vcf', action='store_true', default=False)
parser.add_argument('--multi-pred-vcf', action='store_true', default=False)
parser.add_argument('--get-motif', action='store_true', default=False)
parser.add_argument('--get-position', action='store_true', default=False)
parser.add_argument('--get-ges', action='store_true', default=False)
parser.add_argument('--get-epi', action='store_true', default=False)
parser.add_argument('--motif', action='store_true', default=False)
parser.add_argument('--motif-pos', action='store_true', default=False)
parser.add_argument('--motif-pos-ges', action='store_true', default=False)
parser.add_argument('--motif-pos-ges-epi', action='store_true', default=False)
parser.add_argument('--ensemble', action='store_true', default=False)
parser.add_argument('--predict-all', action='store_true', default=False)
parser.add_argument('--get-features', action='store_true', default=False)
parser.add_argument('--num-mut', type=int, default=0,
help='sampling number of mutation')
parser.add_argument('--frac', type=float, default=0,
help='sampling number of mutation based on data fraction')
parser.add_argument('--mut-type', type=str, default='',
help='mutation type, only [SNV,SNV+MNV,SNV+MNV+indel,SNV+MNV+indel+SV/MEI,SNV+MNV+indel+SV/MEI+Neg] can be applied')
parser.add_argument('--mutratio', type=str, default=None,
help='mutation ratio per mutation type, sum of them must be one')
parser.add_argument('--vis-attention', type=str, default='',
help='visualize attention values')
parser.add_argument('--genomic-tracks', type=str, default=None,
help='Genomic tracks directory')
parser.add_argument('--convert-hg38-hg19',action='store_true', default=False)
parser.add_argument('--vcf42',action='store_true', default=False)
parser.add_argument('--vcf41',action='store_true', default=False)
parser.add_argument('--gel',action='store_true', default=False)
#dmm_parser
parser.add_argument('-v', '--verbose', type=int, help='Try to be more verbose')
parser.add_argument('--mutation-coding', type=int, default=None,
help='Mutation coding table ("ref alt code"/line)')
parser.add_argument('--config', help='Read parameters from a JSON file')
parser.add_argument('--data-config',
help='Column specification for --input, --validation and --aux-data [{}]')
parser.add_argument('--random-seed', default=None, type=int, metavar='seed')
parser.add_argument('--tmp')
parser.add_argument('-i', '--input', action='append', metavar='dir(s)',
help='Either a directory with vcf/maf[.gz] files or a vcf/maf[.gz] file (-i may be given more than once)')
parser.add_argument('-o', '--output', metavar='fn', help='Preprocessed mutation data')
parser.add_argument('-r', '--reference', metavar='ref', help='Reference genome (fasta) [{}]')
parser.add_argument('-re', '--reference-h19', metavar='ref', help='Reference genome (fasta) [{}]')
parser.add_argument('-rt', '--reference-h38', metavar='ref', help='Reference genome (fasta) [{}]')
parser.add_argument('-k', '--context', help='Sequence context length (power of 2) [{}]', metavar='bp', type=int,default=8)
parser.add_argument('-e', '--errors', metavar='fn',
help='File where to log errors [{}]')
parser.add_argument('--no-ref-preload', help='Use samtools to read reference on demand (slow but fast startup) [false]',
action='store_true')
parser.add_argument('--no-filter', help='Process all variants [default=only PASS/. variants]',
action='store_true')
parser.add_argument('--sample-id', help='Sample identifier column name in MAF file')
parser.add_argument('-n', '--generate_negatives', help='Ratio of negative to positive examples [{}]. Two passes on data are required for n>0.', type=float)
parser.add_argument('--median-variant-type-negatives', action='store_true',
help='Generate median number of each variant type as negative examples for each sample')
parser.add_argument('--median-variant-type-file', help='Load median variant numbers from a file')
parser.add_argument('--negative-generation-mode', help='[generate] output in one go (default), [augment] input files or [process] augmented files', default='generate')
parser.add_argument('--info-column', help='Input column name to write toutputo output (MAF input only). May be specified more than once.', action='append')
parser.add_argument('--report-interval', help='Interval to report number of variants processed',
type=int)
parser.add_argument('--array-jobs', help='How many array jobs in total', type=int)
parser.add_argument('--array-index', help='Index of this job', type=int)
parser.add_argument('--nope', help='Only one variant per output sequence', action='store_true')
parser.add_argument('--no-overwrite', help='Do not overwrite if output exists', action='store_true')
args = parser.parse_args()
return args
def execute_annotation(args,only_input_filename):
#gc content
syntax_gc = 'python3 preprocessing/dmm/annotate_mutations_with_gc_content.py \
-i ' + args.tmp_dir + only_input_filename + '.tsv.gz \
-o ' + args.tmp_dir + only_input_filename + '.gc.tsv.gz \
-n 1001 \
-l gc1kb \
--reference ' + args.reference + ' \
--verbose'
subprocess.run(syntax_gc, shell=True)
os.remove(args.tmp_dir + only_input_filename + '.tsv.gz')
pdb.set_trace()
if args.convert_hg38_hg19:
from pyliftover import LiftOver
#lo = LiftOver('/mnt/g/experiment/redo_muat/muat-github/preprocessing/genomic_tracks/hg38ToHg19.over.chain.gz')
#lo = LiftOver('/genomic_tracks/GRCh37_to_GRCh38.chain.gz')
lo = LiftOver('hg38', 'hg19')
pd_hg38 = pd.read_csv(args.tmp_dir + only_input_filename + '.gc.tsv.gz',sep='\t',low_memory=False)
chrom_pos = []
for i in range(len(pd_hg38)):
try:
row = pd_hg38.iloc[i]
chrom = str('chr') + str(row['chrom'])
pos = row['pos']
ref = row['ref']
alt = row['alt']
sample = row['sample']
seq = row['seq']
gc1kb = row['gc1kb']
hg19chrompos = lo.convert_coordinate(chrom, pos)
chrom = hg19chrompos[0][0][3:]
pos = hg19chrompos[0][1]
chrom_pos.append((chrom,pos,ref,alt,sample,seq,gc1kb))
except:
pass
pd_hg19 = pd.DataFrame(chrom_pos)
pd_hg19.columns = pd_hg38.columns.tolist()
pd_hg38.to_csv(args.tmp_dir + only_input_filename + '.gc.tsv.gz',sep='\t',index=False, compression="gzip")
# Genic regions
syntax_genic = 'preprocessing/dmm/annotate_mutations_with_bed.sh \
' + args.tmp_dir + only_input_filename + '.gc.tsv.gz \
' + args.genomic_tracks + 'Homo_sapiens.GRCh37.87.genic.genomic.bed.gz \
'+ args.tmp_dir + only_input_filename + '.gc.genic.tsv.gz \
genic'
subprocess.run(syntax_genic, shell=True)
os.remove(args.tmp_dir + only_input_filename + '.gc.tsv.gz')
#exon regions
syntax_exonic = 'preprocessing/dmm/annotate_mutations_with_bed.sh \
' + args.tmp_dir + only_input_filename + '.gc.genic.tsv.gz \
' + args.genomic_tracks + 'Homo_sapiens.GRCh37.87.exons.genomic.bed.gz \
' + args.tmp_dir + only_input_filename + '.gc.genic.exonic.tsv.gz \
exonic'
subprocess.run(syntax_exonic, shell=True)
#pdb.set_trace()
os.remove(args.tmp_dir + only_input_filename + '.gc.genic.tsv.gz')
# Annotate dataset with gene orientation information
syntax_geneorientation = 'python3 preprocessing/dmm/annotate_mutations_with_coding_strand.py \
-i '+ args.tmp_dir + only_input_filename + '.gc.genic.exonic.tsv.gz \
-o '+ args.tmp_dir + only_input_filename + '.gc.genic.exonic.cs.tsv.gz \
--annotation ' + args.genomic_tracks + 'Homo_sapiens.GRCh37.87.transcript_directionality.bed.gz \
--ref ' + args.reference
#pdb.set_trace()
subprocess.run(syntax_geneorientation, shell=True)
os.remove(args.tmp_dir + only_input_filename + '.gc.genic.exonic.tsv.gz')
if __name__ == '__main__':
best_accuracy=0
args = get_args()
args = fix_path(args)
#simplified args
args = simplified_args(args)
if args.train:
train_dataset = get_simplified_dataloader(args=args,train_val='training',input_filename=None)
validation_dataset = get_simplified_dataloader(args=args,train_val='validation',input_filename=None)
mconf = ModelConfig(vocab_size=train_dataset.vocab_size, block_size=args.block_size,num_class=args.n_class,
n_layer=args.n_layer,n_head=args.n_head, n_embd=args.n_emb,position_size=train_dataset.position_size, ges_size = train_dataset.ges_size,dnn_input=train_dataset.dnn_input, epi_size=train_dataset.epi_size, epi_emb = args.epi_emb)
model = get_model(args,mconf)
tconf = TrainerConfig(max_epochs=args.epoch, batch_size=args.batch_size, learning_rate=args.l_rate,
lr_decay=True, num_workers=1, args=args)
trainer = Trainer(model, train_dataset, validation_dataset, tconf)
#trainer.dynamic_stream()
trainer.batch_train()
if args.predict:
device = 'cpu'
if torch.cuda.is_available():
device = torch.cuda.current_device()
#load ckpt
if device == 'cpu':
allckpt = torch.load(args.load_ckpt_dir + args.load_ckpt_filename,map_location=device)
else:
allckpt = torch.load(args.load_ckpt_dir + args.load_ckpt_filename)
if len(allckpt) == 2:
old_args = allckpt[1]
weight = allckpt[0]
args = update_args(args,old_args)
else:
weight = allckpt
validation_dataset = get_simplified_dataloader(args=args,train_val='validation')
train_dataset = get_simplified_dataloader(args=args,train_val='training')
try:
mconf = ModelConfig(vocab_size=validation_dataset.vocab_size, block_size=args.block_size,num_class=args.n_class, n_layer=args.n_layer,n_head=args.n_head, n_embd=args.n_emb,position_size=validation_dataset.position_size, ges_size = validation_dataset.ges_size)
model = get_model(args,mconf)
#load weight to the model
model = model.to(device)
model.load_state_dict(weight)
except:
#solving
args = solving_arch(args)
mconf = ModelConfig(vocab_size=validation_dataset.vocab_size, block_size=args.block_size,num_class=args.n_class, n_layer=args.n_layer,n_head=args.n_head, n_embd=args.n_emb,
position_size=validation_dataset.position_size, ges_size = validation_dataset.ges_size)
model = get_model(args,mconf)
#load weight to the model
model = model.to(device)
model.load_state_dict(weight)
tconf = TrainerConfig(max_epochs=1, batch_size=1, learning_rate=6e-3,
lr_decay=True,num_workers=20, args=args)
trainer = Trainer(model, None,[validation_dataset], tconf)
if args.vis_attention:
trainer = Trainer(model, None,[train_dataset, validation_dataset], tconf)
trainer.visualize_attention(args.vis_attention)
else:
if args.get_features:
trainer = Trainer(model, None,[train_dataset,validation_dataset], tconf)
trainer.predict(args.get_features,args.input_data_dir)
if args.single_pred_vcf:
args = translate_args(args)
cmd_preprocess(args)
only_input_filename = args.input_filename[:-4]
execute_annotation(args,only_input_filename)
preprocessing_fromdmm(args)
device = 'cpu'
if torch.cuda.is_available():
device = torch.cuda.current_device()
#load ckpt
if device == 'cpu':
allckpt = torch.load(args.load_ckpt_dir + args.load_ckpt_filename,map_location=device)
else:
allckpt = torch.load(args.load_ckpt_dir + args.load_ckpt_filename)
#check weight
#pdb.set_trace()
if len(allckpt) == 3: #newformat
old_args = allckpt[1]
weight = allckpt[0]
update_args(args,old_args)
else:
print('Warning: this model is depricated')
validation_dataset = get_simplified_dataloader(args=args,train_val='validation',input_filename=args.input_filename)
mconf = ModelConfig(vocab_size=validation_dataset.vocab_size,
block_size=args.block_size,
num_class=args.n_class,
n_layer=args.n_layer,
n_head=args.n_head,
n_embd=args.n_emb,
position_size=validation_dataset.position_size,
ges_size = validation_dataset.ges_size,
context_length=args.context_length,
args=args)
#pdb.set_trace()
model = get_model(args,mconf)
#load weight to the model
model = model.to(device)
model.load_state_dict(weight)
tconf = PredictorConfig(max_epochs=1, batch_size=1,num_workers=20, args=args)
predictor = Predictor(model, None,[validation_dataset], tconf)
predictor.predict(args.get_features,args.input_newdata_dir)
if args.ensemble:
if args.predict_all:
args.ensemble = True
args = translate_args(args)
func_annotate_mutation_all_modified(args)
preprocessing_fromdmm_all(args)
device = 'cpu'
if torch.cuda.is_available():
device = torch.cuda.current_device()
all_folder = os.listdir(args.load_ckpt_dir)
#args.single_pred_vcf = True #carefull this is used in args.single pred. will be called twice if this is put above single_pred vcf
for i in range(len(all_folder)):
try:
folder1 = all_folder[i]
splitfold = folder1.split('fold')
#pdb.set_trace()
splitfold = splitfold[1].split('_')
fold = int(splitfold[0])
args.output_prefix = 'model' + str(fold)
#load ckpt
if device == 'cpu':
allckpt = torch.load(args.load_ckpt_dir + str(folder1) + '/' + args.load_ckpt_filename,map_location=device)
else:
allckpt = torch.load(args.load_ckpt_dir + str(folder1) + '/' + args.load_ckpt_filename)
except:
print('can not load ckpt, plesae check the ckpt directory')
#check weight
#pdb.set_trace()
if len(allckpt) == 3: #newformat
old_args = allckpt[1]
weight = allckpt[0]
update_args(args,old_args)
else:
print('Warning: this model is depricated')
validation_dataset = get_simplified_dataloader(args=args,train_val='validation',input_filename=args.input_filename)
mconf = ModelConfig(vocab_size=validation_dataset.vocab_size,
block_size=args.block_size,
num_class=args.n_class,
n_layer=args.n_layer,
n_head=args.n_head,
n_embd=args.n_emb,
position_size=validation_dataset.position_size,
ges_size = validation_dataset.ges_size,
context_length=args.context_length,
args=args)
#pdb.set_trace()
model = get_model(args,mconf)
#load weight to the model
model = model.to(device)
model.load_state_dict(weight)
tconf = PredictorConfig(max_epochs=1, batch_size=1,num_workers=20, args=args)
predictor = Predictor(model, None,[validation_dataset], tconf)
predictor.predict(args.get_features,args.input_newdata_dir)
else:
args = translate_args(args)
cmd_preprocess(args)
#pdb.set_trace()
if args.predict_filepath is not None:
translate_args(args)
execute_annotation_all()
else:
only_input_filename = args.input_filename[:-4]
execute_annotation(args,only_input_filename)
preprocessing_fromdmm(args)
device = 'cpu'
if torch.cuda.is_available():
device = torch.cuda.current_device()
all_folder = os.listdir(args.load_ckpt_dir)
args.single_pred_vcf = True #carefull this is used in args.single pred. will be called twice if this is put above single_pred vcf
for i in range(len(all_folder)):
try:
folder1 = all_folder[i]
splitfold = folder1.split('fold')
#pdb.set_trace()
splitfold = splitfold[1].split('_')
fold = int(splitfold[0])
args.output_prefix = 'model' + str(fold)
#load ckpt
if device == 'cpu':
allckpt = torch.load(args.load_ckpt_dir + str(folder1) + '/' + args.load_ckpt_filename,map_location=device)
else:
allckpt = torch.load(args.load_ckpt_dir + str(folder1) + '/' + args.load_ckpt_filename)
except:
print('can not load ckpt, plesae check the ckpt directory')
#check weight
#pdb.set_trace()
if len(allckpt) == 3: #newformat
old_args = allckpt[1]
weight = allckpt[0]
update_args(args,old_args)
else:
print('Warning: this model is depricated')
validation_dataset = get_simplified_dataloader(args=args,train_val='validation',input_filename=args.input_filename)
mconf = ModelConfig(vocab_size=validation_dataset.vocab_size,
block_size=args.block_size,
num_class=args.n_class,
n_layer=args.n_layer,
n_head=args.n_head,
n_embd=args.n_emb,
position_size=validation_dataset.position_size,
ges_size = validation_dataset.ges_size,
context_length=args.context_length,
args=args)
#pdb.set_trace()
model = get_model(args,mconf)
#load weight to the model
model = model.to(device)
model.load_state_dict(weight)
tconf = PredictorConfig(max_epochs=1, batch_size=1,num_workers=20, args=args)
predictor = Predictor(model, None,[validation_dataset], tconf)
predictor.predict(args.get_features,args.input_newdata_dir)
if args.multi_pred_vcf:
#get all vcf files
vcffiles = os.listdir(args.input_data_dir)
vcffiles = [i for i in vcffiles if i[-4:] =='.vcf']
for i in vcffiles:
args.input_filename = i
args = translate_args(args)
cmd_preprocess(args)
only_input_filename = i[:-4]
execute_annotation(args,only_input_filename)
preprocessing_fromdmm(args)
#pdb.set_trace()
device = 'cpu'
if torch.cuda.is_available():
device = torch.cuda.current_device()
#load ckpt
if device == 'cpu':
allckpt = torch.load(args.load_ckpt_dir + args.load_ckpt_filename,map_location=device)
else:
allckpt = torch.load(args.load_ckpt_dir + args.load_ckpt_filename)
#check weight
if len(allckpt) == 3: #newformat
old_args = allckpt[1]
weight = allckpt[0]
update_args(args,old_args)
else:
print('Warning: this model is depricated')
validation_dataset = get_simplified_dataloader(args=args,train_val='validation',input_filename=vcffiles)
mconf = ModelConfig(vocab_size=validation_dataset.vocab_size,
block_size=args.block_size,
num_class=args.n_class,
n_layer=args.n_layer,
n_head=args.n_head,
n_embd=args.n_emb,
position_size=validation_dataset.position_size,
ges_size = validation_dataset.ges_size,
context_length=args.context_length,
args=args)
#pdb.set_trace()
model = get_model(args,mconf)
#load weight to the model
model = model.to(device)
model.load_state_dict(weight)
tconf = PredictorConfig(max_epochs=1, batch_size=1,num_workers=20, args=args)
predictor = Predictor(model, None,[validation_dataset], tconf)
predictor.predict(args.get_features,args.input_newdata_dir)