# HG changeset patch # User rmarenco # Date 1456879405 18000 # Node ID 163b2de763ea5fefbc30d8b37eb2ad1c0e3e376e Upload the full hubArchiveCreator archive diff -r 000000000000 -r 163b2de763ea hub-archive-creator-1.6/.gitignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hub-archive-creator-1.6/.gitignore Tue Mar 01 19:43:25 2016 -0500 @@ -0,0 +1,3 @@ +*.pyc +.DS_Store +.idea/ diff -r 000000000000 -r 163b2de763ea hub-archive-creator-1.6/README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hub-archive-creator-1.6/README.md Tue Mar 01 19:43:25 2016 -0500 @@ -0,0 +1,18 @@ +# Hub Archive Creator +This Galaxy tool permits to prepare your files to be ready for Assembly Hub visualization. + +To try the software, you need to have a .gff3 and a .fa as input and set an output filename: +```hubArchiveCreator.py -g test_data/augustusDbia3.gff3 -f test_data/dbia3.fa -o output.zip``` + +You will get a .zip file, that you need to put on a server accessible from the outside. Then use UCSC track hubs fonctionality to see your track. + +## Requirements: +1. You need to install [Mako](http://www.makotemplates.org/download.html) +2. HubArchiveCreator use, for now, tools from UCSC Kent Utils. This repository use the linux.x86_64/ ones, but you NEED to replace them accordingly to your architecture. +Here is the link to get these tools: http://hgdownload.soe.ucsc.edu/admin/exe/ + +### Install in Galaxy +1. Take the hubAssembly.py in the hubaDatatype folder, and add it into lib/galaxy/datatypes in your Galaxy instance +2. Add this line in config/datatypes_conf.xml: +`````` +3. Look into hubaDatatype/README.md for more informations diff -r 000000000000 -r 163b2de763ea hub-archive-creator-1.6/__init__.py diff -r 000000000000 -r 163b2de763ea hub-archive-creator-1.6/hubArchiveCreator.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hub-archive-creator-1.6/hubArchiveCreator.py Tue Mar 01 19:43:25 2016 -0500 @@ -0,0 +1,340 @@ +#!/usr/bin/python +""" +This Galaxy tool permits to prepare your files to be ready for +Assembly Hub visualization. +Program test arguments: +hubArchiveCreator.py -g test_data/augustusDbia3.gff3 -f test_data/dbia3.fa -d . -o output.zip +""" + +import sys +import tempfile +import getopt +import zipfile +import subprocess +import os +import argparse + +from mako.template import Template +from mako.lookup import TemplateLookup + +# Internal dependencies +from twoBitCreator import twoBitFileCreator + +# TODO: REMOVE THIS FROM BEING A GLOBAL VARIABLE +toolDirectory = '.' +extra_files_path = '.' + +def main(argv): + # Command Line parsing init + parser = argparse.ArgumentParser(description='Create a foo.txt inside the given folder.') + + parser.add_argument('-g', '--gff3', help='Directory where to put the foo.txt') + parser.add_argument('-f', '--fasta', help='Directory where to put the foo.txt') + parser.add_argument('-d', '--directory', help='Directory where to put the foo.txt') + parser.add_argument('-e', '--extra_files_path', help='Directory where to put the foo.txt') + parser.add_argument('-o', '--output', help='Directory where to put the foo.txt') + + + global toolDirectory + global extra_files_path + inputGFF3File = '' + inputFastaFile = '' + + # Get the args passed in parameter + args = parser.parse_args() + + inputGFF3File = open(args.gff3, 'r') + inputFastaFile = open(args.fasta, 'r') + + if args.directory: + toolDirectory = args.directory + if args.extra_files_path: + extra_files_path = args.extra_files_path + + outputZip = zipfile.ZipFile(os.path.join(extra_files_path, 'myHub.zip'), 'w') + + + # Create the structure of the Assembly Hub + # TODO: Merge the following processing into a function as it is also used in twoBitCreator + baseNameFasta = os.path.basename(inputFastaFile.name) + suffixTwoBit, extensionTwoBit = os.path.splitext(baseNameFasta) + nameTwoBit = suffixTwoBit + '.2bit' + + rootAssemblyHub = createAssemblyHub(outputZip, twoBitName=nameTwoBit) + + # TODO: See if we need these temporary files as part of the generated files + genePredFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".genePred") + unsortedBedFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".unsortedBed") + sortedBedFile = tempfile.NamedTemporaryFile(suffix=".sortedBed") + twoBitInfoFile = tempfile.NamedTemporaryFile(bufsize=0) + chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".chrom.sizes") + + # gff3ToGenePred processing + p = subprocess.Popen( + [os.path.join(toolDirectory, 'tools/gff3ToGenePred'), + inputGFF3File.name, + genePredFile.name]) + # We need to wait the time gff3ToGenePred terminate so genePredToBed can begin + # TODO: Check if we should use communicate instead of wait + p.wait() + + # genePredToBed processing + p = subprocess.Popen( + [os.path.join(toolDirectory, 'tools/genePredToBed'), + genePredFile.name, + unsortedBedFile.name]) + p.wait() + + # Sort processing + p = subprocess.Popen( + ['sort', + '-k' + '1,1', + '-k' + '2,2n', + unsortedBedFile.name, + '-o', + sortedBedFile.name]) + p.wait() + + mySpecieFolderPath = os.path.join(extra_files_path, "myHub", "dbia3") + + # 2bit file creation from input fasta + twoBitFile = twoBitFileCreator(inputFastaFile, toolDirectory, mySpecieFolderPath) + + # Generate the chrom.sizes + # TODO: Isolate in a function + # We first get the twoBit Infos + p = subprocess.Popen( + [os.path.join(toolDirectory, 'tools/twoBitInfo'), + twoBitFile.name, + 'stdout'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + twoBitInfo_out, twoBitInfo_err = p.communicate() + twoBitInfoFile.write(twoBitInfo_out) + + # Then we get the output to inject into the sort + # TODO: Check if no errors + p = subprocess.Popen( + ['sort', + '-k2rn', + twoBitInfoFile.name, + '-o', + chromSizesFile.name]) + p.wait() + + # bedToBigBed processing + # bedToBigBed augustusDbia3.sortbed chrom.sizes augustusDbia3.bb + # TODO: Find the best to get this path without hardcoding it + myTrackFolderPath = os.path.join(mySpecieFolderPath, "tracks") + # TODO: Change the name of the bb, to tool + genome + .bb + myBigBedFilePath = os.path.join(myTrackFolderPath, 'augustusDbia3.bb') + with open(myBigBedFilePath, 'w') as bigBedFile: + p = subprocess.Popen( + [os.path.join(toolDirectory, 'tools/bedToBigBed'), + sortedBedFile.name, + chromSizesFile.name, + bigBedFile.name]) + p.wait() + + # TODO: Add the .bb file in the zip, at the right place + + createZip(outputZip, rootAssemblyHub) + + # outputZip.write(sortedBedFile.name) + # TODO: Find the best to get this path without hardcoding it + + # outputZip.write(bigBedFile.name) + outputZip.close() + + # Just a test to output a simple HTML + with open(args.output, 'w') as htmlOutput: + htmlOutput.write('') + htmlOutput.write('') + htmlOutput.write('

') + htmlOutput.write('The following generated by Hub Archive Creator:') + htmlOutput.write('

') + htmlOutput.write('