geney 1.4.27__py2.py3-none-any.whl → 1.4.29__py2.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.

Potentially problematic release.


This version of geney might be problematic. Click here for more details.

@@ -0,0 +1,65 @@
1
+
2
+ import absl.logging
3
+ absl.logging.set_verbosity(absl.logging.ERROR)
4
+
5
+ import sys
6
+ import numpy as np
7
+
8
+
9
+ import torch
10
+ from spliceai_pytorch import SpliceAI
11
+ model = SpliceAI.from_preconfigured('10k')
12
+
13
+
14
+ if sys.platform == 'darwin':
15
+ device = torch.device("mps") if torch.backends.mps.is_available() else torch.device("cpu")
16
+
17
+ if sys.platform == 'linux':
18
+ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
19
+
20
+
21
+ print(f"SpliceAI loaded to {device}.")
22
+ model.to(device)
23
+
24
+ def one_hot_encode(seq):
25
+
26
+ map = np.asarray([[0, 0, 0, 0],
27
+ [1, 0, 0, 0],
28
+ [0, 1, 0, 0],
29
+ [0, 0, 1, 0],
30
+ [0, 0, 0, 1]])
31
+
32
+ seq = seq.upper().replace('A', '\x01').replace('C', '\x02')
33
+ seq = seq.replace('G', '\x03').replace('T', '\x04').replace('N', '\x00')
34
+
35
+ return map[np.fromstring(seq, np.int8) % 5]
36
+
37
+
38
+ def sai_predict_probs(seq: str, model) -> list:
39
+ '''
40
+ Predicts the donor and acceptor junction probability of each
41
+ NT in seq using SpliceAI.
42
+
43
+ Let m:=2*sai_mrg_context + L be the input seq length. It is assumed
44
+ that the input seq has the following structure:
45
+
46
+ seq = |<sai_mrg_context NTs><L NTs><sai_mrg_context NTs>|
47
+
48
+ The returned probability matrix is of size 2XL, where
49
+ the first row is the acceptor probability and the second row
50
+ is the donor probability. These probabilities corresponds to the
51
+ middel <L NTs> NTs of the input seq.
52
+ '''
53
+ x = one_hot_encode(seq)[None, :]
54
+ y = model(x)
55
+ y = y[0, :, 1:].T
56
+ return y[0, :], y[1, :]
57
+
58
+
59
+ def run_spliceai_seq(seq, indices, threshold=0):
60
+ # seq = 'N' * 5000 + seq + 'N' * 5000
61
+ ref_seq_probs_temp = sai_predict_probs(seq, model)
62
+ ref_seq_acceptor_probs, ref_seq_donor_probs = ref_seq_probs_temp[0, :], ref_seq_probs_temp[1, :]
63
+ acceptor_indices = {a: b for a, b in list(zip(indices, ref_seq_acceptor_probs)) if b >= threshold}
64
+ donor_indices = {a: b for a, b in list(zip(indices, ref_seq_donor_probs)) if b >= threshold}
65
+ return donor_indices, acceptor_indices
@@ -1,9 +1,10 @@
1
1
  # __all__ = ['run_splicing_engine', 'adjoin_splicing_outcomes', 'process_epistasis']
2
2
 
3
3
  import pandas as pd
4
- from typing import List, Tuple
4
+ from typing import List, Tuple, Optional
5
5
 
6
- def run_splicing_engine(seq: str, engine: str = 'spliceai') -> Tuple[List[float], List[float]]:
6
+ # def run_splicing_engine(seq: Optional[str] = None, engine: str = 'spliceai') -> Tuple[List[float], List[float]]:
7
+ def run_splicing_engine(seq: Optional[str] = None, engine: str = 'spliceai') -> Tuple[List[float], List[float]]:
7
8
  """
8
9
  Run the specified splicing engine to predict splice site probabilities on a sequence.
9
10
 
@@ -17,11 +18,19 @@ def run_splicing_engine(seq: str, engine: str = 'spliceai') -> Tuple[List[float]
17
18
  Raises:
18
19
  ValueError: If the engine is not implemented.
19
20
  """
21
+
22
+ if seq is None:
23
+ from geney.util.utils import generate_random_sequence
24
+ seq = generate_random_sequence(15_000)
25
+
20
26
  match engine:
21
27
  case 'spliceai':
