# Note: Works with Python 3 and up
import urllib.request, urllib.parse
# ########################################################################################################
# class library mirDIP_Http #
# ########################################################################################################
class mirDIP_Http:
mapScore = {
'Very High' : '0',
'High' : '1',
'Medium' : '2',
'Low' : '3'
}
url = "http://ophid.utoronto.ca/mirDIP"
map = {} # results will be here
def __init__(self):
return
# unidirectional on genes
def unidirectionalSearchOnGenes(self, geneSymbols, minimumScore):
self.sendPost(self.url + "/Http_U", geneSymbols, '', self.mapScore[minimumScore])
return
# unidirectional on microrna(s)
def unidirectionalSearchOnMicroRNAs(self, microRNAs, minimumScore):
self.sendPost(self.url + "/Http_U", '', microRNAs, self.mapScore[minimumScore])
return
# bidirectional
def bidirectionalSearch(self, geneSymbols, microRNAs, minimumScore, sources, occurrances):
'''
String url_b = url + "/Http_B";
String parameters =
"genesymbol=" + geneSymbols +
"&" + "microrna=" + microRNAs +
"&" + "scoreClass=" + mapScore.get(minimumScore) +
"&" + "dbOccurrences=" + occurrances +
"&" + "sources=" + sources;
int responseCode = sendPost(url_b, parameters);
return responseCode;
'''
self.sendPost(self.url + "/Http_B", geneSymbols, microRNAs, self.mapScore[minimumScore], sources, occurrances)
return
# .. serve POST request
def sendPost(self, url_, geneSymbols, microrna, minimumScore, sources = '', occurrances = '1'):
params = {
'genesymbol' : geneSymbols,
'microrna' : microrna,
'scoreClass' : minimumScore,
'dbOccurrences' : occurrances,
'sources' : sources}
params = bytes( urllib.parse.urlencode( params ).encode() )
response = ''
try:
handler = urllib.request.urlopen(url_, params)
except Exception:
traceback.print_exc()
else:
self.response = handler.read().decode('utf-8')
## print(self.response)
self.makeMap()
return
def makeMap(self):
ENTRY_DEL = 0x01
KEY_DEL = 0x02
arr = self.response.split(chr(ENTRY_DEL))
for str in arr:
arrKeyValue = str.split(chr(KEY_DEL));
if len(arrKeyValue) > 1:
self.map[arrKeyValue[0]] = arrKeyValue[1]
return
def getGeneratedAt(self):
if "generated_at" in self.map:
return self.map["generated_at"]
else:
return ''
def getGeneSymbols(self):
if "gene_symbols" in self.map:
return self.map["gene_symbols"]
else:
return ''
def getMicroRNAs(self):
if "micro_rnas" in self.map:
return self.map["micro_rnas"]
else:
return ''
def getMinimumScore(self):
if "minimum_score" in self.map:
return self.map["minimum_score"]
else:
return ''
def getDatabaseOccurrences(self):
if "dbOccurrences" in self.map:
return self.map["dbOccurrences"]
else:
return ''
def getSources(self):
if "sources" in self.map:
return self.map["sources"]
else:
return ''
def getResulsSize(self):
if "results_size" in self.map:
return self.map["results_size"]
else:
return ''
def getResuls(self):
if "results" in self.map:
return self.map["results"]
else:
return ''
#########################################################################################################
# Pick-up right sample for your search #
#########################################################################################################
# Note: Adjust 'ophid.utoronto.ca' if you are using our development server.
# **************************************************
# Example of Unidirectional search on Gene Symbols *
# **************************************************
# GeneSymbols
# - Comma delimited.
# - Follow to HUGO approved spelling.)
geneSymbols = "AKAP17A,AKR1C2,APP,ZZZ3,MARK4,C17orf51"
# Minimum Score
# - Use one of those: 'Very High', 'High', 'Medium', 'Low'.
# - Mind exact spelling.
minimumScore = "Very High"
o = mirDIP_Http() # note: re-instance with every search !!!
o.unidirectionalSearchOnGenes(geneSymbols, minimumScore)
# print results
print("\r\n Unidirectional Search on Genes: \r\n")
print("Generated at: " + o.getGeneratedAt())
print("Gene Symbols: " + o.getGeneSymbols())
print("Minimum Score: " + o.getMinimumScore())
print("Results Size: " + o.getResulsSize())
print("Results: \r\n" + o.getResuls()); # formatted as tab-delimited spreadsheet
# ***********************************************
# Example of Unidirectional search on MicroRNAs *
# ***********************************************
# MicroRMAs
# - Comma delimited.
# - Follow the notation as shown.
microRNAs = "hsa-miR-603, hsa-let-7a-3p, hsa-miR-625-5p, hsa-miR-7852-3p, hsa-miR-17-5p"
# Minimum Score
# - Use one of those: 'Very High', 'High', 'Medium', 'Low'.
# - Mind exact spelling.
minimumScore = "Very High"
o = mirDIP_Http() # note: re-instance with every search !!!
o.unidirectionalSearchOnMicroRNAs(microRNAs, minimumScore)
# print results
print("\n Unidirectional Search on microRNAs \n");
print("Generated at: " + o.getGeneratedAt());
print("Micro RNAs: " + o.getMicroRNAs());
print("Minimum Score: " + o.getMinimumScore());
print("Results Size: " + o.getResulsSize());
print("Results: \r\n" + o.getResuls()); # formatted as tab-delimited spreadsheet
# *********************************
# Example of Bidirectional search *
# *********************************
# GeneSymbols
# - Comma delimited.
# - Follow to HUGO approved spelling.
geneSymbols = "AKAP17A,AKR1C2,APP,ZZZ3,MARK4, C17orf51"
# MicroRMAs
# - Comma delimited;
# - Follow the notation as shown.
microRNAs = "hsa-miR-603,hsa-let-7a-3p,hsa-miR-625-5p,hsa-miR-7852-3p," + \
"hsa-miR-17-5p,hsa-miR-4321,hsa-miR-758-3p"
# Minimum Score
# - Use one of those: 'Very High', 'High', 'Medium', 'Low'.
# - Mind exact spelling.
minimumScore = "Very High"
# Sources
# - Use ony combination of those:
# bitargeting_May_2021, BCmicrO, CoMeTa, Cupid, DIANA, miranda_May_2021,
# mirbase, mirCoX, mirmap_May_2021, mirzag, miRcode, miRDB_v6, miRTar2GO,
# MBStar, MirAncesTar, MirSNPInTarget, MirTar2, MiRNATIP, MultiMiTar, PACCMIT,
# PITA_May_2021, rnahybrid_May_2021, RNA22, TargetScan_v7_2
# - Mind exact spelling
sources = "bitargeting_May_2021, BCmicrO, CoMeTa, Cupid, DIANA, miranda_May_2021, " + \
"mirbase, mirCoX, mirmap_May_2021, mirzag, miRcode, miRDB_v6, miRTar2GO, " + \
"MBStar, MirAncesTar, MirSNPInTarget, MirTar2, MiRNATIP, MultiMiTar, PACCMIT, " + \
"PITA_May_2021, rnahybrid_May_2021, RNA22, TargetScan_v7_2"
# Data
# Database Occurrences (named as 'Number of Sources' on 'Bidirectional search' web page):
# - Use this option to select microRNA target predictions that are
# present in at least a given number of sources - irrespective
# of what those sources are.
# - The valid values are: from 1 to 24
occurrances = '2'
o = mirDIP_Http() # note: re-instance with every search !!!
o.bidirectionalSearch(geneSymbols, microRNAs, minimumScore, sources, occurrances)
# print results
print("\n Bidirectioanl Search: \n")
print("Generated at: " + o.getGeneratedAt())
print("Gene Symbols: " + o.getGeneSymbols())
print("Minimum Score: " + o.getMinimumScore())
print("Database Occurrences: " + o.getDatabaseOccurrences())
print("Source Filter: " + o.getSources())
print("Results Size: " + o.getResulsSize())
print("Results: \r\n" + o.getResuls()); # formatted as tab-delimited spreadsheet