dspin 1.5.0__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.
- dspin/__init__.py +21 -0
- dspin/annotate.py +461 -0
- dspin/compute.py +1690 -0
- dspin/dspin.py +869 -0
- dspin/gpt.py +65 -0
- dspin/metadata_drug.py +13 -0
- dspin/plot.py +776 -0
- dspin-1.5.0.dist-info/METADATA +49 -0
- dspin-1.5.0.dist-info/RECORD +12 -0
- dspin-1.5.0.dist-info/WHEEL +5 -0
- dspin-1.5.0.dist-info/licenses/LICENSE +201 -0
- dspin-1.5.0.dist-info/top_level.txt +1 -0
dspin/gpt.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import openai
|
|
2
|
+
import csv
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
system_question = "Your are a desperate biology phd professor studying gene expression from a dataset of cancer patients. Given following a list of genes in the gene program, you have two tasks: \
|
|
7
|
+
Firstly, summarize functions of the program in a few important functions. \
|
|
8
|
+
Secondly, give a higher-level name of the gene program based on its function. You are required by your mentor to name it as short as possible.\
|
|
9
|
+
You get 100 score if you can name it in two or three words, 80 score if you can name it in four words, 20 score for five or more words. \
|
|
10
|
+
A limitation to this general rule is that you will lose 20 score if you name a gene program similar 'Gene Expression Program' or 'Gene Regulation Progran'. \
|
|
11
|
+
Please also avoid 'cancer' in the name you give. \
|
|
12
|
+
The results should be in the format: name: (your answer) \n function 1: (), related genes: ();\
|
|
13
|
+
function 2: (), related genes: ();\
|
|
14
|
+
..... (more functions and their annotation, please don't list more than 10 functions)\
|
|
15
|
+
You will be given a list of genes in the same gene program in each user input. "
|
|
16
|
+
|
|
17
|
+
def init_openai_api(api_key):
|
|
18
|
+
openai.api_key = api_key
|
|
19
|
+
|
|
20
|
+
def gene_program_csv_to_list(file_path) -> List[str]:
|
|
21
|
+
data = pd.read_csv(file_path)
|
|
22
|
+
gene_programs = []
|
|
23
|
+
for col in data.columns:
|
|
24
|
+
column_values = data[col].dropna().tolist()
|
|
25
|
+
gene_programs.append(','.join(column_values))
|
|
26
|
+
return gene_programs
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def generate_response(gene_program):
|
|
30
|
+
messages = list()
|
|
31
|
+
messages.append({"role": "system", "content": system_question})
|
|
32
|
+
messages.append({"role": "user", "content": gene_program})
|
|
33
|
+
try:
|
|
34
|
+
response = openai.ChatCompletion.create(
|
|
35
|
+
model = "gpt-3.5-turbo",
|
|
36
|
+
messages=messages, # The starting prompt for the AI
|
|
37
|
+
max_tokens=1024, # Adjust the desired response length
|
|
38
|
+
temperature=0, # Controls the randomness of the response
|
|
39
|
+
n=1, # Number of responses to generate
|
|
40
|
+
)
|
|
41
|
+
# Get the response text from the API response
|
|
42
|
+
response_text = response['choices'][0]['message']['content']
|
|
43
|
+
return response_text
|
|
44
|
+
except Exception as e:
|
|
45
|
+
return str(e)
|
|
46
|
+
|
|
47
|
+
def generate_responses_to_csv(file_path, output_file_path):
|
|
48
|
+
gene_programs = gene_program_csv_to_list(file_path)
|
|
49
|
+
data = []
|
|
50
|
+
responses = []
|
|
51
|
+
for i in range(49,50):
|
|
52
|
+
data_string = generate_response(gene_programs[i])
|
|
53
|
+
responses.append(data_string)
|
|
54
|
+
colon_index = data_string.find(':')
|
|
55
|
+
newline_index = data_string.find('\n')
|
|
56
|
+
name = data_string[colon_index + 1: newline_index]
|
|
57
|
+
name = name.strip('Program')
|
|
58
|
+
function = data_string[newline_index + 1:]
|
|
59
|
+
data[i] = (i, name, function, gene_programs[i])
|
|
60
|
+
print(str(i) + " program done" )
|
|
61
|
+
|
|
62
|
+
with open(output_file_path, 'w', newline = '') as f:
|
|
63
|
+
writer = csv.writer(f)
|
|
64
|
+
writer.writerow(['index', 'name', 'function', 'genes'])
|
|
65
|
+
writer.writerows(data)
|
dspin/metadata_drug.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
num_spin = 30
|
|
4
|
+
|
|
5
|
+
net_class = [[14, 15, 19, 16, 18, 17], [23, 22, 24, 25], [13, 10, 11, 12], [28, 26, 27, 29, 0], [9, 3, 2, 4], [7, 8, 21], [6, 1, 5], [20]]
|
|
6
|
+
|
|
7
|
+
spin_order = [spin for cur_list in net_class for spin in cur_list]
|
|
8
|
+
net_class_len = [len(cur_list) for cur_list in net_class]
|
|
9
|
+
|
|
10
|
+
spin_name = ['Antigen presentation', 'Inflammatory cytokines', 'M2 macrophage', 'Monocyte', 'Myeloid growth', 'Metallothionein', 'Pathogen response', 'Inflammatory macrophage', 'Complement/chemokine', 'Myeloid cell', 'T-cell cytotoxicity', 'Effector CD8 T-cell', 'NK cell', 'Granzyme K T-cell', 'Naive T-cell', 'T-cell maintenance', 'Lymphocyte', 'T-cell', 'Resting maintainence', 'Housekeeping', 'Stress response', 'Dendritic cell', 'Histone', 'T-cell activation', 'Regulatory T-cell', 'T-cell exhaustion', 'B-cell activation', 'Naive B-cell', 'B-cell', 'Resting B-cell']
|
|
11
|
+
|
|
12
|
+
spin_pname = ['P' + str(spin_order.index(ii) + 1) for ii in range(num_spin)]
|
|
13
|
+
spin_name_extend = ['P' + str(spin_order.index(ii) + 1) + '-' + spin_name[ii] for ii in range(num_spin)]
|