-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
183 lines (167 loc) · 4.66 KB
/
test.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
# import requests
#
# def get_gene_name(accession_number):
# # Send a GET request to the UniProt API
# url = "https://www.uniprot.org/uniprot/" + accession_number + ".xml"
# r = requests.get(url)
# xml_data = r.text
#
# # Parse the XML data
# import xml.etree.ElementTree as ET
# root = ET.fromstring(xml_data)
# # print(xml_data)
#
# # # Find the gene name
# # for entry in root.findall('./entry'):
# #
# # for name in entry.findall('./gene/name'):
# # return name.text
#
# entry = root.find(add_uniprot_url('./entry'))
# # gene_name = get_info(entry, add_uniprot_url('./gene/name[@type="primary"]'))
#
#
# # print(get_info(entry, add_uniprot_url('./dbReference[@type = "GO"]')))
# # print(get_info(entry, add_uniprot_url('./dbReference/property[@type = "term"]')))
# x = str(get_info(entry, add_uniprot_url('./dbReference/property[@type = "term"]')))
# print(len(x))
#
# return x
#
#
# def get_info(entry, xml_path):
# # if there is no entry, e.g. no ecNumber since protein is not an enzyme
# if not entry.findall(xml_path):
# # print("no attribute found")
# extracted_info = float("NaN")
# else:
# extracted_info = str()
# for info in entry.findall(xml_path):
# extracted_info += ", " + info.get('value')
# # print(info.get('value'))
# return extracted_info
#
# def add_uniprot_url(xml_path):
# long_path = xml_path.replace("/", "/{http://uniprot.org/uniprot}")
# return long_path
#
#
# # Test the function
# accession_number = "P05771" #PKC beta
# gene_name = get_gene_name(accession_number)
# print(gene_name)
# ####
# gene_name = get_info(entry, add_uniprot_url('./gene/name[@type="primary"]'))
# test running .R in python
# import subprocess
#
# path_Rscript = "C:/Users/M02847/AppData/Local/Programs/R/R-4.2.1/bin/Rscript.exe"
# path_R_file = "/Users/M02847/Desktop/test.R"
# input = "/Users/M02847/Desktop/test.xlsx"
#
# cmd = path_Rscript + " " + path_R_file + " " + input
# print(cmd)
# # res = subprocess.call("C:/Users/M02847/AppData/Local/Programs/R/R-4.2.1/bin/Rscript.exe /Users/M02847/Desktop/test.R", shell=True)
# # res
#
# test = subprocess.call(cmd, shell=True)
# test
# # test creating dir, if dir is not there
# import os
# path = 'C:/Users/monar/Google Drive/Arbeit/homeoffice/230103_RH review/barr1+2 interactome/stringDB_data/'
# try:
# os.mkdir(path + "/OG_stringDB_data/")
# except FileExistsError:
# print("already there")
# pass
# import xlrd
# xlrd.xlsx.ensure_elementtree_imported(False, None)
# xlrd.xlsx.Element_has_iter = True
#
# import pandas as pd
# # homeoffice path
# path = 'C:/Users/monar/Google Drive/Arbeit/homeoffice/230103_RH review/barr1+2 interactome/stringDB_data/OG_stringDB_data/'
# df = pd.read_excel(path + "interactors_stringDB.xlsx")
# print(df)
# import pandas as pd
#
# x = [1,1,1,1,12,3,3,4,5,6123,1,2,65,46,5,42,33,4,5,8,5,5]
# a = [1,12,3,3,4,5]
# b = [1,5,46,4,8,9]
# C = list(set(x)-set(a))
#
# # filter_set = set(a)
# # C = [a for a in x if a not in filter_set]
# # print(C)
#
#
# # translation_df[translation_df["ENSP"] == ENSP]["ID"]
#
# df = pd.DataFrame([a,b])
# df.rename(columns = {0: "X"}, inplace=True)
# df.rename(columns = {1: "Y"}, inplace=True)
# print(df)
#
# print(df[df["X"] == 1]["Y"])
# print(df[df["X"] == 0]["Y"])
#
# d = df[df["X"] == 0]["Y"]
# print(len(d))
#
# # test removing row based on value in Y
# # pendant in STRINGdb would be score >= 0.5
# print(df["Y"]>=5)
# x = df[df["Y"]>5]
# print(x)
#
# import pandas as pd
#
# a = [float("NaN"),12,3,3,4,5]
# b = [4,5,6,7,8,3]
# df = pd.DataFrame([a,b])
# df.rename(columns = {0: "X"}, inplace=True)
# print(df)
#
# print("index of X == NA")
# print(df[df["X"]==float("NaN")].index)
#
# df = df.dropna(axis = 'index')
# print("dropped row df")
# print(df)
#
# import pandas as pd
#
# a = [float("NaN"),12,3,3,4,5]
# b = [4,5,6,7,8,3]
# df = pd.DataFrame([a,b])
# print(df)
# print(df[range(3,5)])
# print(len(df.columns))
# import pandas as pd
# a = [1,12,3,3,4,5]
# b = [1,5,46,4,8,9]
# df = pd.DataFrame([a,b])
# df.rename(columns = {0: "X"}, inplace=True)
# df.rename(columns = {1: "Y"}, inplace=True)
# print(df)
#
# print("---------")
# df2 = pd.DataFrame([b,a])
# df2.rename(columns = {0: "X"}, inplace=True)
# df2.rename(columns = {1: "Y"}, inplace=True)
# print(df2)
# print("---------")
# print(df.iloc[: , 4:6])
# # df.iloc[1,2].join(df2.iloc[3])
#
# print(df2[df2["X"]==1].index)
#
# print(df[["X", "Y"]])
import pandas as pd
a = [1,12,3,3,4,5]
df = pd.DataFrame([a,a])
print(df)
df.rename(columns = {0: "X"}, inplace=True)
df.rename(columns = {1: "Y"}, inplace=True)
print(df.columns)
print(df.columns[0:len(df.columns)-2])