def main(args):
    if args.aid_file is None:
        aidlist = args.aid.split(",")
    else:
        aidlist = readfile.getListFromFile(args.aid_file)
    aidliststring = ",".join(aidlist)
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/" + aidliststring + "/cids/xml"
    print('The constructed REST URL is: %s' % url)
    dic = rest_tool_functions.get_dict_key_value(url, "AID", "CID")
    rest_tool_functions.write_to_sf(dic, args.outfile, "\t")
def main(args):
    if args.aid_file is None:
        aidlist = args.aid.split(",")
    else:
        aidlist = readfile.getListFromFile(args.aid_file)
    aidliststring = ",".join(aidlist)
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/"+aidliststring+"/cids/xml"
    print('The constructed REST URL is: %s' % url)
    dic = rest_tool_functions.get_dict_key_value(url, "AID", "CID")
    rest_tool_functions.write_to_sf(dic, args.outfile, "\t")
def main(args):
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/%s/%s/" % (args.type,
                                                               args.id_type)
    # check if we are POST then skip this part otherwise insert the ids into the url
    if not args.id_type in post_id_types:
        if args.id_type == id_dict[args.type]:
            url += readfile.getListString(args) + "/"
        else:
            url += args.id_value + "/"

    url += args.operation + "/"
    if args.operation in ["target", "property", "xrefs"]:
        url += args.operation_value + "/"

    create_dict_tsv = False
    if args.operation == "xrefs":
        if "," in args.operation_value:
            url += "xml"
        else:
            url += "txt"
    else:
        if args.operation in check_for_id_type:
            # dont create dictionary if they are the same
            if dic_key_value_type[args.type] == dic_key_value_operation[
                    args.operation]:
                url += "txt"
            else:
                url += "xml"
                create_dict_tsv = True
        else:
            url += dict_output[args.operation]
    if args.operation in check_for_id_type and args.id_type not in post_id_types:
        url += "?%s_type=%s" % (args.operation, args.ids_operation_type)
    print('The constructed REST URL is: %s' % url)

    if args.id_type in post_id_types:
        postfile = open(args.id_value, "r")
        post_value = postfile.read()
        post_dict = {args.id_type: post_value}
        #print(post_dict)
        readfile.store_result_post(url, post_dict, args.outfile)
    # check if we have to create a tsv file
    elif create_dict_tsv == True:
        key = dic_key_value_type[args.type]
        value = dic_key_value_operation[args.operation]
        dic = rest_tool_functions.get_dict_key_value(url, key, value)
        rest_tool_functions.write_to_sf(dic, args.outfile, "\t")
    else:
        readfile.store_result_get(url, args.outfile)
def main(args):
    url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/"
    url+=args.id_type+"/"
    # check if we are post then skip this part otherwise put the ids in the url
    if not args.id_type in post_id_types:
        if args.id_type ==id_dict[args.type]:
            url+=readfile.getListString(args)+"/"
        else:
            url+=args.id_value+"/"

    url+=args.operation+"/"
    if args.operation == "target" or args.operation == "property" or args.operation == "xrefs":
        url+=args.operation_value+"/"
    
    create_dict_tsv=False
    if args.operation == "xrefs":
        if "," in args.operation_value:
            url+="xml"
        else:
            url+="txt"
    else:
        if args.operation in check_for_id_type:
            # dont create dictionary if they are the same
            if dic_key_value_type[args.type] == dic_key_value_operation[args.operation]:
                url+="txt"
            else:
                url+="xml"
                create_dict_tsv=True
        else:
            url+=dict_output[args.operation]
    if args.operation in check_for_id_type and args.id_type not in post_id_types:
            url+="?%s_type=%s" % (args.operation, args.ids_operation_type)
    print(url)

    if args.id_type in post_id_types:
        postfile=open(args.id_value,"r")
        post_value=postfile.read()
        post_dict={args.id_type : post_value}
        print(post_dict)
        readfile.store_result_post(url, post_dict, args.outfile)
    # check if have to create a tsv file
    elif create_dict_tsv == True:
        key=dic_key_value_type[args.type]
        value=dic_key_value_operation[args.operation]
        dic=rest_tool_functions.get_dict_key_value(url, key, value)
        rest_tool_functions.write_to_sf(dic, args.outfile, "\t")
    else:
        readfile.store_result_get(url, args.outfile)