|
There are several ways to download data from the ProteomeCommons.org Tranche network: through the Java GUI as described in the user's guide, through the command-line tool, or through the Java API.
The Java GUI is layered on top of a set of scriptable command-line tools. Here is a link to a ZIP file that contains exactly what you need to use the command-line tool that downloads data. It is assumed that you have a current version of Java installed on your computer. Unzip the ZIP file and you are set. The command to run this tool is the following.
The tool will automatically give you a list of options that you can use, including specific server(s) to download from, if digital signatures should be checked, where to save data to, and how to specify the hash of the file(s) to download. Alternatively, you can add the hash you want to download to the end of the line and the tool will get that file. For example:
Replace the {Tranche hash} in the above example with the Tranche hash you want to download. Once the download starts you will get a listing of the download's progress. Note, if you don't specify any servers the tool will automatically attempt to find the servers that contain the data. The tool will also skip the downloading of any file that is already present, i.e. you can easily resume downloads or check that you have all the files by simply starting the download again.
For the following options, you are required to place them before the Tranche hash, as shown in the following example:
Any combination of options may be used in a command.
-cert optionAfter setting the -cert option, specify the file location of a X.509 Certificate to use as a trusted authority. A project or file will only be downloaded if the project, or file, has been signed by the trusted authority.
Multiple '-cert' commands may be used. Only content signed by one of the given certificates will be downloaded.
java -jar Tranche-Downloader.jar -cert {file location 1} -cert {file location 2} {Tranche hash}
-file optionAfter setting the -file option, specify the file or directory that the Tranche code should save the data to, as shown here:
-regex optionAfter setting the -regex option, specify a regular expression that will limit the files that are downloaded. Only files with names that match the regular expression will be downloaded. A great use for this is to download only files of a certain extension. The following is an example of how to use the option:
To use the regular expression to download only ".pkl" files, use the following:
Notice that the period character was preceded with a backslash. If you would like to download more than one type of file, like either ".pkl" or ".t2d" files, use the "|" character betewen the two:
There are many regular expression tutorials available online. We recommend using O'Reilly's Regular Expression Pocket Reference.
-server optionAfter setting the -server option, specify a server to download from, as shown in the following example. If the file you are trying to download is not found on that server, the download will fail.
For indicating multiple servers to download from, you can simply add-server {server} more times, as shown here:
If the file you are trying to download is not found on any of the given servers you specified, the download will fail.
-tempDir optionAfter setting the -tempDir option, specify the temporary directory to use while downloading the data. When the download is complete, the data will be moved to its final destination.
-validate optionAfter setting the -validate option, specify a boolean value that denotes whether or not the data should be validated once downloaded. If the Boolean value is true, then the GetFileTool will check whether the data that was downloaded matches the Tranche hash. Note that the Tranche hash was created using the data that was uploaded. With validation, you can ensure that the data you have downloaded matches the data that was originally uploaded.
You will need the GetFileTool command-line client and the shell script to perform the tasks in this brief section. Unzip the command-line tool in the same directory as the script.
You may wish to download a list of projects. This is particularly convenient if you have a list of projects you wish to download; using the shell script, each project will download sequentially.
There are two ways to use the tool. If you wish to simply provide the hashes as arguments, you can execute the shell script along with the hashes:
However, since the hashes are long, this method will cause problems if the list of arguments are not passed due to their length; your shell may restrict the total size of your arguments. It may be more convenient to place the hashes in a text file, one per line. Say we have a text file called hashes.txt (the name is arbitrary; you can call it anything). You can simply pipe the contents to the shell script, which will download the projects in order:
However, if you use the second method, you must place each hash on a separate line. (As opposed to first method, where the hashes are used as arguments to the script and are separated by spaces.)
Note: remember to make sure the script is executable. If you get a 'permission denied' error while executing:
Remember that Tranche is completely open-source. You are welcome to use, for free, any of the source code in the Tranche project. The following will show you how to set up and use the Java API. Also provided is an overview of the DownloadProject code snippet, provided in the code snippets documentation.
To start using the Tranche Java API, you will first need to download the Tranche source code. Clean and Build the project. For further information on how to set up your Tranche source code, you can consult the beginning developer's tutorial.
Next, use Netbeans to link to the project by opening the project's properties and selecting Libraries, as shown here:
Click the Add Project... button on the right side of the window and locate the folder your Tranche source code is in and select it. Click the Add Project JAR Files button, as shown here:
You now have full access to the Tranche Java API. Read the next section, an overview of using the DownloadProject code snippet, to get an idea of how to use the Java API. For more information on how to use the API, consult the JavaDocs.
We have written some of the most commonly requested code snippets, one of which downloads a project. You are free to use and modify these code snippets for your needs. The following is a walk-through of the DownloadProject code.
Open DownloadProject.java to see the full code that will be reviewed here.
The package the code is contained in may be changed. You are not required to keep this.
You are required to import the classes that are to be used in the code. Keep these lines.
The code snippet is runnable because it contains a main method. Keep this to allow the snippet to be runnable.
This line of code creates a BigHash object out of the string within the createHashFromString method. Replace this string with any Tranche hash you want to download. Of course it is not required that you explicitly name the Tranche hash -- you could replace the given Tranche hash with a String object.
Keep this line as it is. The GetFileTool object is the workhorse for downloading from the Tranche network.
It is required to tell the GetFileTool object the hash of the project you want to download, so keep this line.
You may, or may not, want to include the setValidate method with the value of either true or false. If the Boolean value is true, then the GetFileTool will check whether the data downloaded matches the Tranche hash. Note, the Tranche hash was created using the data uploaded. With validation, you can ensure the data you have downloaded matches the data originally uploaded.
A File object is used to represent the directory to be downloaded to. In this case, we are going to download the project into a folder named "download" in the same directory as the script. If the directory does not exist, the dir.mkdirs(); line will create the directory.
This line will set the local System.out as the standard output of status information. It is not required to keep this line of code.
Executes the download. The Tranche hash used in this example was for a fairly large project, or a set or files, which is why the getDirectory method is used.