Skip to content

Commit

Permalink
GoogleAPI progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Jun 28, 2014
1 parent 4524922 commit 8ff0419
Show file tree
Hide file tree
Showing 18 changed files with 3,809 additions and 353 deletions.
73 changes: 32 additions & 41 deletions src/org/broad/igv/batch/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ public void run() {
private void processClientSession(CommandExecutor cmdExe) throws IOException {
PrintWriter out = null;
BufferedReader in = null;

try {
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String inputLine;


while (!halt && (inputLine = in.readLine()) != null) {

String cmd = inputLine;
Expand All @@ -137,56 +137,47 @@ private void processClientSession(CommandExecutor cmdExe) throws IOException {
String nextLine = in.readLine();
while (nextLine != null && nextLine.length() > 0) {
nextLine = in.readLine();
String [] tokens = Globals.colonPattern.split(nextLine, 2);
if(tokens.length == 2) {
String[] tokens = Globals.colonPattern.split(nextLine, 2);
if (tokens.length == 2) {
headers.put(tokens[0].trim(), tokens[1].trim());
}
}
if(headers.containsKey("Sec-WebSocket-Key"))
{
establishWebSocketConnection(out, headers);

}
else {
log.info(cmd);


String command = null;
Map<String, String> params = null;
String[] tokens = inputLine.split(" ");
if (tokens.length < 2) {
sendHTTPResponse(out, "ERROR unexpected command line: " + inputLine);
return;
} else {
String[] parts = tokens[1].split("\\?");
if (parts.length < 2) {
sendHTTPResponse(out, "ERROR unexpected command line: " + inputLine);
return;
} else {
command = parts[0];
params = parseParameters(parts[1]);
}
}
log.info(cmd);

String command = null;
Map<String, String> params = null;
String[] tokens = inputLine.split(" ");
if (tokens.length < 2) {
sendHTTPResponse(out, "ERROR unexpected command line: " + inputLine);
return;
} else {
String[] parts = tokens[1].split("\\?");

// If a callback (javascript) function is specified write it back immediately. This function
// is used to cancel a timeout handler
String callback = params.get("callback");
if (callback != null) {
sendHTTPResponse(out, callback);
}
command = parts[0];
params = parts.length < 2 ? new HashMap() : parseParameters(parts[1]);

processGet(command, params, cmdExe);
}

// If no callback was specified write back a "no response" header
if (callback == null) {
sendHTTPResponse(out, null);
}

// http sockets are used for one request only
return;
// If a callback (javascript) function is specified write it back immediately. This function
// is used to cancel a timeout handler
String callback = params.get("callback");
if (callback != null) {
sendHTTPResponse(out, callback);
}

processGet(command, params, cmdExe);

// If no callback was specified write back a "no response" header
if (callback == null) {
sendHTTPResponse(out, null);
}

// http sockets are used for one request only
return;
// }

} else {
// Port command
Globals.setBatch(true);
Expand Down Expand Up @@ -216,7 +207,7 @@ private void establishWebSocketConnection(PrintWriter out, Map<String, String> h
out.print("Upgrade: websocket" + CRNL);
out.print("Connection: Upgrade" + CRNL);
out.print("Sec-WebSocket-Accept: " + responseKey + CRNL);
if(headers.containsKey("Sec-WebSocket-Protocol")) {
if (headers.containsKey("Sec-WebSocket-Protocol")) {
out.print("Sec-WebSocket-Protocol: " + headers.get("Sec-WebSocket-Protocol") + CRNL);
}
out.print(CRNL);
Expand Down
15 changes: 1 addition & 14 deletions src/org/broad/igv/cli_plugin/SamAlignmentEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,7 @@ public Map<String, Object> encodeAll(OutputStream stream, Iterator<? extends Sam
return null;
}

private String encode(Alignment feature) {
if (feature instanceof SamAlignment) {
SamAlignment alignment = (SamAlignment) feature;
String out = "";
//TODO This is a hack, but in theory should work.
// if(!headerWritten){
// out = alignment.getRecord().getHeader().getTextHeader() + "\n";
// headerWritten = true;
// }
out += alignment.getRecord().getSAMString();
return out;
}
return SAMWriter.getSAMString(feature);
}


@Override
public void setInputs(List<String> commands, Map<Argument, Object> argumentMap, Argument argument) {
Expand Down
10 changes: 5 additions & 5 deletions src/org/broad/igv/feature/FeatureFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ void increment() {
}


public static void main(String [] args) throws IOException {
createCanonicalGeneFile("/Users/jrobinso/projects/igv-js/igv/assets/hg19/gencode.v19.refGene", "/Users/jrobinso/projects/igv-js/igv/assets/hg19/gencode.v19.collapsed.bed");
}

/**
* Create a "canonical" gene file from an annotation UCSC refseq type annotation file. The "canonical" file
* represents all the isoforms of a gene as a single feature containing the union of all exons from the
Expand Down Expand Up @@ -234,10 +238,6 @@ static void createTSSFile(String iFile, String outputFile) throws IOException {
}
}

public static void main(String [] args) throws IOException {
createTSSFile("/Users/jrobinso/igv/tmp/refGene.txt", "/Users/jrobinso/tss.refSeq.hg19.bed");
}


private static void mergeExons(BasicFeature gene, List<Exon> exons) {
Set<IExon> exonProxies = new HashSet<IExon>(gene.getExons());
Expand Down Expand Up @@ -320,4 +320,4 @@ static void splitEmblFileByType(String emblFile, String outputDirectory) throws
pw.close();
}
}
}
}
169 changes: 169 additions & 0 deletions src/org/broad/igv/ga4gh/Ga4gh.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
package org.broad.igv.ga4gh;

import com.google.gson.Gson;
import org.apache.commons.io.IOUtils;

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;

/**
* Created by jrobinso on 6/16/14.
* <p/>
* Class to full around with the Google Global Alliance API
* <p/>
* TEST CASE
* HG00096 (GBR low coverage)
* 1:70,231,000-70,232,000
* <p/>
* readset id: CJDmkYn8ChCcnc7i4KaWqmQ
*/
public class Ga4gh {


// readset id = CJDmkYn8ChCcnc7i4KaWqmQ


public static void main(String[] args) throws IOException {

//datasets();
//readset();
//readsetSearch();
reads();
}

public static void datasets() throws IOException {

String baseURL = "https://www.googleapis.com/genomics/v1beta/datasets/376902546192?key=AIzaSyC-dujgw4P1QvNd8i_c-I-S_P1uxVZzn0w";


// Create a URLConnection
java.net.URLConnection connection = new java.net.URL(baseURL).openConnection();

// Read the response
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
java.lang.StringBuffer sb = new java.lang.StringBuffer();
java.lang.String str = br.readLine();
while (str != null) {
sb.append(str);
str = br.readLine();
}
br.close();
java.lang.String responseString = sb.toString();

System.out.println(responseString);

}

public static void readset() throws IOException {

String baseURL = "https://www.googleapis.com/genomics/v1beta/readsets/CJDmkYn8ChCcnc7i4KaWqmQ?key=AIzaSyC-dujgw4P1QvNd8i_c-I-S_P1uxVZzn0w";


// Create a URLConnection
java.net.URLConnection connection = new java.net.URL(baseURL).openConnection();

// Read the response
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
java.lang.StringBuffer sb = new java.lang.StringBuffer();
java.lang.String str = br.readLine();
while (str != null) {
sb.append(str);
str = br.readLine();
}
br.close();
java.lang.String responseString = sb.toString();

System.out.println(responseString);

}


public static void reads() throws IOException {

URL baseURL = new URL("https://www.googleapis.com/genomics/v1beta/reads/search?key=AIzaSyC-dujgw4P1QvNd8i_c-I-S_P1uxVZzn0w");
String key = "AIzaSyC-dujgw4P1QvNd8i_c-I-S_P1uxVZzn0w";
String datasetId = "376902546192";

// JSON content to post
java.lang.String contentToPost = //"key=" + key + " " +
"{readsetIds: [\"CJDmkYn8ChCcnc7i4KaWqmQ\"], " +
"sequenceName: 1, " +
"sequenceStart: 70231000, " +
"sequenceEnd: 70232000}";
System.out.println(contentToPost);
byte[] bytes = contentToPost.getBytes();

// Create a URLConnection
HttpURLConnection connection = (HttpURLConnection) baseURL.openConnection();
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
//connection.setRequestProperty("Content-Length", "" + bytes.length);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Cache-Control", "no-cache");

// Post content
java.io.OutputStream stream = connection.getOutputStream();
stream.write(bytes);
stream.close();

// Read the response
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
java.lang.String str;
Gson gson = new Gson();
while ((str = br.readLine()) != null) {
// Object obj = gson.fromJson(str, HashMap.class);
System.out.println(str);
}
br.close();


}

public static void readsetSearch() throws IOException {

URL baseURL = new URL("https://www.googleapis.com/genomics/v1beta/readsets/search?key=AIzaSyC-dujgw4P1QvNd8i_c-I-S_P1uxVZzn0w");
String key = "AIzaSyC-dujgw4P1QvNd8i_c-I-S_P1uxVZzn0w";
String datasetId = "376902546192";

// JSON content to post
java.lang.String contentToPost = //"key=" + key + " " +
"{datasetIds: [" + datasetId + "]}";
System.out.println(contentToPost);
byte[] bytes = contentToPost.getBytes();

// Create a URLConnection
HttpURLConnection connection = (HttpURLConnection) baseURL.openConnection();
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
//connection.setRequestProperty("Content-Length", "" + bytes.length);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Cache-Control", "no-cache");

// Post content
java.io.OutputStream stream = connection.getOutputStream();
stream.write(bytes);
stream.close();

// Read the response
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
java.lang.String str;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
br.close();


}

}
7 changes: 2 additions & 5 deletions src/org/broad/igv/goby/GobyAlignment.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import org.broad.igv.data.CharArrayList;
import org.broad.igv.feature.LocusScore;
import org.broad.igv.feature.Strand;
import org.broad.igv.sam.Alignment;
import org.broad.igv.sam.AlignmentBlock;
import org.broad.igv.sam.ReadMate;
import org.broad.igv.sam.SamAlignment;
import org.broad.igv.sam.*;
import org.broad.igv.track.WindowFunction;

import java.awt.*;
Expand Down Expand Up @@ -226,7 +223,7 @@ public void buildBlocks(Alignments.AlignmentEntry alignmentEntry) {
if (spliceHeadAlignment.gapTypes == null) {
spliceHeadAlignment.gapTypes = new CharArrayList(10);
}
spliceHeadAlignment.gapTypes.add(SamAlignment.SKIPPED_REGION);
spliceHeadAlignment.gapTypes.add(AbstractAlignment.SKIPPED_REGION);

// Since the previous alignment carries this information, we clear up block and insertionBlock
// in this alignment, but keep any softClips:
Expand Down
Loading

0 comments on commit 8ff0419

Please sign in to comment.