77import numpy as np
88import pandas as pd
99import rpy2 .robjects as ro
10+ from fast_bioservices import BioDBNet , Input , Output
1011from GSEpipeline import load_gse_soft
1112from instruments import AffyIO
12-
13- # from fast_bioservices import BioDBNet, Input, Output
14- from multi_bioservices .biodbnet import InputDatabase , OutputDatabase , TaxonID , db2db
1513from rpy2 .robjects import pandas2ri
1614
1715pandas2ri .activate ()
2119
2220# gse = load_gse_soft(gsename)
2321
22+ from fast_bioservices import BioDBNet , Input , Output
23+
2424
25- def download_gsm_id_maps (datadir , gse , gpls : Optional [list [str ]] = None , vendor = "affy" ):
25+ def download_gsm_id_maps (
26+ datadir ,
27+ gse ,
28+ biodbnet : BioDBNet ,
29+ taxon_id : int ,
30+ gpls : Optional [list [str ]] = None ,
31+ vendor = "affy" ,
32+ ):
2633 """
2734 download ID to ENTREZ_GENE_ID maps, create a csv file for each platform, and return dictionary
2835 :param gpls:
@@ -46,18 +53,19 @@ def download_gsm_id_maps(datadir, gse, gpls: Optional[list[str]] = None, vendor=
4653 table ["CONTROL_TYPE" ] == "FALSE" , "SPOT_ID"
4754 ].tolist ()
4855
49- temp = db2db (
56+ temp = biodbnet . db2db (
5057 input_values = input_values ,
51- input_db = InputDatabase .AGILENT_ID ,
52- output_db = [OutputDatabase .GENE_ID , OutputDatabase .ENSEMBL_GENE_ID ],
58+ input_db = Input .AGILENT_ID ,
59+ output_db = [Output .GENE_ID , Output .ENSEMBL_GENE_ID ],
60+ taxon = taxon_id ,
5361 )
5462
5563 temp .drop (columns = ["Ensembl Gene ID" ], inplace = True )
5664 temp .reset_index (inplace = True )
5765 temp .rename (
5866 columns = {
59- InputDatabase .AGILENT_ID .value : "ID" ,
60- OutputDatabase .GENE_ID .value : "ENTREZ_GENE_ID" ,
67+ Input .AGILENT_ID .value : "ID" ,
68+ Output .GENE_ID .value : "ENTREZ_GENE_ID" ,
6169 },
6270 inplace = True ,
6371 )
@@ -74,14 +82,27 @@ def download_gsm_id_maps(datadir, gse, gpls: Optional[list[str]] = None, vendor=
7482
7583
7684class GSEproject :
77- def __init__ (self , gsename , querytable , rootdir = "../" ):
85+ def __init__ (
86+ self ,
87+ gsename ,
88+ querytable ,
89+ show_biodbnet_progress : bool = False ,
90+ use_biodbnet_cache : bool = True ,
91+ rootdir = "../" ,
92+ ):
7893 self .gsename = gsename
7994 # Setup paths
8095 self .querytable = querytable
8196 self .rootdir = rootdir
8297 self .datadir = os .path .join (self .rootdir , "data" )
8398 self .outputdir = os .path .join (self .rootdir , "output" )
8499 self .gene_dir = os .path .join (self .datadir , self .gsename + "_RAW" )
100+
101+ self .biodbnet = BioDBNet (
102+ show_progress = show_biodbnet_progress ,
103+ cache = use_biodbnet_cache ,
104+ )
105+
85106 print (
86107 "Initialize project ({}):\n Root: {}\n Raw data: {}" .format (
87108 self .gsename , self .rootdir , self .gene_dir
@@ -137,7 +158,13 @@ def get_gsm_tables(self):
137158 if not os .path .isfile (filepath ):
138159 # Could improve to automatic download new tables based on platform
139160 gse = load_gse_soft (self .gsename )
140- download_gsm_id_maps (self .datadir , gse , gpls = [gpl ], vendor = vendor )
161+ download_gsm_id_maps (
162+ self .datadir ,
163+ gse ,
164+ gpls = [gpl ],
165+ vendor = vendor ,
166+ biodbnet = self .biodbnet ,
167+ )
141168 print ("Skip Unsupported Platform: {}, {}" .format (gpl , vendor ))
142169 # continue
143170 temp = pd .read_csv (filepath )
@@ -225,16 +252,6 @@ def get_entrez_table_pipeline(self, fromcsv=True):
225252 output_db = [OutputDatabase .GENE_ID ],
226253 )
227254
228- outputdf = instruments .readagilent (
229- platformdir , list (self .gsm_platform .keys ())
230- )
231-
232- gsm_maps [key ] = db2db (
233- input_values = list (map (str , list (outputdf ["ProbeName" ]))),
234- input_db = InputDatabase .AGILENT_ID ,
235- output_db = [OutputDatabase .GENE_ID ],
236- )
237-
238255 gsm_maps [key ].rename (
239256 columns = {"Gene ID" : "ENTREZ_GENE_ID" }, inplace = True
240257 )
@@ -271,23 +288,23 @@ def get_entrez_table_pipeline(self, fromcsv=True):
271288 how = "outer" ,
272289 )
273290
274- df_outer_sc500 .dropna (how = "all" , inplace = True ) # type: ignore
275- print ("Full: {}" .format (df_outer_sc500 .shape )) # type: ignore
276- df_outer_sc500 .rename (str .lower , axis = "columns" , inplace = True ) # type: ignore
291+ df_outer_sc500 .dropna (how = "all" , inplace = True )
292+ print ("Full: {}" .format (df_outer_sc500 .shape ))
293+ df_outer_sc500 .rename (str .lower , axis = "columns" , inplace = True )
277294 keys = []
278295 vals = []
279296 gsms_loaded = []
280297
281- for col in list (df_outer_sc500 ): # type: ignore
282- if ".cel.gz" in col : # type: ignore
283- strs = col .split (".cel.gz" ) # type: ignore
298+ for col in list (df_outer_sc500 ):
299+ if ".cel.gz" in col :
300+ strs = col .split (".cel.gz" )
284301 gsm = strs [0 ].split ("_" )[0 ]
285302 newcol = "{}.cel.gz{}" .format (gsm , strs [- 1 ])
286303 vals .append (newcol )
287304 keys .append (col )
288305 gsms_loaded .append (gsm )
289306
290- df_outer_sc500 .rename (columns = dict (zip (keys , vals )), inplace = True ) # type: ignore
307+ df_outer_sc500 .rename (columns = dict (zip (keys , vals )), inplace = True )
291308 gsms_loaded = list (set (gsms_loaded ).union (set (self .gsm_platform .keys ())))
292309
293310 # Remove duplicated items, keep largest VALUE for each GSM
@@ -329,7 +346,7 @@ def get_entrez_table_pipeline(self, fromcsv=True):
329346 )
330347
331348 try :
332- temp = df_outer_sc500 .loc [:, [col1 , col2 , col3 ]] # type: ignore
349+ temp = df_outer_sc500 .loc [:, [col1 , col2 , col3 ]]
333350
334351 except :
335352 if key in list (self .gsm_platform .keys ()):
0 commit comments