annotate data_manager/resource_building.py @ 5:b05fa99ddda2 draft

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