Repository 'retrieve_ensembl_bed'
hg clone https://toolshed.g2.bx.psu.edu/repos/galaxyp/retrieve_ensembl_bed

Changeset 1:9c4a48f5d4e7 (2019-10-07)
Previous changeset 0:da1b538b87e5 (2018-01-22)
Commit message:
"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/proteogenomics/retrieve_ensembl_bed commit 6babd357845126292cb202aaea0f70ff68819525"
modified:
retrieve_ensembl_bed.py
retrieve_ensembl_bed.xml
added:
test-data/test.bed
b
diff -r da1b538b87e5 -r 9c4a48f5d4e7 retrieve_ensembl_bed.py
--- a/retrieve_ensembl_bed.py Mon Jan 22 13:13:47 2018 -0500
+++ b/retrieve_ensembl_bed.py Mon Oct 07 16:14:39 2019 -0400
[
@@ -34,6 +34,12 @@
         help='Restrict Ensembl retrieval to regions e.g.:'
              + ' X,2:20000-25000,3:100-500+')
     parser.add_argument(
+        '-i', '--interval_file', default=None,
+        help='Regions from a bed, gff, or interval file')
+    parser.add_argument(
+        '-f', '--interval_format', choices=['bed','gff','interval'], default='interval',
+        help='Interval format has TAB-separated columns: Seq, Start, End, Strand')
+    parser.add_argument(
         '-B', '--biotypes', action='append', default=[],
         help='Restrict Ensembl biotypes to retrieve')
     parser.add_argument(
@@ -75,6 +81,27 @@
         if args.debug:
             print("selected_regions: %s" % selected_regions, file=sys.stderr)
 
+    if args.interval_file:
+        pat = r'^(?:chr)?([^\t]+)(?:\t(\d+)(?:\t(\d+)(?:\t([+-])?)?)?)?.*'
+        if args.interval_format == 'bed':
+            pat = r'^(?:chr)?([^\t]+)\t(\d+)\t(\d+)(?:(?:\t[^\t]+\t[^\t]+\t)([+-]))?.*'
+        elif args.interval_format == 'gff':
+            pat = r'^(?:chr)?([^\t]+)\t(\d+)\t(\d+)(?:(?:\t[^\t]+\t[^\t]+\t)([+-]))?.*'
+        with open(args.interval_file,'r') as fh:
+            for i, line in enumerate(fh):
+                if line.startswith('#'):
+                    continue
+                m = re.match(pat, line.rstrip())
+                if m:
+                    (chrom, start, end, strand) = m.groups()
+                    if chrom:
+                        if chrom not in selected_regions:
+                            selected_regions[chrom] = []
+                        selected_regions[chrom].append([start, end, strand])
+        if args.debug:
+            print("selected_regions: %s" % selected_regions, file=sys.stderr)
+               
+
     def retrieve_region(species, ref, start, stop, strand):
         transcript_count = 0
         regions = list(range(start, stop, max_region))
b
diff -r da1b538b87e5 -r 9c4a48f5d4e7 retrieve_ensembl_bed.xml
--- a/retrieve_ensembl_bed.xml Mon Jan 22 13:13:47 2018 -0500
+++ b/retrieve_ensembl_bed.xml Mon Oct 07 16:14:39 2019 -0400
[
@@ -20,6 +20,16 @@
             #if $regions:
                 --regions '$regions'
             #end if
+            #if $interval_file:
+                #if $interval_file.ext.find('bed') > -1
+                    --interval_format bed
+                #elif $interval_file.ext in ['gff','gtf','gff3']
+                    --interval_format gff
+                #else
+                    --interval_format interval
+                #end if
+                --interval_file '$interval_file' 
+            #end if
             '$transcript_bed'
     ]]></command>
     <inputs>
@@ -40,6 +50,7 @@
             <help>Each region is specifed as: chr or chr:pos or chr:from-to</help>
             <validator type="regex" message="">^(\w+(:\d+(-\d+)?)?(,\w+(:\d+(-\d+)?)?)*)?$</validator>
         </param>
+        <param name="interval_file" type="data" format="bed,gff,interval" label="Retrieve the intervals from this file" optional="true"/>
     </inputs>
     <outputs>
         <data name="transcript_bed" format="bed" label="Ensembl ${species} transcripts.bed">
@@ -60,6 +71,16 @@
                 </assert_contents>
             </output>
         </test>
+        <test>
+            <param name="species" value="mouse"/>
+            <param name="biotypes" value="protein_coding"/>
+            <param name="interval_file" ftype="bed" value="test.bed"/>
+            <output name="transcript_bed">
+                <assert_contents>
+                    <has_text_matching expression="(chr)?1\t\d+\t\d+\tENSMUST" />
+                </assert_contents>
+            </output>
+        </test>
     </tests>
     <help><![CDATA[
 Retrieve Ensembl cDNAs in BED format
@@ -69,25 +90,34 @@
                                output
 
 positional arguments:
-  output                Output BED filepath, or for stdout: "-"
+  output                   Output BED filepath, or for stdout: "-"
 
 optional arguments:
-  -h, --help            show this help message and exit
+  -h, --help               show this help message and exit
   -s SPECIES, --species SPECIES
-                        Ensembl Species to retrieve
+                           Ensembl Species to retrieve
   -R REGIONS, --regions REGIONS
-                        Restrict Ensembl retrieval to regions e.g.:
-                        X,2:20000-25000,3:100-500+
+                           Restrict Ensembl retrieval to regions e.g.
+                           X,2:20000-25000,3:100-500+
+  -i INTERVAL_FILE, --interval_file INTERVAL_FILE
+                           Regions from a bed, gff, or interval file
+
+  -f {bed,gff,interval},  --interval_format {bed,gff,interval}
+                           Interval format has TAB-separated
+                           columns: Seq, Start, End, Strand
+
   -B BIOTYPES, --biotypes BIOTYPES
-                        Restrict Ensembl biotypes to retrieve
-  -X, --extended_bed    Include the extended columns returned from Ensembl
+                           Restrict Ensembl biotypes to retrieve
+  -X, --extended_bed       Include the extended columns returned from Ensembl
   -U, --ucsc_chrom_names
-                        Use the UCSC names for Chromosomes
-  -t, --toplevel        Print Ensembl toplevel for species
-  -v, --verbose         Verbose
-  -d, --debug           Debug
+                           Use the UCSC names for Chromosomes
+  -t, --toplevel           Print Ensembl toplevel for species
+  -v, --verbose            Verbose
+  -d, --debug              Debug
 
 
+**Output**
+
 Ensembl REST API returns an extended BED format with these additional columns::
 
   second_name, cds_start_status, cds_end_status, exon_frames, type, gene_name, second_gene_name, gene_type
b
diff -r da1b538b87e5 -r 9c4a48f5d4e7 test-data/test.bed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/test.bed Mon Oct 07 16:14:39 2019 -0400
b
@@ -0,0 +1,3 @@
+X 8146492 8146528 region_0 0 +
+1 39575612 39575640 region_1 0 +
+2 131297127 131297157 region_2 0 +