changeset 50:3e5b6f6a9abe draft

planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit 6391cdb975d14b5a7060fa1665a8a575797a0eaa-dirty
author yating-l
date Thu, 30 Mar 2017 16:03:16 -0400
parents 193e94a43f0f
children acedf82ea46c
files TrackHub.py jbrowse_hub.py jbrowse_hub.xml trackObject.py utils.py
diffstat 5 files changed, 75 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/TrackHub.py	Wed Mar 29 14:46:23 2017 -0400
+++ b/TrackHub.py	Thu Mar 30 16:03:16 2017 -0400
@@ -3,6 +3,7 @@
 import os
 import subprocess
 import shutil
+import json
 import utils
 
 
@@ -38,9 +39,7 @@
     def prepareRefseq(self):
         try:
             #print os.path.join(self.tool_dir, 'prepare-refseqs.pl') + ", '--fasta', " + self.reference +", '--out', self.json])"
-            p = subprocess.Popen(['prepare-refseqs.pl', '--fasta', self.reference, '--out', self.json])
-            # Wait for process to terminate.
-            p.communicate()
+            subprocess.call(['prepare-refseqs.pl', '--fasta', self.reference, '--out', self.json])
         except OSError as e:
             print "Cannot prepare reference error({0}): {1}".format(e.errno, e.strerror)
     #TODO: hard coded the bam and bigwig tracks. Need to allow users to customize the settings
@@ -57,18 +56,18 @@
         elif track['dataType'] == 'bigwig':
             self.BigWig(track, metadata)
         else: 
