import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import org.apache.http.NameValuePair;
public class SeqFetcher
{
- private static String ensemblRest = "rest.ensembl.org";
+ private final static String ENSEMBL_REST = "rest.ensembl.org";
private static boolean ensemblRestavailable = false;
}
try
{
- URL ping = new URL("http://" + ensemblRest + "/info/ping");
+ URL ping = new URL("http://" + ENSEMBL_REST + "/info/ping");
HttpURLConnection conn = (HttpURLConnection) (ping.openConnection());
if (conn.getResponseCode() >= 200 && conn.getResponseCode() < 300)
{
public SeqFetcher()
{
-
- // TODO Auto-generated constructor stub
}
public enum EnsemblSeqType
{
- GENOMIC, CDS, TRANSCRIPT, PROTEIN, CDNA;
+ GENOMIC("genomic"), CDS("cds"), TRANSCRIPT("cds"), PROTEIN("protein"), CDNA(
+ "cdna");
+
+ private String type;
+
+ EnsemblSeqType(String t)
+ {
+ type = t;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
}
/**
*/
public List<NameValuePair> getObjectTypeArg(EnsemblSeqType type)
{
- String arg;
- switch (type)
- {
- case CDS:
- arg = "cds";
- break;
- case TRANSCRIPT:
- arg = "cds";
- break;
- case CDNA:
- arg = "cdna";
- break;
- case PROTEIN:
- arg = "protein";
- break;
- case GENOMIC:
- default:
- arg = "genomic";
- }
- return Arrays.asList(new NameValuePair[]
- { new BasicNameValuePair("type", arg) });
+ NameValuePair nameValue = new BasicNameValuePair("type", type.getType());
+ return Collections.singletonList(nameValue);
}
/**
// adapted From the rest.ensembl.org documentation for sequence_id
- String urls = "http://" + ensemblRest + "/sequence/id";
+ String urls = "http://" + ENSEMBL_REST + "/sequence/id";
List<NameValuePair> vals = getObjectTypeArg(returnType);
boolean f = true;
for (NameValuePair nvp : vals)