Repository 'fasta_regex_finder'
hg clone https://toolshed.g2.bx.psu.edu/repos/mbernt/fasta_regex_finder

Changeset 1:9a811adb714f (2023-01-25)
Previous changeset 0:269c627ae9f4 (2018-06-20)
Commit message:
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/main/tools/bioinformatics-cafe commit c318cd3f894f89c13d7eb257678673da70f72212
modified:
fastaregexfinder.py
fastaregexfinder.xml
b
diff -r 269c627ae9f4 -r 9a811adb714f fastaregexfinder.py
--- a/fastaregexfinder.py Wed Jun 20 11:06:57 2018 -0400
+++ b/fastaregexfinder.py Wed Jan 25 14:03:52 2023 +0000
[
b'@@ -1,33 +1,33 @@\n #!/usr/bin/env python\n \n-import re\n-import sys\n-import string\n import argparse\n import operator\n+import re\n+import sys\n \n-VERSION=\'0.1.1\'\n+VERSION = "0.1.1"\n \n-parser = argparse.ArgumentParser(description="""\n+parser = argparse.ArgumentParser(\n+    description="""\n \n DESCRIPTION\n-    \n+\n     Search a fasta file for matches to a regex and return a bed file with the\n-    coordinates of the match and the matched sequence itself. \n-    \n+    coordinates of the match and the matched sequence itself.\n+\n     Output bed file has columns:\n     1. Name of fasta sequence (e.g. chromosome)\n     2. Start of the match\n     3. End of the match\n     4. ID of the match\n     5. Length of the match\n-    6. Strand \n+    6. Strand\n     7. Matched sequence as it appears on the forward strand\n-    \n+\n     For matches on the reverse strand it is reported the start and end position on the\n     forward strand and the matched string on the forward strand (so the G4 \'GGGAGGGT\'\n     present on the reverse strand is reported as ACCCTCCC).\n-    \n+\n     Note: Fasta sequences (chroms) are read in memory one at a time along with the\n     matches for that chromosome.\n     The order of the output is: chroms as they are found in the inut fasta, matches\n@@ -37,7 +37,7 @@\n     ## Test data:\n     echo \'>mychr\' > /tmp/mychr.fa\n     echo \'ACTGnACTGnACTGnTGAC\' >> /tmp/mychr.fa\n-    \n+\n     fastaRegexFinder.py -f /tmp/mychr.fa -r \'ACTG\'\n         mychr\t0\t4\tmychr_0_4_for\t4\t+\tACTG\n         mychr\t5\t9\tmychr_5_9_for\t4\t+\tACTG\n@@ -47,8 +47,8 @@\n         mychr\t0\t4\tmychr_0_4_for\t4\t+\tACT[3,4]\n         mychr\t5\t9\tmychr_5_9_for\t4\t+\tACT[3,4]\n         mychr\t10\t14\tmychr_10_14_for\t4\t+\tACT[3,4]\n-    \n-    less /tmp/mychr.fa | fastaRegexFinder.py -f - -r \'A\\w\\wGn\'\n+\n+    less /tmp/mychr.fa | fastaRegexFinder.py -f - -r \'A\\\\w\\\\wGn\'\n         mychr\t0\t5\tmychr_0_5_for\t5\t+\tACTGn\n         mychr\t5\t10\tmychr_5_10_for\t5\t+\tACTGn\n         mychr\t10\t15\tmychr_10_15_for\t5\t+\tACTGn\n@@ -56,62 +56,78 @@\n DOWNLOAD\n     fastaRegexFinder.py is hosted at https://github.com/dariober/bioinformatics-cafe/tree/master/fastaRegexFinder\n \n-    """, formatter_class= argparse.RawTextHelpFormatter)\n-\n-parser.add_argument(\'--fasta\', \'-f\',\n-                   type= str,\n-                   help=\'\'\'Input fasta file to search. Use \'-\' to read the file from stdin.\n-                                   \n-                   \'\'\',\n-                   required= True)\n+    """,\n+    formatter_class=argparse.RawTextHelpFormatter,\n+)\n \n-parser.add_argument(\'--regex\', \'-r\',\n-                   type= str,\n-                   help=\'\'\'Regex to be searched in the fasta input.\n+parser.add_argument(\n+    "--fasta",\n+    "-f",\n+    type=str,\n+    help="Input fasta file to search. Use \'-\' to read the file from stdin.",\n+    required=True,\n+)\n+\n+parser.add_argument(\n+    "--regex",\n+    "-r",\n+    type=str,\n+    help="""Regex to be searched in the fasta input.\n Matches to the reverse complement will have - strand.\n-The default regex is \'([gG]{3,}\\w{1,7}){3,}[gG]{3,}\' which searches\n-for G-quadruplexes.                                   \n-                   \'\'\',\n-                   default= \'([gG]{3,}\\w{1,7}){3,}[gG]{3,}\')\n+The default regex is \'([gG]{3,}\\\\w{1,7}){3,}[gG]{3,}\' which searches\n+for G-quadruplexes.""",\n+    default="([gG]{3,}\\\\w{1,7}){3,}[gG]{3,}",\n+)\n \n-parser.add_argument(\'--matchcase\', \'-m\',\n-                   action= \'store_true\',\n-                   help=\'\'\'Match case while searching for matches. Default is\n+parser.add_argument(\n+    "--matchcase",\n+    "-m",\n+    action="store_true",\n+    help="""Match case while searching for matches. Default is\n to ignore case (I.e. \'ACTG\' will match \'actg\').\n-                   \'\'\')\n+                   """,\n+)\n \n-parser.add_argument(\'--noreverse\',\n-                   action= \'store_true\',\n-                   help=\'\'\'Do not search the reverse complement of the input fasta.\n-Use this flag to search protein sequences.                                   \n-                   \'\'\''..b'"g",\n+        "g": "c",\n+        "t": "a",\n+        "r": "y",\n+        "y": "r",\n+        "s": "w",\n+        "w": "s",\n+        "k": "m",\n+        "m": "k",\n+        "b": "v",\n+        "d": "h",\n+        "h": "d",\n+        "v": "b",\n+        "n": "n",\n+    }\n+    xrc = []\n     for n in x:\n         xrc.append(compdict[n])\n-    xrc= \'\'.join(xrc)[::-1]\n-    return(xrc)\n+    xrc = "".join(xrc)[::-1]\n+    return xrc\n+\n+\n # -----------------------------------------------------------------------------\n \n-psq_re_f= re.compile(args.regex, flags= flag)\n-## psq_re_r= re.compile(regexrev)\n+psq_re_f = re.compile(args.regex, flags=flag)\n+# psq_re_r= re.compile(regexrev)\n \n-if args.fasta != \'-\':\n-    ref_seq_fh= open(args.fasta)\n+if args.fasta != "-":\n+    ref_seq_fh = open(args.fasta)\n else:\n-    ref_seq_fh= sys.stdin    \n+    ref_seq_fh = sys.stdin\n \n-ref_seq=[]\n-line= (ref_seq_fh.readline()).strip()\n-chr= re.sub(\'^>\', \'\', line)\n-line= (ref_seq_fh.readline()).strip()\n-gquad_list= []\n+ref_seq = []\n+line = (ref_seq_fh.readline()).strip()\n+chr = re.sub("^>", "", line)\n+line = (ref_seq_fh.readline()).strip()\n+gquad_list = []\n while True:\n     if not args.quiet:\n-        sys.stderr.write(\'Processing %s\\n\' %(chr))\n-    while line.startswith(\'>\') is False:\n+        sys.stderr.write("Processing %s\\n" % (chr))\n+    while line.startswith(">") is False:\n         ref_seq.append(line)\n-        line= (ref_seq_fh.readline()).strip()\n-        if line == \'\':\n+        line = (ref_seq_fh.readline()).strip()\n+        if line == "":\n             break\n-    ref_seq= \'\'.join(ref_seq)\n+    ref_seq = "".join(ref_seq)\n     if args.seqnames == [None] or chr in args.seqnames:\n         for m in re.finditer(psq_re_f, ref_seq):\n-            matchstr= trimMatch(m.group(0), args.maxstr)\n-            quad_id= str(chr) + \'_\' + str(m.start()) + \'_\' + str(m.end()) + \'_for\'\n-            gquad_list.append([chr, m.start(), m.end(), quad_id, len(m.group(0)), \'+\', matchstr])\n+            matchstr = trimMatch(m.group(0), args.maxstr)\n+            quad_id = str(chr) + "_" + str(m.start()) + "_" + str(m.end()) + "_for"\n+            gquad_list.append(\n+                [chr, m.start(), m.end(), quad_id, len(m.group(0)), "+", matchstr]\n+            )\n         if args.noreverse is False:\n-            ref_seq= revcomp(ref_seq)\n-            seqlen= len(ref_seq)\n+            ref_seq = revcomp(ref_seq)\n+            seqlen = len(ref_seq)\n             for m in re.finditer(psq_re_f, ref_seq):\n-                matchstr= trimMatch(revcomp(m.group(0)), args.maxstr)\n-                mstart= seqlen - m.end()\n-                mend= seqlen - m.start()\n-                quad_id= str(chr) + \'_\' + str(mstart) + \'_\' + str(mend) + \'_rev\'\n-                gquad_list.append([chr, mstart, mend, quad_id, len(m.group(0)), \'-\', matchstr])\n-        gquad_sorted= sort_table(gquad_list, (1,2,3))\n-        gquad_list= []\n+                matchstr = trimMatch(revcomp(m.group(0)), args.maxstr)\n+                mstart = seqlen - m.end()\n+                mend = seqlen - m.start()\n+                quad_id = str(chr) + "_" + str(mstart) + "_" + str(mend) + "_rev"\n+                gquad_list.append(\n+                    [chr, mstart, mend, quad_id, len(m.group(0)), "-", matchstr]\n+                )\n+        gquad_sorted = sort_table(gquad_list, (1, 2, 3))\n+        gquad_list = []\n         for xline in gquad_sorted:\n-            xline= \'\\t\'.join([str(x) for x in xline])\n+            xline = "\\t".join([str(x) for x in xline])\n             print(xline)\n-    chr= re.sub(\'^>\', \'\', line)\n-    ref_seq= []\n-    line= (ref_seq_fh.readline()).strip()\n-    if line == \'\':\n+    chr = re.sub("^>", "", line)\n+    ref_seq = []\n+    line = (ref_seq_fh.readline()).strip()\n+    if line == "":\n         break\n \n-#gquad_sorted= sort_table(gquad_list, (0,1,2,3))\n+# gquad_sorted= sort_table(gquad_list, (0,1,2,3))\n #\n-#for line in gquad_sorted:\n+# for line in gquad_sorted:\n #    line= \'\\t\'.join([str(x) for x in line])\n #    print(line)\n sys.exit()\n'
b
diff -r 269c627ae9f4 -r 9a811adb714f fastaregexfinder.xml
--- a/fastaregexfinder.xml Wed Jun 20 11:06:57 2018 -0400
+++ b/fastaregexfinder.xml Wed Jan 25 14:03:52 2023 +0000
[
@@ -1,14 +1,15 @@
-<tool id="fasta_regex_finder" name="fasta_regex_finder" version="0.1.0">
+<tool id="fasta_regex_finder" name="Fasta regular expression finder" version="0.1.0">
     <description>
         Search in fasta for regexp match
     </description>
     <requirements>
+        <requirement type="package" version="3.8">python</requirement>
     </requirements>
-    <version_command>python $__tool_directory__/fastaregexfinder.py --version</version_command>
+    <version_command>python '$__tool_directory__/fastaregexfinder.py' --version</version_command>
     <command detect_errors="exit_code"><![CDATA[
-python $__tool_directory__/fastaregexfinder.py 
---fasta "$input"
---regex "$regex"
+python '$__tool_directory__/fastaregexfinder.py'
+--fasta '$input'
+--regex '$regex'
 #if $settings.advanced == "advanced"
     $settings.matchcase
     $settings.noreverse
@@ -18,7 +19,7 @@
     #end if
 #end if
 --quiet
-> $output
+> '$output'
     ]]></command>
     <inputs>
         <param type="data" name="input" format="fasta" />