-            gff3_file = os.path.join(self.raw, track['fileName'])
-            if track['dataType'] == 'bedSpliceJunctions' or track['dataType'] == 'gtf' or track['dataType'] == 'blastxml':
-                p = subprocess.Popen(['flatfile-to-json.pl', '--gff', gff3_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"glyph": "JBrowse/View/FeatureGlyph/Segments", "category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
+            flat_file = os.path.join(self.raw, track['fileName'])
+            if track['dataType'] == 'bed':
+                subprocess.call(['flatfile-to-json.pl', '--bed', flat_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
+            elif track['dataType'] == 'bedSpliceJunctions' or track['dataType'] == 'gtf' or track['dataType'] == 'blastxml':
+                subprocess.call(['flatfile-to-json.pl', '--gff', flat_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"glyph": "JBrowse/View/FeatureGlyph/Segments", "category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
             elif track['dataType'] == 'gff3_transcript':
-                p = subprocess.Popen(['flatfile-to-json.pl', '--gff', gff3_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"transcriptType": "transcript", "category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
+                subprocess.call(['flatfile-to-json.pl', '--gff', flat_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"transcriptType": "transcript", "category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
             else:
-                p = subprocess.Popen(['flatfile-to-json.pl', '--gff', gff3_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
-            p.communicate()
+                subprocess.call(['flatfile-to-json.pl', '--gff', flat_file, '--trackType', metadata['type'], '--trackLabel', metadata['label'], '--Config', '{"category" : "%s"}' % metadata['category'], '--clientConfig', '{"color" : "%s"}' % metadata['color'], '--out', self.json])
             
     def indexName(self):
-        p = subprocess.Popen(['generate-names.pl', '-v', '--out', self.json])
-        p.communicate()
+        subprocess.call(['generate-names.pl', '-v', '--out', self.json])
         print "finished name index \n"
 
     def makeArchive(self):
@@ -83,8 +82,7 @@
         except OSError as oserror:
             print "Cannot create data folder({0}): {1}".format(oserror.errno, oserror.strerror)
         shutil.copytree(self.out_path, data_folder)
-        p = subprocess.Popen(['chmod', '-R', 'o+rx', '/var/www/html/JBrowse-1.12.1/jbrowse_hub'])
-        p.communicate()
+        subprocess.call(['chmod', '-R', 'o+rx', '/var/www/html/JBrowse-1.12.1/jbrowse_hub'])
         shutil.rmtree(self.out_path)
     
     #TODO: this will list all zip files in the filedir and sub-dirs. worked in Galaxy but all list zip files in test-data when
@@ -93,7 +91,7 @@
         with open(self.outfile, 'w') as htmlfile:
             htmlstr = 'The JBrowse Hub is created: <br>'
             zipfiles = '<li><a href = "%s">Download</a></li>'
-            jbrowse_hub = '<li><a href = "http://192.168.56.11/JBrowse-1.12.1/index.html?data=jbrowse_hub/json" target="_blank">View JBrowse Hub</a></li>'
+            jbrowse_hub = '<li><a href = "/static/JBrowse-1.12.1/index.html?data=jbrowse_hub/json" target="_blank">View JBrowse Hub</a></li>'
             filedir_abs = os.path.abspath(self.outfile)
             filedir = os.path.dirname(filedir_abs)
             filedir = os.path.join(filedir, self.outfolder)
@@ -122,8 +120,11 @@
         bam_track['baiUrlTemplate'] = os.path.join('../raw', track['index'])
         bam_track['label'] = metadata['label']
         bam_track['category'] = metadata['category']
-        utils.add_tracks_to_json(json_file, bam_track, 'add_tracks')
-
+        bam_track = json.dumps(bam_track)
+        #Use add-track-json.pl to add bam track to json file
+        new_track = subprocess.Popen(['echo', bam_track], stdout=subprocess.PIPE)
+        subprocess.call(['add-track-json.pl', json_file], stdin=new_track.stdout)
+    
     def BigWig(self, track, metadata):
         #create trackList.json if not exist
         self.createTrackList()
@@ -135,7 +136,11 @@
         bigwig_track['label'] = metadata['label']
         bigwig_track['style'] = metadata['style']
         bigwig_track['category'] = metadata['category']
-        utils.add_tracks_to_json(json_file, bigwig_track, 'add_tracks')
+        bigwig_track = json.dumps(bigwig_track)
+        #Use add-track-json.pl to add bigwig track to json file
+        new_track = subprocess.Popen(['echo', bigwig_track], stdout=subprocess.PIPE)
+        #output = new_track.communicate()[0]
+        subprocess.call(['add-track-json.pl', json_file], stdin=new_track.stdout)
 
     #If the metadata is not set, use the default value
     def SetMetadata(self, track, metadata):
@@ -147,9 +152,9 @@
             if 'style' not in metadata.keys():
                 metadata['style'] = {}
             if 'pos_color' not in metadata['style'] or metadata['style']['pos_color'] == '':
-                metadata['pos_color'] = "#FFA600"
+                metadata['style']['pos_color'] = "#FFA600"
             if 'neg_color' not in metadata['style'] or metadata['style']['neg_color'] == '':
-                metadata['neg_color'] = "#005EFF"
+                metadata['style']['neg_color'] = "#005EFF"
         if 'category' not in metadata.keys() or metadata['category'] == '':
             metadata['category'] = "Default group"
         if track['dataType'] == 'blastxml':
--- a/jbrowse_hub.py	Wed Mar 29 14:46:23 2017 -0400
+++ b/jbrowse_hub.py	Thu Mar 30 16:03:16 2017 -0400
@@ -27,11 +27,17 @@
     #Tool Directory
     parser.add_argument('-d', '--tool_directory', help='The directory of JBrowse file convertion scripts and UCSC tools')
 
+    #GFF3
+    parser.add_argument('--gff3', action='append', help='GFF3 format')
+
     # GFF3 structure: gene->transcription->CDS
-    parser.add_argument('--gff3_transcript', action='append', help='GFF3 format, structure: gene->transcription->CDS')
+    parser.add_argument('--gff3_transcript', action='append', help='GFF3 format for gene prediction, structure: gene->transcription->CDS')
 
     # GFF3 structure: gene->mRNA->CDS
-    parser.add_argument('--gff3_mrna', action='append', help='GFF3 format, structure: gene->mRNA->CDS')
+    parser.add_argument('--gff3_mrna', action='append', help='GFF3 format for gene prediction, structure: gene->mRNA->CDS')
+
+    # generic BED 
+    parser.add_argument('--bed', action='append', help='BED format')
 
     # trfBig simple repeats (BED 4+12)
     parser.add_argument('--bedSimpleRepeats', action='append', help='BED 4+12 format, using simpleRepeats.as')
@@ -93,9 +99,11 @@
     all_tracks = trackObject.trackObject(chrom_size.name, genome, extra_files_path) 
     
     array_inputs_bam = args.bam
+    array_inputs_bed = args.bed
     array_inputs_bed_simple_repeats = args.bedSimpleRepeats
     array_inputs_bed_splice_junctions = args.bedSpliceJunctions
     array_inputs_bigwig = args.bigwig
+    array_inputs_gff3 = args.gff3
     array_inputs_gff3_transcript = args.gff3_transcript
     array_inputs_gff3_mrna = args.gff3_mrna
     array_inputs_gtf = args.gtf
@@ -103,12 +111,16 @@
 
     if array_inputs_bam:
         all_datatype_dictionary['bam'] = array_inputs_bam
+    if array_inputs_bed:
+        all_datatype_dictionary['bed'] = array_inputs_bed
     if array_inputs_bed_simple_repeats:
         all_datatype_dictionary['bedSimpleRepeats'] = array_inputs_bed_simple_repeats
     if array_inputs_bed_splice_junctions:
         all_datatype_dictionary['bedSpliceJunctions'] = array_inputs_bed_splice_junctions
     if array_inputs_bigwig:
         all_datatype_dictionary['bigwig'] = array_inputs_bigwig
+    if array_inputs_gff3:
+        all_datatype_dictionary['gff3'] = array_inputs_gff3
     if array_inputs_gff3_transcript:
         all_datatype_dictionary['gff3_transcript'] = array_inputs_gff3_transcript
     if array_inputs_gff3_mrna:
--- a/jbrowse_hub.xml	Wed Mar 29 14:46:23 2017 -0400
+++ b/jbrowse_hub.xml	Thu Mar 30 16:03:16 2017 -0400
@@ -42,8 +42,11 @@
             #set extra_data_dict = {"label" : $track_label, "category" : $group_name} 
             #if $f.formatChoice.format_select == 'bed'
                 #set track_color = str($f.formatChoice.track_color)
+                #if $f.formatChoice.bedChoice.bed_select == 'bed_generic_option'
+                    --bed $f.formatChoice.bedChoice.BED_generic
+                    #silent $prepare_json($f.formatChoice.bedChoice.BED_generic, extra_data_dict)
                 #silent extra_data_dict.update({"color" : $track_color})
-                #if $f.formatChoice.bedChoice.bed_select == 'bed_simple_repeats_option'
+                #elif $f.formatChoice.bedChoice.bed_select == 'bed_simple_repeats_option'
                     --bedSimpleRepeats $f.formatChoice.bedChoice.BED_simple_repeats
                     #silent $prepare_json($f.formatChoice.bedChoice.BED_simple_repeats, extra_data_dict)
                 #elif $f.formatChoice.bedChoice.bed_select == 'bed_splice_junctions_option'
@@ -58,7 +61,10 @@
             #if $f.formatChoice.format_select == 'gff3'
                 #set track_color = str($f.formatChoice.track_color)
                 #silent extra_data_dict.update({"color" : $track_color})
-                #if $f.formatChoice.gff3Choice.gff3_select == 'gff3_transcript'
+                #if $f.formatChoice.gff3Choice.gff3_select == 'gff3_generic'
+                    --gff3 $f.formatChoice.gff3Choice.GFF3_generic
+                    #silent $prepare_json($f.formatChoice.gff3Choice.GFF3_generic, extra_data_dict)
+                #esif $f.formatChoice.gff3Choice.gff3_select == 'gff3_transcript'
                     --gff3_transcript $f.formatChoice.gff3Choice.GFF3_transcript
                     #silent $prepare_json($f.formatChoice.gff3Choice.GFF3_transcript, extra_data_dict)
                 #elif $f.formatChoice.gff3Choice.gff3_select == 'gff3_mrna'
@@ -121,9 +127,18 @@
                     <when value="bed">
                         <conditional name="bedChoice">
                             <param name="bed_select" type="select" label="Bed Choice">
+                                <option value="bed_generic_option">BED format</option>
                                 <option value="bed_simple_repeats_option">BED Simple repeat (bed4+12 / simpleRepeat.as)</option>
                                 <option value="bed_splice_junctions_option">BED Splice junctions (bed12+1 / spliceJunctions.as)</option>
                             </param>
+                            <when value="bed_generic_option">
+                                <param
+                                        format="bed"
+                                        name="BED_generic"
+                                        type="data"
+                                        label="Bed File"
+                                />
+                            </when>
                             <when value="bed_simple_repeats_option">
                                 <param
                                         format="bed"
@@ -185,15 +200,24 @@
                     <when value="gff3">
                         <conditional name="gff3Choice">
                             <param name="gff3_select" type="select" label="gff3 type">
-                                <option value="gff3_transcript">GFF3 format, structure: gene->transcription->CDS</option>
-                                <option value="gff3_mrna">GFF3 format, structure: gene->mRNA->CDS</option>
+                                <option value="gff3_generic">GFF3 format</option>
+                                <option value="gff3_transcript">GFF3 format output from gene prediction tools (e.g. Augustus), structure: gene->transcription->CDS</option>
+                                <option value="gff3_mrna">GFF3 format output from gene prediction tools (e.g. SNAP), structure: gene->mRNA->CDS</option>
                             </param>
+                            <when value="gff3_generic">
+                                <param
+                                        format="gff3"
+                                        name="GFF3_generic"
+                                        type="data"
+                                        label="GFF3 File"
+                                />
+                            </when>
                             <when value="gff3_transcript">
                                 <param
                                         format="gff3"
                                         name="GFF3_transcript"
                                         type="data"
-                                        label="GFF3 File"
+                                        label="GFF3 File from gene prediction"
                                 />
                             </when>
                             <when value="gff3_mrna">
@@ -201,7 +225,7 @@
                                         format="gff3"
                                         name="GFF3_mrna"
                                         type="data"
-                                        label="GFF3 File"
+                                        label="GFF3 File from gene prediction"
                                 />
                             </when>
                         </conditional>
--- a/trackObject.py	Wed Mar 29 14:46:23 2017 -0400
+++ b/trackObject.py	Thu Mar 30 16:03:16 2017 -0400
@@ -33,10 +33,12 @@
         fileName = os.path.basename(dataFile)
         des_path = os.path.join(self.raw_folder, fileName)
         track = {}
-        if dataType == 'gff3_mrna' or dataType == 'gff3_transcript' or dataType == 'fasta' or dataType == 'bam' or dataType == 'bigwig' or dataType == 'bai':
+        if dataType == 'bed' or dataType == 'gff3' or dataType == 'gff3_mrna' or dataType == 'gff3_transcript' or dataType == 'fasta' or dataType == 'bam' or dataType == 'bigwig':
             if dataType == 'bam':
                 # JBrowse will raise error: not a BAM file if the filename hasn't .bam extension
-                fileName = fileName + '.bam'
+                extension = os.path.splitext(fileName)[1]
+                if extension != '.bam':
+                    fileName = fileName + '.bam'
                 des_path = os.path.join(self.raw_folder, fileName)
                 bam_index = utils.createBamIndex(dataFile)
                 indexname = os.path.basename(bam_index)
--- a/utils.py	Wed Mar 29 14:46:23 2017 -0400
+++ b/utils.py	Thu Mar 30 16:03:16 2017 -0400
@@ -35,13 +35,11 @@
     except IOError as err:
         print "Cannot create tempfile err({0}): {1}".format(err.errno, err.strerror)
     try:
-        p = subprocess.Popen(['faToTwoBit', reference, twoBitFile.name])
-        p.communicate()
+        subprocess.call(['faToTwoBit', reference, twoBitFile.name])
     except OSError as err:
         print "Cannot generate twoBitFile from faToTwoBit err({0}): {1}".format(err.errno, err.strerror)
     try:
-        p = subprocess.Popen(['twoBitInfo', twoBitFile.name, chrom_sizes.name])
-        p.communicate()
+        subprocess.call(['twoBitInfo', twoBitFile.name, chrom_sizes.name])
     except OSError as err:
         print "Cannot generate chrom_sizes from twoBitInfo err({0}): {1}".format(err.errno, err.strerror)
     return chrom_sizes
@@ -155,8 +153,7 @@
     return "gonramp_" + sanitized_name
 
 def createBamIndex(bamfile):
-    p = subprocess.Popen(['samtools', 'index', bamfile])
-    p.communicate()
+    subprocess.call(['samtools', 'index', bamfile])
     filename = bamfile + '.bai'
     if os.path.exists(filename):
         return filename