{
  "id": "https://cgc-api.sbgenomics.com/gauravCGC/tutorials/Transcribe/0/raw/",
  "class": "CommandLineTool",
  "label": "Transcribe",
  "description": "This project was created to demonstrate the use of argparse to create CLI tools in Python, wrap them using CWL/SDK.v2, and running them.\n\nThis tool takes a TXT file with a DNA sequence and converts to an RNA sequence.",
  "requirements": [
    {
      "class": "CreateFileRequirement",
      "fileDef": [
        {
          "filename": "transcribe_argparse.py",
          "fileContent": "#!/usr/bin/env/python\nimport argparse\nimport re\nimport sys\n\ndef transcribe(args):\n\t# create a transcription map and use regex to translate\n\tmap = {\"A\":\"U\", \"T\":\"A\", \"C\":\"G\", \"G\":\"C\"}\n\tmap = dict((re.escape(k), v) for k, v in map.iteritems())\n\tpattern = re.compile(\"|\".join(map.keys()))\n\tDNA = args['dna'].read().strip()\n\tmRNA = pattern.sub(lambda m: map[re.escape(m.group(0))], DNA)\n\n\t# write a verbose output to stderr and just mRNA to sdtout \n\tif args['verbose']:\n\t\tsys.stderr.write(\"Your original DNA sequence: \" + DNA + \"\\n\")\n\t\tsys.stderr.write(\"Your translated mRNA sequence: \" + mRNA + \"\\n\")\n\tsys.stdout.write(mRNA + '\\n')\n\tsys.exit(0)\n\treturn mRNA\n\nif __name__ == \"__main__\":\n\t\"\"\" Parse the command line arguments \"\"\"\n\tparser = argparse.ArgumentParser()\n\tparser.add_argument(\"-d\", \"--dna\", type=argparse.FileType(\"r\"), default=sys.stdin)\n\tparser.add_argument(\"-v\", \"--verbose\", action=\"store_true\", default=False)\n\t# By setting args as var(...), it becomes a dict, so 'dna' is a key\n\t# Alternative use: args = parser.parse_args(), and 'dna' is an attr of args!\n\t# You must change how you call the args you parse based on this usage! \n\targs = vars(parser.parse_args())\n\n\t\"\"\" Run the desired methods \"\"\"\n\ttranscribe(args)"
        }
      ]
    },
    {
      "class": "ExpressionEngineRequirement",
      "id": "#cwl-js-engine",
      "requirements": [
        {
          "class": "DockerRequirement",
          "dockerPull": "rabix/js-engine"
        }
      ]
    }
  ],
  "inputs": [
    {
      "description": "Input file",
      "inputBinding": {
        "position": 3,
        "prefix": "-d",
        "separate": true
      },
      "id": "#input_file",
      "type": [
        "File"
      ]
    },
    {
      "inputBinding": {
        "position": 4,
        "prefix": "--verbose",
        "separate": true
      },
      "id": "#verbose",
      "type": [
        "null",
        "boolean"
      ]
    },
    {
      "description": "Specify output filename",
      "id": "#output_filename",
      "type": [
        "null",
        "string"
      ]
    }
  ],
  "outputs": [
    {
      "outputBinding": {
        "glob": "*.txt"
      },
      "id": "#output_file_glob",
      "type": [
        "File"
      ]
    }
  ],
  "hints": [
    {
      "class": "DockerRequirement",
      "dockerImageId": "",
      "dockerPull": "rfranklin/pythondev"
    }
  ],
  "baseCommand": [
    "python",
    "transcribe_argparse.py"
  ],
  "stdout": {
    "class": "Expression",
    "script": "($job.inputs.output_filename || 'rna') + '.txt'",
    "engine": "#cwl-js-engine"
  }
}
