How can I serve a directory of BAM files via http most easily?
1
1
Entering edit mode
9.5 years ago

This is bordering on off-topic, but I routinely want to quickly serve up a set of BAM files to users for viewing via IGV and the like via a simple http server. Both python and node (http-server) servers do not seem to correctly support range requests. Short of configuring and running something more heavyweight (nginx, apache, etc.), are there other simple command-line http servers that can support quickly and easily serving up a directory?

bam http • 2.1k views
ADD COMMENT
0
Entering edit mode

Any reason for not considering an FTP server? I often do range requests on 1000 genomes BAMs and it works quite well.

ADD REPLY
3
Entering edit mode
9.5 years ago

set-up a jetty server? see the gist below. you just have to change the path

holderPwd.setInitParameter("resourceBase", "/home/user/path/to/directory");

import org.eclipse.jetty.server.*;
import org.eclipse.jetty.servlet.*;
public class BamServer {
public static void main(String[] args) throws Exception {
Server jettyServer = new Server(8080);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
DefaultServlet servlet= new DefaultServlet();
ServletHolder holderPwd = new ServletHolder("default", servlet);
holderPwd.setInitParameter("resourceBase", "/home/user/path/to/directory");
context.addServlet(holderPwd, "/*");
jettyServer.setHandler(context);
try {
jettyServer.start();
jettyServer.join();
} finally {
jettyServer.destroy();
}
}
}
view raw BamServer.java hosted with ❤ by GitHub
$ curl -s -r 10-100 "http://localhost:8080/blastn.xml"
ion="1.0"?>
<!DOCTYPE BlastOutput PUBLIC "-//NCBI//NCBI BlastOutput/EN" "http://www.ncbi.nl
view raw example.txt hosted with ❤ by GitHub
lib.dir=lib
jetty.jars=$(lib.dir)/org/eclipse/jetty/jetty-servlet/9.3.6.v20151106/jetty-servlet-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-server/9.3.6.v20151106/jetty-server-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-io/9.3.6.v20151106/jetty-io-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-security/9.3.6.v20151106/jetty-security-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-util/9.3.6.v20151106/jetty-util-9.3.6.v20151106.jar:$(lib.dir)/org/eclipse/jetty/jetty-http/9.3.6.v20151106/jetty-http-9.3.6.v20151106.jar:$(lib.dir)/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar
all: $(subst :, ,${jetty.jars}) BamServer.java
javac -cp ${jetty.jars} BamServer.java
java -cp ${jetty.jars}:. BamServer
$(subst :, ,${jetty.jars}) :
mkdir -p $(dir $@) && wget -O "$@" "http://central.maven.org/maven2/$(patsubst ${lib.dir}/%,%,$@)"
view raw Makefile hosted with ❤ by GitHub

ADD COMMENT

Login before adding your answer.

Traffic: 2766 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6