#!/usr/bin/python

import sys
import getopt
from AnnotatorCore import *

def main(argv):

    baseurl = 'http://oncokb.org'
    inputcnafile = ''
    inputclinicalfile = ''
    outputcnafile = ''
    defaultcancertype = 'cancer'

    try:
        opts, args = getopt.getopt(argv, "hi:o:c:d:t:u:")
    except getopt.GetoptError:
        print 'for help: python CnaAnnotator.py -h'
        sys.exit(2)

    for opt, arg in opts:
        if opt == '-h':
            print 'CnaAnnotator.py -i <input cNA file> -o <output MAF file> [-c <input clinical file>] [-t <default tumor type>] [-u base-url]'
            print '  Input CNA file should follow the GISTIC output (https://cbioportal.readthedocs.io/en/latest/File-Formats.html#discrete-copy-number-data)'
            print '  Essential clinical columns:'
            print '    SAMPLE_ID: sample ID'
            print '    ONCOTREE_CODE: tumor type code from oncotree (oncotree.mskcc.org)'
            print '  Cancer type will be assigned based on the following priority:'
            print '     1) ONCOTREE_CODE in clinical data file'
            print '     2) ONCOTREE_CODE exist in MAF'
            print '     3) default tumor type (-t)'
            print '  Default OncoKB base url is http://oncokb.org'
            sys.exit()
        elif opt in ("-i"):
            inputcnafile = arg
        elif opt in ("-o"):
            outputcnafile = arg
        elif opt in ("-c"):
            inputclinicalfile = arg
        elif opt in ("-t"):
            defaultcancertype = arg
        elif opt in ("-u"):
            setoncokbbaseurl(arg)

    if inputcnafile == '' or outputcnafile=='':
        print 'for help: python MafAnnotator.py -h'
        sys.exit(2)

    cancertypemap = {}
    if inputclinicalfile != '':
        readCancerTypes(inputclinicalfile, cancertypemap)

    print 'annotating '+inputcnafile+"..."

    processcnagisticdata(inputcnafile, outputcnafile, defaultcancertype, cancertypemap, False)

    print 'done!'

if __name__ == "__main__":
    argv = [
        '-i', 'data/example_cna.txt',
        '-o', 'data/example_cna.oncokb.txt',
        '-c', 'data/example_clinical.txt',
    ]
    main(argv)

    # print sys.argv[1:]
    # main(sys.argv[1:])
@@ -2011,16 +2011,18 @@
 __%22:%0A   
+ #
  argv = 
@@ -2022,24 +2022,26 @@
 argv = %5B%0A   
+ #
      '-i', '
@@ -2062,24 +2062,26 @@
 na.txt',%0A   
+ #
      '-o', '
@@ -2109,24 +2109,26 @@
 kb.txt',%0A   
+ #
      '-c', '
@@ -2162,14 +2162,18 @@
 %0A   
+ #
  %5D%0A   
+ #
  mai
@@ -2205,26 +2205,24 @@
 argv%5B1:%5D%0A   
- #
  main(sys.ar
@@ -2228,8 +2228,9 @@
 rgv%5B1:%5D)
+%0A

revert testing code