Mercurial > repos > yating-l > jbrowse_hub
comparison jbrowse_hub.py @ 5:e7c80e9b70ae draft
planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f18ea51d27ec7addfa6413716391cfefebc8acbc-dirty
| author | yating-l |
|---|---|
| date | Tue, 14 Mar 2017 12:24:37 -0400 |
| parents | e4f3f2ed4fa5 |
| children | e1f188b43750 |
comparison
equal
deleted
inserted
replaced
| 4:c7c1474a6b7d | 5:e7c80e9b70ae |
|---|---|
| 8 import blastxmlToGff3 | 8 import blastxmlToGff3 |
| 9 import utils | 9 import utils |
| 10 import tempfile | 10 import tempfile |
| 11 import trackObject | 11 import trackObject |
| 12 import TrackHub | 12 import TrackHub |
| 13 import shutil | |
| 13 | 14 |
| 14 def main(argv): | 15 def main(argv): |
| 15 parser = argparse.ArgumentParser(description='Create a hub to display in jbrowse.') | 16 parser = argparse.ArgumentParser(description='Create a hub to display in jbrowse.') |
| 16 | 17 |
| 17 # Reference genome mandatory | 18 # Reference genome mandatory |
| 18 parser.add_argument('-f', '--fasta', help='Fasta file of the reference genome') | 19 parser.add_argument('-f', '--fasta', help='Fasta file of the reference genome') |
| 19 | 20 |
| 21 # Genome name | |
| 22 parser.add_argument('-g', '--genome_name', help='Name of reference genome') | |
| 23 | |
| 20 # Output folder | 24 # Output folder |
| 21 parser.add_argument('-o', '--out', help='Name of the HTML summarizing the content of the JBrowse Hub') | 25 parser.add_argument('-o', '--out', help='output html') |
| 26 | |
| 27 # Output folder | |
| 28 parser.add_argument('-e', '--extra_files_path', help="Directory of JBrowse Hub folder") | |
| 22 | 29 |
| 23 # GFF3 | 30 # GFF3 |
| 24 parser.add_argument('--gff3', action='append', help='GFF3 format') | 31 parser.add_argument('--gff3', action='append', help='GFF3 format') |
| 25 | 32 |
| 26 # trfBig simple repeats (BED 4+12) | 33 # trfBig simple repeats (BED 4+12) |
| 43 # GTF format | 50 # GTF format |
| 44 parser.add_argument('--gtf', action='append', help='GTF format from StringTie') | 51 parser.add_argument('--gtf', action='append', help='GTF format from StringTie') |
| 45 | 52 |
| 46 args = parser.parse_args() | 53 args = parser.parse_args() |
| 47 all_datatype_dictionary = dict() | 54 all_datatype_dictionary = dict() |
| 48 all_tracks = [] | 55 |
| 49 | 56 |
| 50 reference = args.fasta | 57 reference = args.fasta |
| 51 out_path = args.out | 58 genome = 'unknown' |
| 52 tool_directory = 'JBrowse-1.12.1/bin' | 59 out_path = '.' |
| 53 chrom_size = utils.getChromSizes(reference, '../ucsc_tools_340_for_HAC') | 60 extra_files_path = '.' |
| 61 if args.genome_name: | |
| 62 genome = utils.sanitize_name_path(args.genome_name) | |
| 63 if args.out: | |
| 64 out_path = args.out | |
| 65 if args.extra_files_path: | |
| 66 extra_files_path = utils.sanitize_name_path(args.extra_files_path) | |
| 67 cwd = os.getcwd() | |
| 68 #tool_directory not work for Galaxy tool, all tools need to exist in the current PATH, deal with it with tool dependencies | |
| 69 tool_directory = os.path.join(cwd, 'JBrowse-1.12.1/bin') | |
| 70 chrom_size = utils.getChromSizes(reference, tool_directory) | |
| 71 all_tracks = trackObject.trackObject(chrom_size.name, genome, extra_files_path) #store converted files in the array: all_tracks.tracks | |
| 54 array_inputs_bam = args.bam | 72 array_inputs_bam = args.bam |
| 55 array_inputs_bed_simple_repeats = args.bedSimpleRepeats | 73 array_inputs_bed_simple_repeats = args.bedSimpleRepeats |
| 56 array_inputs_bed_splice_junctions = args.bedSpliceJunctions | 74 array_inputs_bed_splice_junctions = args.bedSpliceJunctions |
| 57 array_inputs_bigwig = args.bigwig | 75 array_inputs_bigwig = args.bigwig |
| 58 array_inputs_gff3 = args.gff3 | 76 array_inputs_gff3 = args.gff3 |
| 75 | 93 |
| 76 print all_datatype_dictionary | 94 print all_datatype_dictionary |
| 77 | 95 |
| 78 for datatype, inputfiles in all_datatype_dictionary.items(): | 96 for datatype, inputfiles in all_datatype_dictionary.items(): |
| 79 try: | 97 try: |
| 80 user_input = inputfiles | 98 if not inputfiles: |
| 81 if not user_input: | |
| 82 raise ValueError('empty input, must provide track files!\n') | 99 raise ValueError('empty input, must provide track files!\n') |
| 83 except IOError: | 100 except IOError: |
| 84 print 'Cannot open', datatype | 101 print 'Cannot open', datatype |
| 85 else: | 102 else: |
| 86 for f in inputfiles: | 103 for f in inputfiles: |
| 87 track = trackObject.trackObject(f, datatype, chrom_size.name) | 104 all_tracks.addToRaw(f, datatype) |
| 88 track.addToRaw() | |
| 89 all_tracks.append(track) | |
| 90 | 105 |
| 91 jbrowseHub = TrackHub.TrackHub(all_tracks, reference, out_path, tool_directory) | 106 jbrowseHub = TrackHub.TrackHub(all_tracks, reference, out_path, tool_directory, genome, extra_files_path) |
| 92 jbrowseHub.createHub() | 107 jbrowseHub.createHub() |
| 93 | 108 |
| 94 | 109 |
| 110 | |
| 95 ''' | 111 ''' |
| 96 if reference: | 112 if reference: |
| 97 p = subprocess.Popen(['JBrowse-1.12.1/bin/prepare-refseqs.pl', '--fasta', reference, '--out', out_path]) | 113 p = subprocess.Popen(['JBrowse-1.12.1/bin/prepare-refseqs.pl', '--fasta', reference, '--out', out_path]) |
| 98 # Wait for process to terminate. | 114 # Wait for process to terminate. |
| 99 p.communicate() | 115 p.communicate() |
