# -*- coding: utf-8 -*-
"""
Usage: (python) parse_full_xml_report.py <.xml files>
Example:
        $ python parse_full_xml_report.py ncbi_full_report.xml
"""

import sys

WATSON_INDId = 30346
VENTER_INDId = 30342

THOUSAND_GENOME_popId = [13148, 13149, 13150, 16651, 16652, 16653, 16654, 16655];

def 
(full_report):
    """Writes to 'phenotype_full_xml.txt' with genes associated with rsids retrieved 
        from XML file generated by NCBI"""
    phenotype_dict = {}
    
    f = open(full_report)  

    for line in f:
        if "<FxnSet geneId=" in line:
            if "allele=" in line:
                start = line.find("symbol")
                start_quote = line.index('"', start)
                end_quote = line.index('"', start_quote+1)
                symbol = line[start_quote+1:end_quote]
                
                start = line.find("allele")
                start_quote = line.index('"', start)
                end_quote = line.index('"', start_quote+1)
                allele = line[start_quote+1:end_quote]
                
                if symbol not in phenotype_dict:
                    phenotype_dict[symbol] = allele
                    info = symbol + "\t" + allele + "\n"
                    with open('phenotype_full_xml.txt','ab') as f: f.write(info)
   
if __name__ == '__main__':
    if len(sys.argv) != 1:
        full_report = sys.argv[1]
        parse_genotype_report(full_report)
    else:
        print 'Usage: (python) parse_full_xml_report.py <.xml files>'
        print 'Example: \
            python parse_full_xml_report.py ncbi_full_report.xml'
parse_genotype_report