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