OpenSpliceai 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- OpenSpliceai-0.0.1.dist-info/LICENSE +674 -0
- OpenSpliceai-0.0.1.dist-info/METADATA +177 -0
- OpenSpliceai-0.0.1.dist-info/RECORD +42 -0
- OpenSpliceai-0.0.1.dist-info/WHEEL +5 -0
- OpenSpliceai-0.0.1.dist-info/entry_points.txt +2 -0
- OpenSpliceai-0.0.1.dist-info/top_level.txt +1 -0
- openspliceai/__init__.py +1 -0
- openspliceai/calibrate/__init__.py +0 -0
- openspliceai/calibrate/calibrate.py +85 -0
- openspliceai/calibrate/calibrate_utils.py +42 -0
- openspliceai/calibrate/model_utils.py +59 -0
- openspliceai/calibrate/temperature_scaling.py +211 -0
- openspliceai/calibrate/visualization.py +99 -0
- openspliceai/constants.py +14 -0
- openspliceai/create_data/__init__.py +0 -0
- openspliceai/create_data/create_datafile.py +159 -0
- openspliceai/create_data/create_dataset.py +64 -0
- openspliceai/create_data/paralogs.py +81 -0
- openspliceai/create_data/utils.py +254 -0
- openspliceai/create_data/verify_h5_file.py +61 -0
- openspliceai/header.py +11 -0
- openspliceai/merge_data/__init__.py +0 -0
- openspliceai/merge_data/merge_dataset.py +103 -0
- openspliceai/openspliceai.py +197 -0
- openspliceai/predict/__init__.py +0 -0
- openspliceai/predict/predict.py +1091 -0
- openspliceai/predict/utils.py +53 -0
- openspliceai/test/__init__.py +0 -0
- openspliceai/test/spliceai.py +45 -0
- openspliceai/test/test.py +92 -0
- openspliceai/train/__init__.py +0 -0
- openspliceai/train/train.py +76 -0
- openspliceai/train_base/__init__.py +0 -0
- openspliceai/train_base/spliceai.py +61 -0
- openspliceai/train_base/utils.py +644 -0
- openspliceai/transfer/__init__.py +0 -0
- openspliceai/transfer/transfer.py +107 -0
- openspliceai/variant/__init__.py +0 -0
- openspliceai/variant/get_anno.py +129 -0
- openspliceai/variant/test.py +31 -0
- openspliceai/variant/utils.py +541 -0
- openspliceai/variant/variant.py +89 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# import necessary libraries
|
|
2
|
+
import argparse
|
|
3
|
+
import h5py
|
|
4
|
+
import torch
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
import time
|
|
7
|
+
import h5py
|
|
8
|
+
|
|
9
|
+
def verify_h5(args):
|
|
10
|
+
'''
|
|
11
|
+
Verifies the integrity of the created testing and/or training h5 datasets.
|
|
12
|
+
'''
|
|
13
|
+
# record start time for benchmark
|
|
14
|
+
print("--- Step 3: Verifying integrity of h5 file ... ---")
|
|
15
|
+
start_time = time.time()
|
|
16
|
+
|
|
17
|
+
# construct the filename and open h5 file
|
|
18
|
+
dataset_ls = []
|
|
19
|
+
if args.chr_split == 'test':
|
|
20
|
+
dataset_ls.append('test')
|
|
21
|
+
elif args.chr_split == 'train-test':
|
|
22
|
+
dataset_ls.append('test')
|
|
23
|
+
dataset_ls.append('train')
|
|
24
|
+
for dataset_type in dataset_ls:
|
|
25
|
+
if args.biotype =="non-coding":
|
|
26
|
+
filename = f"{args.output_dir}/dataset_{dataset_type}_ncRNA.h5"
|
|
27
|
+
figname = f"{args.output_dir}/verify_{dataset_type}_ncRNA.png"
|
|
28
|
+
elif args.biotype =="protein-coding":
|
|
29
|
+
filename = f"{args.output_dir}/dataset_{dataset_type}.h5"
|
|
30
|
+
figname = f"{args.output_dir}/verify_{dataset_type}.png"
|
|
31
|
+
|
|
32
|
+
print(f'Verifying {filename}...')
|
|
33
|
+
with h5py.File(filename, 'r') as hf:
|
|
34
|
+
# print the available dataset keys in the file
|
|
35
|
+
print(f"Dataset keys: {list(hf.keys())}\n\n")
|
|
36
|
+
|
|
37
|
+
# convert datasets to PyTorch tensors and display their shapes
|
|
38
|
+
X0_tensor = torch.from_numpy(hf['X0'][:]).float()
|
|
39
|
+
Y0_tensor = torch.from_numpy(hf['Y0'][:])
|
|
40
|
+
print(f"X0 shape: {X0_tensor.shape}, Y0 shape: {Y0_tensor.shape}")
|
|
41
|
+
|
|
42
|
+
# process a specific dataset ('X3') for visualization
|
|
43
|
+
x = torch.from_numpy(hf['X3'][:]).float()
|
|
44
|
+
y = torch.from_numpy(hf['Y3'][:])
|
|
45
|
+
print(f"x[0].shape: {x[0].shape}, y[0].shape: {y[0].shape}")
|
|
46
|
+
|
|
47
|
+
# plot the sum of the last entry in the 'X3' dataset along its rows
|
|
48
|
+
fig = plt.figure(figsize=(7, 3))
|
|
49
|
+
ax = fig.add_subplot(111)
|
|
50
|
+
ax.set_xlim([0, 15000])
|
|
51
|
+
ax.plot(x[-1].sum(axis=1)) # Sum over rows and plot
|
|
52
|
+
fig.savefig(figname, dpi=300, bbox_inches='tight')
|
|
53
|
+
plt.close(fig)
|
|
54
|
+
|
|
55
|
+
# additional info
|
|
56
|
+
print("x[0].sum(axis=1): ", len(x[len(x)-1].sum(axis=1))) # Length of row sum in the last 'X3' entry
|
|
57
|
+
print("x[0].sum(axis=0): ", len(x[len(x)-1].sum(axis=0))) # Length of column sum in the last 'X3' entry
|
|
58
|
+
print(f"(x[0].sum(axis=1) == 0).sum(): {(x[0].sum(axis=1) == 0).sum()}") # Number of zero-sum rows in the first 'X3' entry
|
|
59
|
+
|
|
60
|
+
# END
|
|
61
|
+
print(("--- %s seconds ---" % (time.time() - start_time)))
|
openspliceai/header.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
__author__ = "Kuan-Hao Chao"
|
|
2
|
+
__contact__ = "kuanhao.chao@gmail.com"
|
|
3
|
+
__copyright__ = "Copyright 2024, Kuan-Hao Chao, Alan Mao"
|
|
4
|
+
__credits__ = ["Kuan-Hao Chao", "Alan Mao"]
|
|
5
|
+
__date__ = "2024/02/18"
|
|
6
|
+
__deprecated__ = False
|
|
7
|
+
__email__ = "kuanhao.chao@gmail.com"
|
|
8
|
+
__license__ = "GPL-3.0"
|
|
9
|
+
__maintainer__ = "developer"
|
|
10
|
+
__status__ = "Kuan-Hao Chao"
|
|
11
|
+
__version__ = "0.0.1"
|
|
File without changes
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import h5py
|
|
2
|
+
import numpy as np
|
|
3
|
+
import sys, os
|
|
4
|
+
import time
|
|
5
|
+
# from utils import *
|
|
6
|
+
import argparse
|
|
7
|
+
import openspliceai.create_data.utils as utils
|
|
8
|
+
|
|
9
|
+
donor_motif_counts = {} # Initialize counts
|
|
10
|
+
acceptor_motif_counts = {} # Initialize counts
|
|
11
|
+
|
|
12
|
+
def merge_dataset(args):
|
|
13
|
+
print("--- Merging dataset.h5 ... ---")
|
|
14
|
+
start_time = time.time()
|
|
15
|
+
|
|
16
|
+
dataset_ls = []
|
|
17
|
+
if args.chr_split == 'test':
|
|
18
|
+
dataset_ls.append('test')
|
|
19
|
+
elif args.chr_split == 'train-test':
|
|
20
|
+
dataset_ls.append('test')
|
|
21
|
+
dataset_ls.append('train')
|
|
22
|
+
for dataset_type in dataset_ls:
|
|
23
|
+
print(("\tProcessing %s ..." % dataset_type))
|
|
24
|
+
# if args.biotype =="non-coding":
|
|
25
|
+
# input_file = f"{args.output_dir}/datafile_{dataset_type}_ncRNA.h5"
|
|
26
|
+
# output_file = f"{args.output_dir}/dataset_{dataset_type}_ncRNA.h5"
|
|
27
|
+
# elif args.biotype =="protein-coding":
|
|
28
|
+
# input_file = f"{args.output_dir}/datafile_{dataset_type}.h5"
|
|
29
|
+
# output_file = f"{args.output_dir}/dataset_{dataset_type}.h5"
|
|
30
|
+
|
|
31
|
+
os.makedirs(args.output_dir, exist_ok=True)
|
|
32
|
+
output_file = f"{args.output_dir}/dataset_{dataset_type}.h5"
|
|
33
|
+
h5f2 = h5py.File(output_file, 'w')
|
|
34
|
+
print(f"\t output {output_file} ... ")
|
|
35
|
+
|
|
36
|
+
key_counter = 0
|
|
37
|
+
|
|
38
|
+
for input_dir in args.input_dir:
|
|
39
|
+
input_file = f"{input_dir}/dataset_{dataset_type}.h5"
|
|
40
|
+
print(f"\tReading {input_file} ... ")
|
|
41
|
+
with h5py.File(input_file, 'r') as h5f:
|
|
42
|
+
x_keys = [key for key in h5f.keys() if key.startswith('X')]
|
|
43
|
+
y_keys = [key for key in h5f.keys() if key.startswith('Y')]
|
|
44
|
+
x_keys.sort(key=lambda x: int(x[1:])) # Sort by numeric value
|
|
45
|
+
y_keys.sort(key=lambda y: int(y[1:])) # Sort by numeric value
|
|
46
|
+
for x_key, y_key in zip(x_keys, y_keys):
|
|
47
|
+
new_x_key = f'X{key_counter}'
|
|
48
|
+
new_y_key = f'Y{key_counter}'
|
|
49
|
+
h5f2.create_dataset(new_x_key, data=h5f[x_key][:])
|
|
50
|
+
h5f2.create_dataset(new_y_key, data=h5f[y_key][:])
|
|
51
|
+
key_counter += 1
|
|
52
|
+
h5f2.close()
|
|
53
|
+
print(f"--- {time.time() - start_time} seconds ---")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# CHUNK_SIZE = 100
|
|
60
|
+
# seq_num = SEQ.shape[0]
|
|
61
|
+
# print("seq_num: ", seq_num)
|
|
62
|
+
# print("STRAND.shape[0]: ", STRAND.shape[0])
|
|
63
|
+
# print("TX_START.shape[0]: ", TX_START.shape[0])
|
|
64
|
+
# print("TX_END.shape[0]: ", TX_END.shape[0])
|
|
65
|
+
# print("LABEL.shape[0]: ", LABEL.shape[0])
|
|
66
|
+
# # # Check motif
|
|
67
|
+
# # for idx in range(seq_num):
|
|
68
|
+
# # label_decode = LABEL[idx].decode('ascii')
|
|
69
|
+
# # seq_decode = SEQ[idx].decode('ascii')
|
|
70
|
+
# # strand_decode = STRAND[idx].decode('ascii')
|
|
71
|
+
# # label_int = [int(char) for char in label_decode]
|
|
72
|
+
# # utils.check_and_count_motifs(seq_decode, label_int, strand_decode, donor_motif_counts, acceptor_motif_counts)
|
|
73
|
+
# # utils.print_motif_counts(donor_motif_counts, acceptor_motif_counts)
|
|
74
|
+
# # Create dataset
|
|
75
|
+
# for i in range(seq_num//CHUNK_SIZE):
|
|
76
|
+
# # Each dataset has CHUNK_SIZE genes
|
|
77
|
+
# if (i+1) == seq_num//CHUNK_SIZE:
|
|
78
|
+
# NEW_CHUNK_SIZE = CHUNK_SIZE + seq_num%CHUNK_SIZE
|
|
79
|
+
# else:
|
|
80
|
+
# NEW_CHUNK_SIZE = CHUNK_SIZE
|
|
81
|
+
# X_batch = []
|
|
82
|
+
# Y_batch = [[] for t in range(1)]
|
|
83
|
+
# for j in range(NEW_CHUNK_SIZE):
|
|
84
|
+
# idx = i*CHUNK_SIZE + j
|
|
85
|
+
# seq_decode = SEQ[idx].decode('ascii')
|
|
86
|
+
# strand_decode = STRAND[idx].decode('ascii')
|
|
87
|
+
# tx_start_decode = TX_START[idx].decode('ascii')
|
|
88
|
+
# tx_end_decode = TX_END[idx].decode('ascii')
|
|
89
|
+
# label_decode = LABEL[idx].decode('ascii')
|
|
90
|
+
# fixed_seq = utils.replace_non_acgt_to_n(seq_decode)
|
|
91
|
+
# X, Y = utils.create_datapoints(fixed_seq, strand_decode, label_decode)
|
|
92
|
+
# X_batch.extend(X)
|
|
93
|
+
# for t in range(1):
|
|
94
|
+
# Y_batch[t].extend(Y[t])
|
|
95
|
+
# X_batch = np.asarray(X_batch).astype('int8')
|
|
96
|
+
# print("X_batch.shape: ", X_batch.shape)
|
|
97
|
+
# for t in range(1):
|
|
98
|
+
# Y_batch[t] = np.asarray(Y_batch[t]).astype('int8')
|
|
99
|
+
# print("len(Y_batch[0]): ", len(Y_batch[0]))
|
|
100
|
+
# h5f2.create_dataset('X' + str(i), data=X_batch)
|
|
101
|
+
# h5f2.create_dataset('Y' + str(i), data=Y_batch)
|
|
102
|
+
# h5f2.close()
|
|
103
|
+
print("--- %s seconds ---" % (time.time() - start_time))
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import os, sys, time
|
|
3
|
+
import random
|
|
4
|
+
import h5py
|
|
5
|
+
import numpy as np
|
|
6
|
+
from openspliceai import header
|
|
7
|
+
from openspliceai.create_data import create_datafile, create_dataset, verify_h5_file
|
|
8
|
+
from openspliceai.train import train
|
|
9
|
+
from openspliceai.test import test
|
|
10
|
+
from openspliceai.calibrate import calibrate
|
|
11
|
+
from openspliceai.transfer import transfer
|
|
12
|
+
from openspliceai.predict import predict
|
|
13
|
+
from openspliceai.variant import variant
|
|
14
|
+
|
|
15
|
+
__VERSION__ = header.__version__
|
|
16
|
+
|
|
17
|
+
def parse_args_create_data(subparsers):
|
|
18
|
+
parser_create_data = subparsers.add_parser('create-data', help='Create dataset for your genome for SpliceAI model training')
|
|
19
|
+
parser_create_data.add_argument('--annotation-gff', type=str, required=True, help='Path to the GFF file')
|
|
20
|
+
parser_create_data.add_argument('--genome-fasta', type=str, required=True, help='Path to the FASTA file')
|
|
21
|
+
parser_create_data.add_argument('--output-dir', type=str, required=True, help='Output directory to save the data')
|
|
22
|
+
parser_create_data.add_argument('--parse-type', type=str, default='canonical', choices=['canonical', 'all_isoforms'], help='Type of transcript processing')
|
|
23
|
+
parser_create_data.add_argument('--biotype', type=str, default='protein-coding', choices=['protein-coding', 'non-coding'], help='Biotype of transcript processing')
|
|
24
|
+
parser_create_data.add_argument('--chr-split', type=str, choices=['train-test','test'], default='train-test', help='Whether to obtain testing or both training and testing groups')
|
|
25
|
+
'''AM: newly added flags below vv'''
|
|
26
|
+
parser_create_data.add_argument('--split-method', type=str, choices=['random', 'human'], default='random', help='Chromosome split method for training and testing dataset')
|
|
27
|
+
parser_create_data.add_argument('--split-ratio', type=float, default=0.8, help='Ratio of training and testing dataset')
|
|
28
|
+
parser_create_data.add_argument('--canonical-only', action='store_true', default=False, help='Flag to obtain only canonical splice site pairs')
|
|
29
|
+
parser_create_data.add_argument('--flanking-size', type=int, default=80, help='Sum of flanking sequence lengths on each side of input (i.e. 40+40)')
|
|
30
|
+
parser_create_data.add_argument('--verify-h5', action='store_true', default=False, help='Verify the generated HDF5 file(s)')
|
|
31
|
+
parser_create_data.add_argument('--remove-paralogs', action='store_true', default=False, help='Remove paralogous sequences between training and testing dataset')
|
|
32
|
+
parser_create_data.add_argument('--min-identity', type=float, default=0.8, help='Minimum minimap2 alignment identity for paralog removal between training and testing dataset')
|
|
33
|
+
parser_create_data.add_argument('--min-coverage', type=float, default=0.5, help='Minimum minimap2 alignment coverage for paralog removal between training and testing dataset')
|
|
34
|
+
parser_create_data.add_argument('--write-fasta', action='store_true', default=False, help='Flag to write out sequences into fasta files')
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def parse_args_train(subparsers):
|
|
38
|
+
parser_train = subparsers.add_parser('train', help='Train the SpliceAI model')
|
|
39
|
+
parser_train.add_argument('--epochs', '-n', type=int, default=10, help='Number of epochs for training')
|
|
40
|
+
parser_train.add_argument('--scheduler', '-s', type=str, default="MultiStepLR", choices=["MultiStepLR", "CosineAnnealingWarmRestarts"], help="Learning rate scheduler")
|
|
41
|
+
parser_train.add_argument('--early-stopping', '-E', action='store_true', default=False, help='Enable early stopping')
|
|
42
|
+
parser_train.add_argument("--patience", '-P', type=int, default=2, help="Number of epochs to wait before early stopping")
|
|
43
|
+
parser_train.add_argument('--output-dir', '-o', type=str, required=True, help='Output directory to save the data')
|
|
44
|
+
parser_train.add_argument('--project-name', '-p', type=str, required=True, help="Project name for the train experiment")
|
|
45
|
+
parser_train.add_argument('--exp-num', '-e', type=str, default="0", help="Experiment number")
|
|
46
|
+
parser_train.add_argument('--flanking-size', '-f', type=int, default=80, choices=[80, 400, 2000, 10000], help="Flanking sequence size")
|
|
47
|
+
parser_train.add_argument('--random-seed', '-r', type=int, default=42, help="Random seed for reproducibility")
|
|
48
|
+
parser_train.add_argument('--train-dataset', '-train', type=str, required=True, help="Path to the training dataset")
|
|
49
|
+
parser_train.add_argument('--test-dataset', '-test', type=str, required=True, help="Path to the testing dataset")
|
|
50
|
+
parser_train.add_argument("--loss", '-l', type=str, default='cross_entropy_loss', choices=["cross_entropy_loss", "focal_loss"], help="Loss function for training")
|
|
51
|
+
parser_train.add_argument('--model', '-m', default="SpliceAI", type=str)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def parse_args_test(subparsers):
|
|
55
|
+
parser_test = subparsers.add_parser('test', help='Test the SpliceAI model')
|
|
56
|
+
parser_test.add_argument("--pretrained-model", '-m', type=str, required=True, help="Path to the pre-trained model")
|
|
57
|
+
parser_test.add_argument('--output-dir', '-o', type=str, required=True, help='Output directory to save the data')
|
|
58
|
+
parser_test.add_argument('--project-name', '-p', type=str, required=True, help="Project name for the fine-tuning experiment")
|
|
59
|
+
parser_test.add_argument('--exp-num', '-e', type=str, default=0, help="Experiment number")
|
|
60
|
+
parser_test.add_argument('--flanking-size', '-f', type=int, default=80, choices=[80, 400, 2000, 10000], help="Flanking sequence size")
|
|
61
|
+
parser_test.add_argument('--random-seed', '-r', type=int, default=42, help="Random seed for reproducibility")
|
|
62
|
+
parser_test.add_argument('--test-dataset', '-test', type=str, required=True, help="Path to the testing dataset")
|
|
63
|
+
parser_test.add_argument("--loss", '-l', type=str, default='cross_entropy_loss', choices=["cross_entropy_loss", "focal_loss"], help="Loss function for training")
|
|
64
|
+
parser_test.add_argument('--test-target', '-t', default="OpenSpliceAI", choices=["OpenSpliceAI", "SpliceAI-Keras"], type=str)
|
|
65
|
+
parser_test.add_argument('--log-dir', '-L', default="TEST_LOG", type=str)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def parse_args_calibrate(subparsers):
|
|
69
|
+
parser_calibrate = subparsers.add_parser('calibrate', help='Calibrate the SpliceAI model')
|
|
70
|
+
parser_calibrate.add_argument('--epochs', '-n', type=int, default=10, help='Number of epochs for training')
|
|
71
|
+
parser_calibrate.add_argument('--early-stopping', '-E', action='store_true', default=False, help='Enable early stopping')
|
|
72
|
+
parser_calibrate.add_argument("--patience", '-P', type=int, default=2, help="Number of epochs to wait before early stopping")
|
|
73
|
+
parser_calibrate.add_argument("--output-dir", '-o', type=str, required=True, help="Output directory for model checkpoints and logs")
|
|
74
|
+
parser_calibrate.add_argument("--project-name", '-p', type=str, required=True, help="Project name for the fine-tuning experiment")
|
|
75
|
+
parser_calibrate.add_argument("--exp-num", '-e', type=int, default=0, help="Experiment number")
|
|
76
|
+
parser_calibrate.add_argument("--flanking-size", '-f', type=int, default=80, choices=[80, 400, 2000, 10000], help="Flanking sequence size")
|
|
77
|
+
parser_calibrate.add_argument("--random-seed", '-r', type=int, default=42, help="Random seed for reproducibility")
|
|
78
|
+
parser_calibrate.add_argument("--temperature-file", '-T', type=str, default=None, required=False, help="Path to the temperature file")
|
|
79
|
+
parser_calibrate.add_argument("--pretrained-model", '-m', type=str, required=True, help="Path to the pre-trained model")
|
|
80
|
+
parser_calibrate.add_argument("--train-dataset", '-train', type=str, required=True, help="Path to the training dataset")
|
|
81
|
+
parser_calibrate.add_argument("--test-dataset", '-test', type=str, required=True, help="Path to the testing dataset")
|
|
82
|
+
parser_calibrate.add_argument("--loss", '-l', type=str, default='cross_entropy_loss', choices=["cross_entropy_loss", "focal_loss"], help="Loss function for fine-tuning")
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def parse_args_transfer(subparsers):
|
|
86
|
+
parser_transfer = subparsers.add_parser('transfer', help='transfer a pre-trained SpliceAI model on new data.')
|
|
87
|
+
parser_transfer.add_argument('--epochs', '-n', type=int, default=10, help='Number of epochs for training')
|
|
88
|
+
parser_transfer.add_argument('--scheduler', '-s', type=str, default="MultiStepLR", choices=["MultiStepLR", "CosineAnnealingWarmRestarts"], help="Learning rate scheduler")
|
|
89
|
+
parser_transfer.add_argument('--early-stopping', '-E', action='store_true', default=False, help='Enable early stopping')
|
|
90
|
+
parser_transfer.add_argument("--patience", '-P', type=int, default=2, help="Number of epochs to wait before early stopping")
|
|
91
|
+
parser_transfer.add_argument("--output-dir", '-o', type=str, required=True, help="Output directory for model checkpoints and logs")
|
|
92
|
+
parser_transfer.add_argument("--project-name", '-p', type=str, required=True, help="Project name for the fine-tuning experiment")
|
|
93
|
+
parser_transfer.add_argument("--exp-num", '-e', type=int, default=0, help="Experiment number")
|
|
94
|
+
parser_transfer.add_argument("--flanking-size", '-f', type=int, default=80, choices=[80, 400, 2000, 10000], help="Flanking sequence size")
|
|
95
|
+
parser_transfer.add_argument("--random-seed", '-r', type=int, default=42, help="Random seed for reproducibility")
|
|
96
|
+
parser_transfer.add_argument("--pretrained-model", '-m', type=str, required=True, help="Path to the pre-trained model")
|
|
97
|
+
parser_transfer.add_argument("--train-dataset", '-train', type=str, required=True, help="Path to the training dataset")
|
|
98
|
+
parser_transfer.add_argument("--test-dataset", '-test', type=str, required=True, help="Path to the testing dataset")
|
|
99
|
+
parser_transfer.add_argument("--loss", '-l', type=str, default='cross_entropy_loss', choices=["cross_entropy_loss", "focal_loss"], help="Loss function for fine-tuning")
|
|
100
|
+
parser_transfer.add_argument("--unfreeze-all", '-A', action='store_true', default=True, help='Unfreeze all layers for fine-tuning')
|
|
101
|
+
parser_transfer.add_argument("--unfreeze", '-u', type=int, default=1, help="Number of layers to unfreeze for fine-tuning")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def parse_args_predict(subparsers):
|
|
105
|
+
parser_predict = subparsers.add_parser('predict', help='Predict splice sites in a given sequence using the SpliceAI model')
|
|
106
|
+
parser_predict.add_argument('--model', '-m', type=str, default="SpliceAI", help='Path to a PyTorch SpliceAI model file or "SpliceAI" for the default model')
|
|
107
|
+
parser_predict.add_argument('--output-dir', '-o', type=str, required=True, help='Output directory to save the data')
|
|
108
|
+
parser_predict.add_argument('--flanking-size', '-f', type=int, default=80, help='Sum of flanking sequence lengths on each side of input (i.e. 40+40)')
|
|
109
|
+
parser_predict.add_argument('--input-sequence', '-i', type=str, help="Path to FASTA file of the input sequence")
|
|
110
|
+
parser_predict.add_argument('--annotation-file', '-a', type=str, required=False, help="Path to GFF file of coordinates for genes")
|
|
111
|
+
parser_predict.add_argument('--threshold', '-t', type=float, default=1e-6, help="Threshold to determine acceptor and donor sites")
|
|
112
|
+
parser_predict.add_argument('--predict-all', '-p', action='store_true', required=False, help="Writes all collected predictions to an intermediate file (Warning: on full genomes, will consume much space.)")
|
|
113
|
+
parser_predict.add_argument('--debug', '-D', action='store_true', required=False, help="Run in debug mode (debug statements are printed to stderr)")
|
|
114
|
+
'''AM: very optional flags below vv'''
|
|
115
|
+
parser_predict.add_argument('--hdf-threshold', type=int, default=0, help='Maximum size before reading sequence into an HDF file for storage')
|
|
116
|
+
parser_predict.add_argument('--flush-threshold', type=int, default=500, help='Maximum number of predictions before flushing to file')
|
|
117
|
+
parser_predict.add_argument('--split-threshold', type=int, default=1500000, help='Maximum length of FASTA entry before splitting')
|
|
118
|
+
parser_predict.add_argument('--chunk-size', type=int, default=100, help='Chunk size for loading HDF5 dataset')
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def parse_args_variant(subparsers):
|
|
122
|
+
parser_variant = subparsers.add_parser('variant', help='Label genetic variations with their predicted effects on splicing.')
|
|
123
|
+
parser_variant.add_argument('-R', metavar='reference', required=True, help='path to the reference genome fasta file')
|
|
124
|
+
parser_variant.add_argument('-A', metavar='annotation', required=True, help='"grch37" (GENCODE V24lift37 canonical annotation file in '
|
|
125
|
+
'package), "grch38" (GENCODE V24 canonical annotation file in '
|
|
126
|
+
'package), or path to a similar custom gene annotation file')
|
|
127
|
+
parser_variant.add_argument('-I', metavar='input', nargs='?', default=sys.stdin, help='path to the input VCF file, defaults to standard in')
|
|
128
|
+
parser_variant.add_argument('-O', metavar='output', nargs='?', default=sys.stdout, help='path to the output VCF file, defaults to standard out')
|
|
129
|
+
parser_variant.add_argument('-D', metavar='distance', nargs='?', default=50, type=int, choices=range(0, 5000),
|
|
130
|
+
help='maximum distance between the variant and gained/lost splice '
|
|
131
|
+
'site, defaults to 50')
|
|
132
|
+
parser_variant.add_argument('-M', metavar='mask', nargs='?', default=0, type=int, choices=[0, 1],
|
|
133
|
+
help='mask scores representing annotated acceptor/donor gain and '
|
|
134
|
+
'unannotated acceptor/donor loss, defaults to 0')
|
|
135
|
+
'''AM: newly added flags below vv'''
|
|
136
|
+
parser_variant.add_argument('--model', '-m', default="SpliceAI", type=str, help='Path to a SpliceAI model file, or path to a directory of SpliceAI models, or "SpliceAI" for the default model')
|
|
137
|
+
parser_variant.add_argument('--flanking-size', '-f', type=int, default=80, help='Sum of flanking sequence lengths on each side of input (i.e. 40+40)')
|
|
138
|
+
parser_variant.add_argument('--model-type', '-t', type=str, choices=['keras', 'pytorch'], default='pytorch', help='Type of model file (keras or pytorch)')
|
|
139
|
+
parser_variant.add_argument('--precision', '-p', type=int, default=2, help='Number of decimal places to round the output scores')
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def parse_args(arglist):
|
|
143
|
+
parser = argparse.ArgumentParser(description='OpenSpliceAI toolkit to help you retrain your own splice site predictor')
|
|
144
|
+
# Create a parent subparser to house the common subcommands.
|
|
145
|
+
subparsers = parser.add_subparsers(dest='command', required=True, help='Subcommands: create-data, train, test, calibrate, predict, transfer, variant')
|
|
146
|
+
parse_args_create_data(subparsers)
|
|
147
|
+
parse_args_train(subparsers)
|
|
148
|
+
parse_args_test(subparsers)
|
|
149
|
+
parse_args_calibrate(subparsers)
|
|
150
|
+
parse_args_transfer(subparsers)
|
|
151
|
+
parse_args_predict(subparsers)
|
|
152
|
+
parse_args_variant(subparsers)
|
|
153
|
+
if arglist is not None:
|
|
154
|
+
args = parser.parse_args(arglist)
|
|
155
|
+
else:
|
|
156
|
+
args = parser.parse_args()
|
|
157
|
+
return args
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def main(arglist=None):
|
|
161
|
+
# ANSI Shadow
|
|
162
|
+
banner = '''
|
|
163
|
+
====================================================================
|
|
164
|
+
Deep learning framework to train your own SpliceAI model
|
|
165
|
+
====================================================================
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
██████╗ ██████╗ ███████╗███╗ ██╗███████╗██████╗ ██╗ ██╗ ██████╗███████╗ █████╗ ██╗
|
|
169
|
+
██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔════╝██╔══██╗██║ ██║██╔════╝██╔════╝██╔══██╗██║
|
|
170
|
+
██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████╗██████╔╝██║ ██║██║ █████╗ ███████║██║
|
|
171
|
+
██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║╚════██║██╔═══╝ ██║ ██║██║ ██╔══╝ ██╔══██║██║
|
|
172
|
+
╚██████╔╝██║ ███████╗██║ ╚████║███████║██║ ███████╗██║╚██████╗███████╗██║ ██║██║
|
|
173
|
+
╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚══════╝╚═╝ ╚═════╝╚══════╝╚═╝ ╚═╝╚═╝
|
|
174
|
+
'''
|
|
175
|
+
print(banner, file=sys.stderr)
|
|
176
|
+
print(f"{__VERSION__}\n", file=sys.stderr)
|
|
177
|
+
args = parse_args(arglist)
|
|
178
|
+
|
|
179
|
+
if args.command == 'create-data':
|
|
180
|
+
create_datafile.create_datafile(args)
|
|
181
|
+
create_dataset.create_dataset(args)
|
|
182
|
+
if args.verify_h5:
|
|
183
|
+
verify_h5_file.verify_h5(args)
|
|
184
|
+
elif args.command == 'train':
|
|
185
|
+
train.train(args)
|
|
186
|
+
elif args.command == 'test':
|
|
187
|
+
test.test(args)
|
|
188
|
+
elif args.command == 'calibrate':
|
|
189
|
+
calibrate.calibrate(args)
|
|
190
|
+
elif args.command == 'transfer':
|
|
191
|
+
transfer.transfer(args)
|
|
192
|
+
elif args.command == 'predict':
|
|
193
|
+
predict.predict_cli(args)
|
|
194
|
+
elif args.command == 'variant':
|
|
195
|
+
variant.variant(args)
|
|
196
|
+
|
|
197
|
+
# To-do adding logic to each subcommand.
|
|
File without changes
|