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