Mercurial > repos > proteore > proteore_data_manager
annotate data_manager/resource_building.py @ 4:e967a99d66b3 draft
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
author | proteore |
---|---|
date | Thu, 23 Jan 2020 08:38:02 -0500 |
parents | af0250fd023c |
children | b05fa99ddda2 |
rev | line source |
---|---|
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
2 """ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
3 The purpose of this script is to create source files from different databases to be used in other proteore tools |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
4 """ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
5 |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
6 import os, shutil, sys, argparse, requests, time, csv, re, json, shutil, zipfile, subprocess |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
7 from io import BytesIO |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
8 from zipfile import ZipFile |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
9 from galaxy.util.json import from_json_string, to_json_string |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
10 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
11 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
12 # General functions |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
13 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
14 def unzip(url, output_file): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
15 """ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
16 Get a zip file content from a link and unzip |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
17 """ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
18 content = requests.get(url) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
19 zipfile = ZipFile(BytesIO(content.content)) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
20 output_content = "" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
21 output_content += zipfile.open(zipfile.namelist()[0]).read() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
22 output = open(output_file, "w") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
23 output.write(output_content) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
24 output.close() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
25 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
26 def _add_data_table_entry(data_manager_dict, data_table_entry,data_table): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
27 data_manager_dict['data_tables'] = data_manager_dict.get('data_tables', {}) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
28 data_manager_dict['data_tables'][data_table] = data_manager_dict['data_tables'].get(data_table, []) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
29 data_manager_dict['data_tables'][data_table].append(data_table_entry) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
30 return data_manager_dict |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
31 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
32 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
33 # 1. Human Protein Atlas |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
34 # - Normal tissue |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
35 # - Pathology |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
36 # - Full Atlas |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
37 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
38 def HPA_sources(data_manager_dict, tissue, target_directory): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
39 if tissue == "HPA_normal_tissue": |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
40 tissue_name = "HPA normal tissue" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
41 url = "https://www.proteinatlas.org/download/normal_tissue.tsv.zip" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
42 table = "proteore_protein_atlas_normal_tissue" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
43 elif tissue == "HPA_pathology": |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
44 tissue_name = "HPA pathology" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
45 url = "https://www.proteinatlas.org/download/pathology.tsv.zip" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
46 table = "proteore_protein_atlas_tumor_tissue" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
47 elif tissue == "HPA_full_atlas": |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
48 tissue_name = "HPA full atlas" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
49 url = "https://www.proteinatlas.org/download/proteinatlas.tsv.zip" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
50 table = "proteore_protein_full_atlas" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
51 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
52 output_file = tissue +"_"+ time.strftime("%d-%m-%Y") + ".tsv" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
53 path = os.path.join(target_directory, output_file) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
54 unzip(url, path) #download and save file |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
55 tissue_name = tissue_name + " " + time.strftime("%d/%m/%Y") |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
56 release = tissue_name.replace(" ","_").replace("/","-") |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
57 id = str(10000000000 - int(time.strftime("%Y%m%d"))) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
58 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
59 |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
60 data_table_entry = dict(id=id, release=release, name = tissue_name, tissue = tissue, value = path) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
61 _add_data_table_entry(data_manager_dict, data_table_entry, table) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
62 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
63 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
64 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
65 # 2. Peptide Atlas |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
66 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
67 def peptide_atlas_sources(data_manager_dict, tissue, date, target_directory): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
68 # Define organism_id (here Human) - to be upraded when other organism added to the project |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
69 organism_id = "2" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
70 # Extract sample_category_id and output filename |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
71 tissue=tissue.split(".") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
72 sample_category_id = tissue[0] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
73 tissue_name = tissue[1] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
74 output_file = tissue_name+"_"+date + ".tsv" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
75 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
76 query="https://db.systemsbiology.net/sbeams/cgi/PeptideAtlas/GetProteins?&atlas_build_id="+ \ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
77 sample_category_id+"&display_options=ShowAbundances&organism_id="+organism_id+ \ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
78 "&redundancy_constraint=4&presence_level_constraint=1%2C2&gene_annotation_level_constraint=leaf\ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
79 &QUERY_NAME=AT_GetProteins&action=QUERY&output_mode=tsv&apply_action=QUERY" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
80 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
81 with requests.Session() as s: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
82 download = s.get(query) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
83 decoded_content = download.content.decode('utf-8') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
84 cr = csv.reader(decoded_content.splitlines(), delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
85 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
86 uni_dict = build_dictionary(cr) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
87 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
88 #columns of data table peptide_atlas |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
89 tissue_id = tissue_name+"_"+date |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
90 name = tissue_id.replace("-","/").replace("_"," ") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
91 path = os.path.join(target_directory,output_file) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
92 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
93 with open(path,"w") as out : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
94 w = csv.writer(out,delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
95 w.writerow(["Uniprot_AC","nb_obs"]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
96 w.writerows(uni_dict.items()) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
97 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
98 data_table_entry = dict(id=tissue_id, name=name, value = path, tissue = tissue_name) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
99 _add_data_table_entry(data_manager_dict, data_table_entry, "proteore_peptide_atlas") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
100 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
101 #function to count the number of observations by uniprot id |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
102 def build_dictionary (csv) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
103 uni_dict = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
104 for line in csv : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
105 if "-" not in line[0] and check_uniprot_access(line[0]) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
106 if line[0] in uni_dict : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
107 uni_dict[line[0]] += int(line[5]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
108 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
109 uni_dict[line[0]] = int(line[5]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
110 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
111 return uni_dict |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
112 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
113 #function to check if an id is an uniprot accession number : return True or False- |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
114 def check_uniprot_access (id) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
115 uniprot_pattern = re.compile("[OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2}") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
116 if uniprot_pattern.match(id) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
117 return True |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
118 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
119 return False |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
120 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
121 def check_entrez_geneid (id) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
122 entrez_pattern = re.compile("[0-9]+|[A-Z]{1,2}_[0-9]+|[A-Z]{1,2}_[A-Z]{1,4}[0-9]+") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
123 if entrez_pattern.match(id) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
124 return True |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
125 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
126 return False |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
127 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
128 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
129 # 3. ID mapping file |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
130 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
131 import ftplib, gzip |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
132 csv.field_size_limit(sys.maxsize) # to handle big files |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
133 |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
134 def id_mapping_sources (data_manager_dict, species, target_directory, tool_data_path) : |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
135 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
136 human = species == "Human" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
137 species_dict = { "Human" : "HUMAN_9606", "Mouse" : "MOUSE_10090", "Rat" : "RAT_10116" } |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
138 files=["idmapping_selected.tab.gz","idmapping.dat.gz"] |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
139 archive = os.path.join(tool_data_path, "id_mapping/ID_mapping_archive_"+species+"_"+str(time.strftime("%Y%m%d"))) |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
140 if os.path.isdir(archive) is False : os.mkdir(archive) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
141 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
142 #header |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
143 if human : tab = [["UniProt-AC","UniProt-AC_reviewed","UniProt-ID","GeneID","RefSeq","GI","PDB","GO","PIR","MIM","UniGene","Ensembl_Gene","Ensembl_Transcript","Ensembl_Protein","neXtProt","BioGrid","STRING","KEGG",'Gene_Name']] |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
144 else : tab = [["UniProt-AC","UniProt-AC_reviewed","UniProt-ID","GeneID","RefSeq","GI","PDB","GO","PIR","MIM","UniGene","Ensembl_Gene","Ensembl_Transcript","Ensembl_Protein","BioGrid","STRING","KEGG",'Gene_Name']] |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
145 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
146 #get selected.tab and keep only ids of interest |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
147 selected_tab_file=species_dict[species]+"_"+files[0] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
148 tab_path = download_from_uniprot_ftp(selected_tab_file,target_directory) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
149 with gzip.open(tab_path,"rt") as select : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
150 tab_reader = csv.reader(select,delimiter="\t") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
151 for line in tab_reader : |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
152 tab.append([line[0]]+[line[i] for i in [0,1,2,3,4,5,6,11,13,14,18,19,20]]) |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
153 if os.path.exists(os.path.join(archive,tab_path.split("/")[-1])) : os.remove(os.path.join(archive,tab_path.split("/")[-1])) |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
154 shutil.move(tab_path, archive) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
155 #print("selected_tab ok") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
156 |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
157 #get uniprot-AC reviewed |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
158 organism = species_dict[species].split("_")[1] |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
159 query = "https://www.uniprot.org/uniprot/?query=reviewed:yes+AND+organism:"+organism+"&format=list" |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
160 |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
161 with requests.Session() as s: |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
162 download = s.get(query) |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
163 decoded_content = download.content.decode('utf-8') |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
164 uniprot_reviewed_list = decoded_content.splitlines() |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
165 |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
166 #save reviewed list |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
167 reviewed_list_path = os.path.join(archive,'uniprot_reviewed_list.txt') |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
168 with open(reviewed_list_path,'w') as reviewed_list_file: |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
169 for id in uniprot_reviewed_list: |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
170 reviewed_list_file.write(id+"\n") |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
171 |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
172 #remove unreviewed uniprot-AC |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
173 for line in tab[1:]: |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
174 UniProtAC = line[1] |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
175 if UniProtAC not in uniprot_reviewed_list : |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
176 line[1]="" |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
177 |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
178 """ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
179 Supplementary ID to get from HUMAN_9606_idmapping.dat : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
180 -NextProt,BioGrid,STRING,KEGG |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
181 """ |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
182 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
183 #there's more id type for human |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
184 if human : ids = ['neXtProt','BioGrid','STRING','KEGG','Gene_Name' ] #ids to get from dat_file |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
185 else : ids = ['BioGrid','STRING','KEGG','Gene_Name' ] |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
186 unidict = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
187 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
188 #keep only ids of interest in dictionaries |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
189 dat_file = species_dict[species]+"_"+files[1] |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
190 dat_path = download_from_uniprot_ftp(dat_file,target_directory) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
191 with gzip.open(dat_path,"rt") as dat : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
192 dat_reader = csv.reader(dat,delimiter="\t") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
193 for line in dat_reader : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
194 uniprotID=line[0] #UniProtID as key |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
195 id_type=line[1] #ID type of corresponding id, key of sub-dictionnary |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
196 cor_id=line[2] #corresponding id |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
197 if "-" not in id_type : #we don't keep isoform |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
198 if id_type in ids and uniprotID in unidict : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
199 if id_type in unidict[uniprotID] : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
200 unidict[uniprotID][id_type]= ";".join([unidict[uniprotID][id_type],cor_id]) #if there is already a value in the dictionnary |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
201 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
202 unidict[uniprotID].update({ id_type : cor_id }) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
203 elif id_type in ids : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
204 unidict[uniprotID]={id_type : cor_id} |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
205 if os.path.exists(os.path.join(archive,dat_path.split("/")[-1])) : os.remove(os.path.join(archive,dat_path.split("/")[-1])) |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
206 shutil.move(dat_path, archive) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
207 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
208 #print("dat_file ok") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
209 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
210 #add ids from idmapping.dat to the final tab |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
211 for line in tab[1:] : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
212 uniprotID=line[0] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
213 if human : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
214 if uniprotID in unidict : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
215 nextprot = access_dictionary(unidict,uniprotID,'neXtProt') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
216 if nextprot != '' : nextprot = clean_nextprot_id(nextprot,line[0]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
217 line.extend([nextprot,access_dictionary(unidict,uniprotID,'BioGrid'),access_dictionary(unidict,uniprotID,'STRING'), |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
218 access_dictionary(unidict,uniprotID,'KEGG'),access_dictionary(unidict,uniprotID,'Gene_Name')]) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
219 else : |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
220 line.extend(["","","","",""]) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
221 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
222 if uniprotID in unidict : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
223 line.extend([access_dictionary(unidict,uniprotID,'BioGrid'),access_dictionary(unidict,uniprotID,'STRING'), |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
224 access_dictionary(unidict,uniprotID,'KEGG'),access_dictionary(unidict,uniprotID,'Gene_Name')]) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
225 else : |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
226 line.extend(["","","",""]) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
227 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
228 #print ("tab ok") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
229 |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
230 #add missing nextprot ID for human or replace old ones |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
231 if human : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
232 #build next_dict |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
233 nextprot_path = id_list_from_nextprot_ftp("nextprot_ac_list_all.txt",target_directory) |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
234 with open(nextprot_path,'r') as nextprot_ids : |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
235 nextprot_ids = nextprot_ids.read().splitlines() |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
236 if os.path.exists(os.path.join(archive,nextprot_path.split("/")[-1])) : os.remove(os.path.join(archive,nextprot_path.split("/")[-1])) |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
237 shutil.move(nextprot_path,archive) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
238 next_dict = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
239 for nextid in nextprot_ids : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
240 next_dict[nextid.replace("NX_","")] = nextid |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
241 #os.remove(os.path.join(target_directory,"nextprot_ac_list_all.txt")) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
242 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
243 #add missing nextprot ID |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
244 for line in tab[1:] : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
245 uniprotID=line[0] |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
246 nextprotID=line[14] |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
247 if uniprotID in next_dict and (nextprotID == '' or (nextprotID != "NX_"+uniprotID and next_dict[uniprotID] == "NX_"+uniprotID)) : |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
248 line[14]=next_dict[uniprotID] |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
249 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
250 output_file = species+"_id_mapping_"+ time.strftime("%d-%m-%Y") + ".tsv" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
251 path = os.path.join(target_directory,output_file) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
252 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
253 with open(path,"w") as out : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
254 w = csv.writer(out,delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
255 w.writerows(tab) |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
256 |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
257 subprocess.call(['tar', '-czvf', archive+".tar.gz", archive]) |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
258 shutil.rmtree(archive, ignore_errors=True) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
259 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
260 name_dict={"Human" : "Homo sapiens", "Mouse" : "Mus musculus", "Rat" : "Rattus norvegicus"} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
261 name = species +" (" + name_dict[species]+" "+time.strftime("%d/%m/%Y")+")" |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
262 release = species+"_id_mapping_"+ time.strftime("%d-%m-%Y") |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
263 id = str(10000000000 - int(time.strftime("%Y%m%d"))) #new ids must be inferior to previous id -> sort by <filter> in xml only in descending order |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
264 |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
265 data_table_entry = dict(id=id, release=release , name = name, species = species, value = path) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
266 _add_data_table_entry(data_manager_dict, data_table_entry, "proteore_id_mapping_"+species) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
267 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
268 def download_from_uniprot_ftp(file,target_directory) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
269 ftp_dir = "pub/databases/uniprot/current_release/knowledgebase/idmapping/by_organism/" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
270 path = os.path.join(target_directory, file) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
271 ftp = ftplib.FTP("ftp.uniprot.org") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
272 ftp.login("anonymous", "anonymous") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
273 ftp.cwd(ftp_dir) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
274 ftp.retrbinary("RETR " + file, open(path, 'wb').write) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
275 ftp.quit() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
276 return (path) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
277 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
278 def id_list_from_nextprot_ftp(file,target_directory) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
279 ftp_dir = "pub/current_release/ac_lists/" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
280 path = os.path.join(target_directory, file) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
281 ftp = ftplib.FTP("ftp.nextprot.org") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
282 ftp.login("anonymous", "anonymous") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
283 ftp.cwd(ftp_dir) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
284 ftp.retrbinary("RETR " + file, open(path, 'wb').write) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
285 ftp.quit() |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
286 |
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
287 return (path) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
288 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
289 #return '' if there's no value in a dictionary, avoid error |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
290 def access_dictionary (dico,key1,key2) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
291 if key1 in dico : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
292 if key2 in dico[key1] : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
293 return (dico[key1][key2]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
294 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
295 return ("") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
296 #print (key2,"not in ",dico,"[",key1,"]") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
297 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
298 return ('') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
299 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
300 #if there are several nextprot ID for one uniprotID, return the uniprot like ID |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
301 def clean_nextprot_id (next_id,uniprotAc) : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
302 if len(next_id.split(";")) > 1 : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
303 tmp = next_id.split(";") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
304 if "NX_"+uniprotAc in tmp : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
305 return ("NX_"+uniprotAc) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
306 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
307 return (tmp[1]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
308 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
309 return (next_id) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
310 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
311 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
312 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
313 # 4. Build protein interaction maps files |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
314 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
315 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
316 def get_interactant_name(line,dico): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
317 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
318 if line[0] in dico : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
319 interactant_A = dico[line[0]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
320 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
321 interactant_A = "NA" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
322 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
323 if line[1] in dico : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
324 interactant_B = dico[line[1]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
325 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
326 interactant_B = "NA" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
327 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
328 return interactant_A, interactant_B |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
329 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
330 def PPI_ref_files(data_manager_dict, species, interactome, target_directory): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
331 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
332 species_dict={'Human':'Homo sapiens',"Mouse":"Mus musculus","Rat":"Rattus norvegicus"} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
333 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
334 ##BioGRID |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
335 if interactome=="biogrid": |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
336 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
337 tab2_link="https://downloads.thebiogrid.org/Download/BioGRID/Release-Archive/BIOGRID-3.5.167/BIOGRID-ORGANISM-3.5.167.tab2.zip" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
338 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
339 #download zip file |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
340 r = requests.get(tab2_link) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
341 with open("BioGRID.zip", "wb") as code: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
342 code.write(r.content) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
343 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
344 #unzip files |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
345 with zipfile.ZipFile("BioGRID.zip", 'r') as zip_ref: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
346 if not os.path.exists("tmp_BioGRID"): os.makedirs("tmp_BioGRID") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
347 zip_ref.extractall("tmp_BioGRID") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
348 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
349 #import file of interest and build dictionary |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
350 file_path="tmp_BioGRID/BIOGRID-ORGANISM-"+species_dict[species].replace(" ","_")+"-3.5.167.tab2.txt" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
351 with open(file_path,"r") as handle : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
352 tab_file = csv.reader(handle,delimiter="\t") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
353 dico_network = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
354 GeneID_index=1 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
355 network_cols=[1,2,7,8,11,12,14,18,20] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
356 for line in tab_file : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
357 if line[GeneID_index] not in dico_network: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
358 dico_network[line[GeneID_index]]=[[line[i] for i in network_cols]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
359 else: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
360 dico_network[line[GeneID_index]].append([line[i] for i in network_cols]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
361 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
362 #delete tmp_BioGRID directory |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
363 os.remove("BioGRID.zip") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
364 shutil.rmtree("tmp_BioGRID", ignore_errors=True) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
365 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
366 #download NCBI2Reactome.txt file and build dictionary |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
367 with requests.Session() as s: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
368 r = s.get('https://www.reactome.org/download/current/NCBI2Reactome.txt') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
369 r.encoding ="utf-8" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
370 tab_file = csv.reader(r.content.splitlines(), delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
371 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
372 dico_nodes = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
373 geneid_index=0 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
374 pathway_description_index=3 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
375 species_index=5 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
376 for line in tab_file : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
377 if line[species_index]==species_dict[species]: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
378 if line[geneid_index] in dico_nodes : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
379 dico_nodes[line[geneid_index]].append(line[pathway_description_index]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
380 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
381 dico_nodes[line[geneid_index]] = [line[pathway_description_index]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
382 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
383 dico={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
384 dico['network']=dico_network |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
385 dico['nodes']=dico_nodes |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
386 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
387 ##Bioplex |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
388 elif interactome=="bioplex": |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
389 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
390 with requests.Session() as s: |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
391 r = s.get('http://bioplex.hms.harvard.edu/data/BioPlex_interactionList_v4a.tsv') |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
392 r = r.content.decode('utf-8') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
393 bioplex = csv.reader(r.splitlines(), delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
394 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
395 dico_network = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
396 dico_network["GeneID"]={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
397 network_geneid_cols=[0,1,4,5,8] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
398 dico_network["UniProt-AC"]={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
399 network_uniprot_cols=[2,3,4,5,8] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
400 dico_GeneID_to_UniProt = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
401 for line in bioplex : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
402 if line[0] not in dico_network["GeneID"]: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
403 dico_network["GeneID"][line[0]]=[[line[i] for i in network_geneid_cols]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
404 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
405 dico_network["GeneID"][line[0]].append([line[i] for i in network_geneid_cols]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
406 if line[1] not in dico_network["UniProt-AC"]: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
407 dico_network["UniProt-AC"][line[2]]=[[line[i] for i in network_uniprot_cols]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
408 else: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
409 dico_network["UniProt-AC"][line[2]].append([line[i] for i in network_uniprot_cols]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
410 dico_GeneID_to_UniProt[line[0]]=line[2] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
411 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
412 with requests.Session() as s: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
413 r = s.get('https://reactome.org/download/current/UniProt2Reactome.txt') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
414 r.encoding ="utf-8" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
415 tab_file = csv.reader(r.content.splitlines(), delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
416 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
417 dico_nodes_uniprot = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
418 uniProt_index=0 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
419 pathway_description_index=3 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
420 species_index=5 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
421 for line in tab_file : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
422 if line[species_index]==species_dict[species]: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
423 if line[uniProt_index] in dico_nodes_uniprot : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
424 dico_nodes_uniprot[line[uniProt_index]].append(line[pathway_description_index]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
425 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
426 dico_nodes_uniprot[line[uniProt_index]] = [line[pathway_description_index]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
427 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
428 with requests.Session() as s: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
429 r = s.get('https://www.reactome.org/download/current/NCBI2Reactome.txt') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
430 r.encoding ="utf-8" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
431 tab_file = csv.reader(r.content.splitlines(), delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
432 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
433 dico_nodes_geneid = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
434 geneid_index=0 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
435 pathway_description_index=3 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
436 species_index=5 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
437 for line in tab_file : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
438 if line[species_index]==species_dict[species]: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
439 if line[geneid_index] in dico_nodes_geneid : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
440 dico_nodes_geneid[line[geneid_index]].append(line[pathway_description_index]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
441 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
442 dico_nodes_geneid[line[geneid_index]] = [line[pathway_description_index]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
443 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
444 dico={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
445 dico_nodes={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
446 dico_nodes['GeneID']=dico_nodes_geneid |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
447 dico_nodes['UniProt-AC']=dico_nodes_uniprot |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
448 dico['network']=dico_network |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
449 dico['nodes']=dico_nodes |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
450 dico['convert']=dico_GeneID_to_UniProt |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
451 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
452 ##Humap |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
453 elif interactome=="humap": |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
454 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
455 with requests.Session() as s: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
456 r = s.get('http://proteincomplexes.org/static/downloads/nodeTable.txt') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
457 r = r.content.decode('utf-8') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
458 humap_nodes = csv.reader(r.splitlines(), delimiter=',') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
459 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
460 dico_geneid_to_gene_name={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
461 dico_protein_name={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
462 for line in humap_nodes : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
463 if check_entrez_geneid(line[4]): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
464 if line[4] not in dico_geneid_to_gene_name: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
465 dico_geneid_to_gene_name[line[4]]=line[3] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
466 if line[4] not in dico_protein_name: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
467 dico_protein_name[line[4]]=line[5] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
468 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
469 with requests.Session() as s: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
470 r = s.get('http://proteincomplexes.org/static/downloads/pairsWprob.txt') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
471 r = r.content.decode('utf-8') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
472 humap = csv.reader(r.splitlines(), delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
473 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
474 dico_network = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
475 for line in humap : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
476 if check_entrez_geneid(line[0]) and check_entrez_geneid(line[1]): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
477 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
478 interactant_A, interactant_B = get_interactant_name(line,dico_geneid_to_gene_name) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
479 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
480 #first interactant (first column) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
481 if line[0] not in dico_network: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
482 dico_network[line[0]]=[line[:2]+[interactant_A,interactant_B,line[2]]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
483 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
484 dico_network[line[0]].append(line[:2]+[interactant_A,interactant_B,line[2]]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
485 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
486 #second interactant (second column) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
487 if line[1] not in dico_network: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
488 dico_network[line[1]]=[[line[1],line[0],interactant_B,interactant_A,line[2]]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
489 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
490 dico_network[line[1]].append([line[1],line[0],interactant_B,interactant_A,line[2]]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
491 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
492 with requests.Session() as s: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
493 r = s.get('https://www.reactome.org/download/current/NCBI2Reactome.txt') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
494 r.encoding ="utf-8" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
495 tab_file = csv.reader(r.content.splitlines(), delimiter='\t') |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
496 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
497 dico_nodes = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
498 geneid_index=0 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
499 pathway_description_index=3 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
500 species_index=5 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
501 for line in tab_file : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
502 if line[species_index]==species_dict[species]: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
503 #Fill dictionary with pathways |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
504 if line[geneid_index] in dico_nodes : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
505 dico_nodes[line[geneid_index]].append(line[pathway_description_index]) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
506 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
507 dico_nodes[line[geneid_index]] = [line[pathway_description_index]] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
508 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
509 dico={} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
510 dico['network']=dico_network |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
511 dico['nodes']=dico_nodes |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
512 dico['gene_name']=dico_geneid_to_gene_name |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
513 dico['protein_name']=dico_protein_name |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
514 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
515 #writing output |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
516 output_file = species+'_'+interactome+'_'+ time.strftime("%Y-%m-%d") + ".json" |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
517 path = os.path.join(target_directory,output_file) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
518 name = species+" ("+species_dict[species]+") "+time.strftime("%d/%m/%Y") |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
519 release = species+"_"+interactome+"_"+ time.strftime("%Y-%m-%d") |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
520 id = str(10000000000 - int(time.strftime("%Y%m%d"))) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
521 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
522 with open(path, 'w') as handle: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
523 json.dump(dico, handle, sort_keys=True) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
524 |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
525 data_table_entry = dict(id=id, release=release, name = name, species = species, value = path) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
526 _add_data_table_entry(data_manager_dict, data_table_entry, "proteore_"+interactome+"_dictionaries") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
527 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
528 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
529 # 5. nextprot (add protein features) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
530 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
531 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
532 def Build_nextprot_ref_file(data_manager_dict,target_directory): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
533 nextprot_ids_file = "nextprot_ac_list_all.txt" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
534 ids = id_list_from_nextprot_ftp(nextprot_ids_file,target_directory) |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
535 |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
536 output_file = 'nextprot_ref_'+ time.strftime("%d-%m-%Y") + ".tsv" |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
537 path = os.path.join(target_directory,output_file) |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
538 name = "neXtProt release "+time.strftime("%d-%m-%Y") |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
539 release_id = "nextprot_ref_"+time.strftime("%d-%m-%Y") |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
540 |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
541 output = open(path, 'w') |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
542 writer = csv.writer(output,delimiter="\t") |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
543 |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
544 nextprot_file=[["NextprotID","MW","SeqLength","IsoPoint","Chr","SubcellLocations","Diseases","TMDomains","ProteinExistence"]] |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
545 writer.writerows(nextprot_file) |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
546 |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
547 for id in ids : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
548 #print (id) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
549 query="https://api.nextprot.org/entry/"+id+".json" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
550 resp = requests.get(url=query) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
551 data = resp.json() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
552 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
553 #get info from json dictionary |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
554 mass_mol = data["entry"]["isoforms"][0]["massAsString"] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
555 seq_length = data['entry']["isoforms"][0]["sequenceLength"] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
556 iso_elec_point = data['entry']["isoforms"][0]["isoelectricPointAsString"] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
557 chr_loc = data['entry']["chromosomalLocations"][0]["chromosome"] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
558 protein_existence = "PE"+str(data['entry']["overview"]['proteinExistence']['level']) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
559 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
560 #put all subcell loc in a set |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
561 if "subcellular-location" in data['entry']["annotationsByCategory"].keys() : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
562 subcell_locs = data['entry']["annotationsByCategory"]["subcellular-location"] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
563 all_subcell_locs = set() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
564 for loc in subcell_locs : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
565 all_subcell_locs.add(loc['cvTermName']) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
566 all_subcell_locs.discard("") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
567 all_subcell_locs = ";".join(all_subcell_locs) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
568 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
569 all_subcell_locs = "NA" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
570 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
571 #put all subcell loc in a set |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
572 if ('disease') in data['entry']['annotationsByCategory'].keys() : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
573 diseases = data['entry']['annotationsByCategory']['disease'] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
574 all_diseases = set() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
575 for disease in diseases : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
576 if (disease['cvTermName'] is not None and disease['cvTermName'] != ""): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
577 all_diseases.add(disease['cvTermName']) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
578 if len(all_diseases) > 0 : all_diseases = ";".join(all_diseases) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
579 else : all_diseases="NA" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
580 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
581 all_diseases="NA" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
582 |
1
f3507260b30f
planemo upload commit 39a9e2bf22b07beeca3fb77d86cda25820eb309c
proteore
parents:
0
diff
changeset
|
583 #get all tm domain |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
584 nb_domains = 0 |
1
f3507260b30f
planemo upload commit 39a9e2bf22b07beeca3fb77d86cda25820eb309c
proteore
parents:
0
diff
changeset
|
585 if "transmembrane-region" in data['entry']['annotationsByCategory'].keys(): |
f3507260b30f
planemo upload commit 39a9e2bf22b07beeca3fb77d86cda25820eb309c
proteore
parents:
0
diff
changeset
|
586 tm_domains = data['entry']['annotationsByCategory']["transmembrane-region"] |
f3507260b30f
planemo upload commit 39a9e2bf22b07beeca3fb77d86cda25820eb309c
proteore
parents:
0
diff
changeset
|
587 all_tm_domains = set() |
f3507260b30f
planemo upload commit 39a9e2bf22b07beeca3fb77d86cda25820eb309c
proteore
parents:
0
diff
changeset
|
588 for tm in tm_domains : |
f3507260b30f
planemo upload commit 39a9e2bf22b07beeca3fb77d86cda25820eb309c
proteore
parents:
0
diff
changeset
|
589 all_tm_domains.add(tm['cvTermName']) |
f3507260b30f
planemo upload commit 39a9e2bf22b07beeca3fb77d86cda25820eb309c
proteore
parents:
0
diff
changeset
|
590 nb_domains+=1 |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
591 #print "nb domains ++" |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
592 #print (nb_domains) |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
593 nextprot_file[:] = [] |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
594 nextprot_file.append([id,mass_mol,str(seq_length),iso_elec_point,chr_loc,all_subcell_locs,all_diseases,str(nb_domains),protein_existence]) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
595 writer.writerows(nextprot_file) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
596 |
2
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
597 id = str(10000000000 - int(time.strftime("%Y%m%d"))) |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
598 |
9ec42cb35abd
planemo upload commit 339ab77a83db03409c8001324f10b36ff5b13a39-dirty
proteore
parents:
1
diff
changeset
|
599 data_table_entry = dict(id=id, release=release_id, name = name, value = path) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
600 _add_data_table_entry(data_manager_dict, data_table_entry, "proteore_nextprot_ref") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
601 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
602 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
603 # Main function |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
604 ####################################################################################################### |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
605 def main(): |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
606 parser = argparse.ArgumentParser() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
607 parser.add_argument("--hpa", metavar = ("HPA_OPTION")) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
608 parser.add_argument("--peptideatlas", metavar=("SAMPLE_CATEGORY_ID")) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
609 parser.add_argument("--id_mapping", metavar = ("ID_MAPPING_SPECIES")) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
610 parser.add_argument("--interactome", metavar = ("PPI")) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
611 parser.add_argument("--species") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
612 parser.add_argument("--date") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
613 parser.add_argument("-o", "--output") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
614 parser.add_argument("--database") |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
615 parser.add_argument("--tool_data_path") |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
616 args = parser.parse_args() |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
617 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
618 data_manager_dict = {} |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
619 # Extract json file params |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
620 filename = args.output |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
621 params = from_json_string(open(filename).read()) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
622 target_directory = params[ 'output_data' ][0]['extra_files_path'] |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
623 os.mkdir(target_directory) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
624 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
625 ## Download source files from HPA |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
626 try: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
627 hpa = args.hpa |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
628 except NameError: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
629 hpa = None |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
630 if hpa is not None: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
631 #target_directory = "/projet/galaxydev/galaxy/tools/proteore/ProteoRE/tools/resources_building/test-data/" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
632 hpa = hpa.split(",") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
633 for hpa_tissue in hpa: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
634 HPA_sources(data_manager_dict, hpa_tissue, target_directory) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
635 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
636 ## Download source file from Peptide Atlas query |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
637 try: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
638 peptide_atlas = args.peptideatlas |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
639 date = args.date |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
640 except NameError: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
641 peptide_atlas = None |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
642 if peptide_atlas is not None: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
643 #target_directory = "/projet/galaxydev/galaxy/tools/proteore/ProteoRE/tools/resources_building/test-data/" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
644 peptide_atlas = peptide_atlas.split(",") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
645 for pa_tissue in peptide_atlas: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
646 peptide_atlas_sources(data_manager_dict, pa_tissue, date, target_directory) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
647 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
648 ## Download ID_mapping source file from Uniprot |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
649 try: |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
650 id_mapping = args.id_mapping |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
651 except NameError: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
652 id_mapping = None |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
653 if id_mapping is not None: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
654 id_mapping = id_mapping .split(",") |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
655 for species in id_mapping : |
4
e967a99d66b3
"planemo upload commit 540dd383c0617193db43bf11457011888751b022-dirty"
proteore
parents:
3
diff
changeset
|
656 id_mapping_sources(data_manager_dict, species, target_directory, args.tool_data_path) |
0
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
657 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
658 ## Download PPI ref files from biogrid/bioplex/humap |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
659 try: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
660 interactome=args.interactome |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
661 if interactome == "biogrid" : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
662 species=args.species |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
663 else : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
664 species="Human" |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
665 except NameError: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
666 interactome=None |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
667 species=None |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
668 if interactome is not None and species is not None: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
669 PPI_ref_files(data_manager_dict, species, interactome, target_directory) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
670 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
671 ## Build nextprot ref file for add protein features |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
672 try: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
673 database=args.database |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
674 except NameError: |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
675 database=None |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
676 if database is not None : |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
677 Build_nextprot_ref_file(data_manager_dict,target_directory) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
678 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
679 #save info to json file |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
680 filename = args.output |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
681 open(filename, 'wb').write(to_json_string(data_manager_dict)) |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
682 |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
683 if __name__ == "__main__": |
9e31ea9fc7ea
planemo upload commit 567ba7934c0ca55529dfeb5e7ca0935ace260ad7-dirty
proteore
parents:
diff
changeset
|
684 main() |