Skip to content

Commit

Permalink
Auto-download complex and family data
Browse files Browse the repository at this point in the history
  • Loading branch information
dustine32 committed Apr 28, 2020
1 parent 0b96894 commit 67e915f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
28 changes: 28 additions & 0 deletions download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import requests
import os
from requests.models import Response


class SignorDownloader:
@staticmethod
def write_response_content(response: Response, file_basename, destination_dir=None):
if destination_dir is None:
destination_dir = "resources"
file_target = os.path.join(destination_dir, file_basename)
with open(file_target, "wb") as ft:
ft.write(response.content)
return file_target

@staticmethod
def download_complexes(destination_dir=None):
response = requests.post(url="https://signor.uniroma2.it/download_complexes.php",
data={"submit": "Download complex data"})
file_basename = "SIGNOR_complexes.csv"
return SignorDownloader.write_response_content(response, file_basename, destination_dir=destination_dir)

@staticmethod
def download_families(destination_dir=None):
response = requests.post(url="https://signor.uniroma2.it/download_complexes.php",
data={"submit": "Download protein family data"})
file_basename = "SIGNOR_PF.csv"
return SignorDownloader.write_response_content(response, file_basename, destination_dir=destination_dir)
26 changes: 20 additions & 6 deletions entity_factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import csv
import os
from naming_conventions import NamingConvention
from entity_models import SignorEntity, SignorProtein, SignorComplex, SignorProteinFamily
from download import SignorDownloader


class SignorGroupingFactory:
Expand Down Expand Up @@ -28,26 +30,38 @@ def __init__(self, filename):


class SignorComplexFactory(SignorGroupingFactory):
def __init__(self, filename):
FILENAME = "resources/SIGNOR_complexes.csv"

def __init__(self, filename=None):
if filename is None:
filename = self.FILENAME
if not os.path.exists(filename):
filename = SignorDownloader.download_complexes()

self.NAME_FIELD = "COMPLEX NAME"
self.GROUPING_CLASS = SignorComplex
SignorGroupingFactory.__init__(self, filename)
self.complexes = self.grouping


class SignorProteinFamilyFactory(SignorGroupingFactory):
def __init__(self, filename):
FILENAME = "resources/SIGNOR_PF.csv"

def __init__(self, filename=None):
if filename is None:
filename = self.FILENAME
if not os.path.exists(filename):
filename = SignorDownloader.download_families()

self.NAME_FIELD = "PROT. FAMILY NAME"
self.GROUPING_CLASS = SignorProteinFamily
SignorGroupingFactory.__init__(self, filename)
self.families = self.grouping


class SignorEntityFactory:
complex_csv_filename = "SIGNOR_complexes.csv"
complex_factory = SignorComplexFactory(complex_csv_filename)
family_csv_filename = "SIGNOR_PF.csv"
family_factory = SignorProteinFamilyFactory(family_csv_filename)
complex_factory = SignorComplexFactory()
family_factory = SignorProteinFamilyFactory()

@classmethod
def determine_entity(cls, entity_id: str, entity_name: str) -> SignorEntity:
Expand Down
3 changes: 1 addition & 2 deletions pathway_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from rdflib.term import URIRef
from prefixcommons.curie_util import expand_uri
from entity_factories import SignorEntityFactory
from naming_conventions import NamingConvention
from entity_models import SignorEntity, SignorProtein, SignorComplex
from entity_models import SignorEntity

ro = OboRO()

Expand Down

0 comments on commit 67e915f

Please sign in to comment.