22
- from geney.utils.spliceai_utils import sai_predict_probs, sai_models
23
- # print(seq)
24
- acceptor_probs, donor_probs = sai_predict_probs(seq, models=sai_models)
28
+ # from geney.utils.spliceai_utils import sai_predict_probs, sai_models
29
+ # acceptor_probs, donor_probs = sai_predict_probs(seq, models=sai_models)
30
+
31
+ from geney.utils.spliceai_pytorch_utils import sai_predict_probs, model
32
+ acceptor_probs, donor_probs = sai_predict_probs(seq, model=model)
33
+
25
34
  case 'pangolin':
26
35
  from geney.utils.pangolin_utils import pangolin_predict_probs, pang_models
27
36
  # print(seq)
geney/utils/utils.py CHANGED
@@ -6,6 +6,7 @@ import json
6
6
  # from pathlib import Path
7
7
  from bisect import bisect_left
8
8
  import hashlib
9
+ import random
9
10
 
10
11
  # def is_monotonic(A):
11
12
  # x, y = [], []
@@ -60,6 +61,9 @@ def is_monotonic(A):
60
61
  return all(x <= y for x, y in zip(A, A[1:])) or all(x >= y for x, y in zip(A, A[1:]))
61
62
 
62
63
 
64
+ def generate_random_sequence(length: int) -> str:
65
+ """Generates a random DNA sequence of given length (A, C, G, T)."""
66
+ return ''.join(random.choices('ACGT', k=length))
63
67
 
64
68
  def generate_random_nucleotide_sequences(num_sequences, min_len=3, max_len=10):
65
69
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: geney
3
- Version: 1.4.27
3
+ Version: 1.4.29
4
4
  Summary: A Python package for gene expression modeling.
5
5
  Home-page: https://github.com/nicolaslynn/geney
6
6
  Author: Nicolas Lynn
@@ -43,10 +43,11 @@ geney/utils/TranscriptLibrary.py,sha256=W1hv4Y8wRlmwTs3iFdn4_IqS-2suVDzZe4fwti2K
43
43
  geney/utils/__init__.py,sha256=-nJ-DMx1JzP-ZCe_QuQCeM0ZYIT_16jxoXDhUaO_4Oc,714
44
44
  geney/utils/mutation_utils.py,sha256=r-pHr56gEa5kh_DPX8MjFY3ZfYaOtyo4CUfJ5ZHlXPw,3243
45
45
  geney/utils/pangolin_utils.py,sha256=JQSPbWxdzqGFYfWQktkfLMaMSGR28eGQhNzO7MLMe5M,6162
46
+ geney/utils/spliceai_pytorch_utils.py,sha256=PfMgaoG6ftWfqKZKc_JNqj5wqQRUR2B-4YF22-zNh1M,2079
46
47
  geney/utils/spliceai_utils.py,sha256=VtrIbjyQxk_3lw86eWjftRYyal9OzxArJ0GV5u_ymTg,2721
47
- geney/utils/splicing_utils.py,sha256=vPCGnCPR1ooEZEHR79yFHLmRQXEJHXEQjjxpBR-YWOs,20635
48
- geney/utils/utils.py,sha256=m51Vd0cEbrcIHo6_8BAuI9YSPcKRs22e5LfVd2Qj6Is,2181
49
- geney-1.4.27.dist-info/METADATA,sha256=m4-HDmqjW43J6QhNdel4Luy18FvL4FXAHw-zE1hPDcQ,990
50
- geney-1.4.27.dist-info/WHEEL,sha256=AHX6tWk3qWuce7vKLrj7lnulVHEdWoltgauo8bgCXgU,109
51
- geney-1.4.27.dist-info/top_level.txt,sha256=O-FuNUMb5fn9dhZ-dYCgF0aZtfi1EslMstnzhc5IIVo,6
52
- geney-1.4.27.dist-info/RECORD,,
48
+ geney/utils/splicing_utils.py,sha256=wyO0CzNsfragDbAt9J016zxiA-MUuE2r9eyVAC0bZxk,21051
49
+ geney/utils/utils.py,sha256=GXqlatNhix1akt3fburNzIwhiW9ZdCQSt2vmU80neyA,2370
50
+ geney-1.4.29.dist-info/METADATA,sha256=DvrTqggg2aWWJ56k49iotD3zC0PO8VHWnvQwDxSPwho,990
51
+ geney-1.4.29.dist-info/WHEEL,sha256=AHX6tWk3qWuce7vKLrj7lnulVHEdWoltgauo8bgCXgU,109
52
+ geney-1.4.29.dist-info/top_level.txt,sha256=O-FuNUMb5fn9dhZ-dYCgF0aZtfi1EslMstnzhc5IIVo,6
53
+ geney-1.4.29.dist-info/RECORD,,
File without changes