import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class MyMain {
public static void main(String[] args) {
// ... 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.)
String geneSymbols = "AKAP17A,AKR1C2,APP,ZZZ3,MARK4,C17orf51";
// Minimum Score
// - Use one of those: 'Very High', 'High', 'Medium', 'Low'.
// - Mind exact spelling.
String minimumScore = "Very High";
mirDIP_Http o = new mirDIP_Http();
int responseCode = o.unidirectionalSearchOnGenes(geneSymbols, minimumScore);
if (responseCode != 200) {
System.out.println("Error: Response Code : " + responseCode);
} else {
// print results
System.out.println("\n Unidirectional Search on Genes: \n");
System.out.println("Generated at: " + o.getGeneratedAt());
System.out.println("Gene Symbols: " + o.getGeneSymbols());
System.out.println("Minimum Score: " + o.getMinimumScore());
System.out.println("Results Size: " + o.getResulsSize());
System.out.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.
String 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.
String minimumScore = "Very High";
mirDIP_Http o = new mirDIP_Http();
int responseCode = o.unidirectionalSearchOnMicroRNAs(microRNAs, minimumScore);
if (responseCode != 200) {
System.out.println("Error: Response Code : " + responseCode);
} else {
// print results
System.out.println("\n Unidirectional Search on microRNAs \n");
System.out.println("Generated at: " + o.getGeneratedAt());
System.out.println("Micro RNAs: " + o.getMicroRNAs());
System.out.println("Minimum Score: " + o.getMinimumScore());
System.out.println("Results Size: " + o.getResulsSize());
System.out.print("Results: \r\n" + o.getResuls()); // formatted as tab-delimited spreadsheet
}
}
// */
// /*
// *********************************
// Example of Bidirectional search *
// *********************************
{
// GeneSymbols
// - Comma delimited.
// - Follow to HUGO approved spelling.
String geneSymbols =
"AKAP17A,AKR1C2,APP,ZZZ3,MARK4, C17orf51";
// MicroRMAs
// - Comma delimited;
// - Follow the notation as shown.
String 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.
String minimumScore = "Very High";
// Sources
// - Use only 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
String 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
int occurrances = 2;
mirDIP_Http o = new mirDIP_Http();
int responseCode = o.bidirectionalSearch(geneSymbols,
microRNAs, minimumScore, sources, occurrances);
if (responseCode != 200) {
System.out.println("Error: Response Code : " + responseCode);
} else {
// print results
System.out.println("\n Bidirectioanl Search: \n");
System.out.println("Generated at: " + o.getGeneratedAt());
System.out.println("Gene Symbols: " + o.getGeneSymbols());
System.out.println("Minimum Score: " + o.getMinimumScore());
System.out.println("Database Occurrences: " + o.getDatabaseOccurrences());
System.out.println("Source Filter: " + o.getSources());
System.out.println("Results Size: " + o.getResulsSize());
System.out.print("Results: \r\n" + o.getResuls()); // formatted as tab-delimited spreadsheet
}
}
// */
}
}
// ... Add mirDIP_Http class to your code.
class mirDIP_Http {
private final String USER_AGENT = "Mozilla/5.0";
final static Map<String, Integer> mapScore = new HashMap<String, Integer>();
static {
mapScore.put("Very High", 0);
mapScore.put("High", 1);
mapScore.put("Medium", 2);
mapScore.put("Low", 3);
}
final private String url = "http://ophid.utoronto.ca/mirDIP";
private final StringBuilder response = new StringBuilder();
private final Map<String, String> map = new HashMap<String, String>();
int unidirectionalSearchOnGenes(String geneSymbols, String minimumScore) {
String url_u = url + "/Http_U";
String parameters =
"genesymbol=" + geneSymbols + "&" + "microrna=" + "&" + "scoreClass=" +
mapScore.get(minimumScore);
int responseCode = sendPost(url_u, parameters);
return responseCode;
}
int unidirectionalSearchOnMicroRNAs(String microRNAs, String minimumScore) {
String url_u = url + "/Http_U";
String parameters =
"genesymbol=" + "&" + "microrna=" + microRNAs + "&" + "scoreClass=" +
mapScore.get(minimumScore);
int responseCode = sendPost(url_u, parameters);
return responseCode;
}
int bidirectionalSearch(String geneSymbols,
String microRNAs, String minimumScore, String sources, int 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;
}
// .. server GET request
int sendGet(String url_, String parameters) {
try {
URL obj = new URL(url_ + "?" + parameters);
// ... make request
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", USER_AGENT);
// ... get response
int responseCode = con.getResponseCode();
if (responseCode == 200) {
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String end_line = System.getProperty("line.separator");
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine).append(end_line);
}
in.close();
}
con.disconnect();
// .. format response
if (responseCode == 200) makeMap(response);
return responseCode;
} catch (IOException e) {
e.printStackTrace(System.err);
}
return 520; // 520 Unknown Error
}
// .. serve POST request
int sendPost(String url_, String parameters) {
try {
URL obj = new URL(url_);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
// ... send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(parameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
if (responseCode == 200) {
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String end_line = System.getProperty("line.separator");
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine).append(end_line);
}
in.close();
}
con.disconnect();
// .. format response
if (responseCode == 200) makeMap(response);
return responseCode;
} catch (IOException e) {
e.printStackTrace(System.err);
}
return 520; // 520 Unknown Error
}
void makeMap(StringBuilder response) {
final char ENTRY_DEL = 0x01;
final char KEY_DEL = 0x02;
String[] arr = response.toString().split(String.valueOf(ENTRY_DEL));
for (String str : arr) {
String[] arrKeyValue = str.split(String.valueOf(KEY_DEL));
if (arrKeyValue.length > 1) map.put(arrKeyValue[0], arrKeyValue[1]);
}
}
String getGeneratedAt() {return (map.get("generated_at") == null) ? "" : map.get("generated_at");}
String getGeneSymbols() {return (map.get("gene_symbols") == null) ? "" : map.get("gene_symbols");}
String getMicroRNAs() {return (map.get("micro_rnas") == null) ? "" : map.get("micro_rnas");}
String getMinimumScore() {return (map.get("minimum_score") == null) ? "" : map.get("minimum_score");}
String getDatabaseOccurrences() {return (map.get("dbOccurrences") == null) ? "" : map.get("dbOccurrences");}
String getSources() {return (map.get("sources") == null) ? "" : map.get("sources");}
String getResulsSize() {return (map.get("results_size") == null) ? "" : map.get("results_size");}
String getResuls() {return (map.get("results") == null) ? "" : map.get("results");}
}