コード例 #1
0
def getAllCidsForAssayActivity(activity):
    url = ("http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/activity/" +
           activity + "/aids/txt?list_return=listkey")
    readfile.getresult(url)
    #    url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/listkey/"+listkey+"/cids/xml"
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/25425,12345/cids/xml"
    print(("url: " + url))
    xml = readfile.getresult(url)

    # init parser
    handler = DictHandler()
    parser = sax.make_parser()
    parser.setContentHandler(handler)

    tempfile = open("tempfile", "w")
    # handle the last line, there is sometimes some random output
    lastline_arr = xml.split("\n")
    # print(lastline_arr)

    print("l: ")
    print((len(lastline_arr)))
    lastline = lastline_arr[len(lastline_arr) - 1]
    print(("lastline: " + lastline))
    print(("lastline-2: " + lastline_arr[len(lastline_arr) - 2]))
    cidlastline = getIDofLine(lastline)
    # aidkey = "-1"
    if cidlastline != "-1":
        i = len(lastline_arr) - 2
        # search for nex aid entry
        while i >= 0 and "AID" not in lastline_arr[i]:
            i -= 1
        # if i >= 0:
        #     aid = getIDofLine(lastline_arr[i])
        # if aid != "-1":
        #     aidkey = aid
    # remove the last line and put the array back together

    lastline_arr_list = list(lastline_arr)
    # lastline_arr_list.remove(lastline)
    xml2 = "\n".join(lastline_arr_list)
    tempfile.write(xml2)
    # add the last tags
    # tempfile.write("</Information></InformationList>")
    tempfile.close()
    parser.parse(open("tempfile", "r"))
    dic = handler.ergebnis

    # add the last line
    # if cidlastline != "-1":
    #    dic[aidkey].append(cidlastline)
    return dic
def getAllCidsForAssayActivity(activity):
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/activity/" + activity + "/aids/txt?list_return=listkey"
    listkey = readfile.getresult(url)
    #    url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/listkey/"+listkey+"/cids/xml"
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/aid/25425,12345/cids/xml"
    print ("url: " + url)
    xml = readfile.getresult(url)

    # init parser
    handler = DictHandler()
    parser = sax.make_parser()
    parser.setContentHandler(handler)

    tempfile = open("tempfile", "w")
    # handle the last line, there is sometimes some random output
    lastline_arr = xml.split("\n")
    # print(lastline_arr)

    print ("l: ")
    print (len(lastline_arr))
    lastline = lastline_arr[len(lastline_arr) - 1]
    print ("lastline: " + lastline)
    print ("lastline-2: " + lastline_arr[len(lastline_arr) - 2])
    cidlastline = getIDofLine(lastline)
    aidkey = "-1"
    if cidlastline != "-1":
        i = len(lastline_arr) - 2
        # search for nex aid entry
        while i >= 0 and "AID" not in lastline_arr[i]:
            i -= 1
        if i >= 0:
            aid = getIDofLine(lastline_arr[i])
            if aid != "-1":
                aidkey = aid
    # remove the last line and put the array back together

    lastline_arr_list = list(lastline_arr)
    # lastline_arr_list.remove(lastline)
    xml2 = "\n".join(lastline_arr_list)
    tempfile.write(xml2)
    # add the last tags
    # tempfile.write("</Information></InformationList>")
    tempfile.close()
    parser.parse(open("tempfile", "r"))
    dic = handler.ergebnis

    # add the last line
    # if cidlastline != "-1":
    #    dic[aidkey].append(cidlastline)
    return dic
コード例 #3
0
ファイル: rest_tool.py プロジェクト: Ahsanzia/galaxytools
def main(args):
    url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/"+args.type+"/"
    if args.type == "assay":
        url+="aid/"
    elif args.type == "compound":
        url+="cid/"
    elif args.type == "substance":
        url+="sid/"
    if args.id_file is None:
        idstring=str(args.id)
    else:
        idlist=readfile.getListFromFile(args.id_file)
        idstring=",".join(idlist)
    url+=idstring+"/"+args.operation+"/"
    if args.operation == "property":
        url+=args.property_value+"/"
    if args.operation in csv_output:
        url+="csv"
    elif args.operation in txt_output:
        url+="txt"
    else:
        url+="xml"
    if args.operation in check_for_id_type and not args.id_type is None:
        url+="?"+args.operation+"_type="+args.id_type
    print('The constructed REST URL is: %s' % url)
    data=readfile.getresult(url)
    outfile=args.outfile
    outfile.write(data)
    outfile.close()
コード例 #4
0
def main(args):
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/" + args.type + "/"
    if args.type == "assay":
        url += "aid/"
    elif args.type == "compound":
        url += "cid/"
    elif args.type == "substance":
        url += "sid/"
    if args.id_file is None:
        idstring = str(args.id)
    else:
        idlist = readfile.getListFromFile(args.id_file)
        idstring = ",".join(idlist)
    url += idstring + "/" + args.operation + "/"
    if args.operation == "property":
        url += args.property_value + "/"
    if args.operation in csv_output:
        url += "csv"
    elif args.operation in txt_output:
        url += "txt"
    else:
        url += "xml"
    if args.operation in check_for_id_type and not args.id_type is None:
        url += "?" + args.operation + "_type=" + args.id_type
    print(url)
    data = readfile.getresult(url)
    outfile = args.outfile
    outfile.write(data)
    outfile.close()
コード例 #5
0
def get_dict_key_value(url, key, value):
    xml = readfile.getresult(url)
    tmp = tempfile.TemporaryFile()
    tmp.write(xml)
    tmp.seek(0)
    dic = dict_from_xml(tmp, key, value)
    tmp.close()
    return dic
コード例 #6
0
def get_dict_key_value(url, key, value):
    xml=readfile.getresult(url)
    tmp = tempfile.TemporaryFile() 
    tmp.write(xml)
    tmp.seek(0)
    dic=dict_from_xml(tmp, key, value)
    tmp.close()
    return dic
コード例 #7
0
def main(args):
    #search for acitivity or target
    url="http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/"
    if args.activity is None:
        #target
        url+= "target/%s/%s" % ( args.targettype, args.targetid )
    else:
        url+="activity/"+args.activity
    url+="/aids/txt"
    data=readfile.getresult(url)
    args.outfile.write(data)
    args.outfile.close()
コード例 #8
0
def get_dict_key_value(url, key, value):
    """
    Get all ids from a XML file, obtained from the given URL
    and convert the information into a dictionary
    """
    xml = readfile.getresult(url)
    tmp = tempfile.TemporaryFile()
    tmp.write(xml)
    tmp.seek(0)
    dic = dict_from_xml(tmp, key, value)
    tmp.close()
    return dic
コード例 #9
0
def get_dict_key_value(url, key, value):
    """
        Get all ids from a XML file, obtained from the given URL
        and convert the information into a dictionary
    """
    xml = readfile.getresult(url)
    tmp = tempfile.TemporaryFile()
    tmp.write(xml)
    tmp.seek(0)
    dic = dict_from_xml(tmp, key, value)
    tmp.close()
    return dic
コード例 #10
0
def getAllAssayIDs():
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/type/all/aids/TXT"
    data = readfile.getresult(url)
    self.keywertlist = readfile.getListFromString(data)
    return self.keywertlist
def getAllAssayIDs():
    url = "http://pubchem.ncbi.nlm.nih.gov/rest/pug/assay/type/all/aids/TXT"
    data = readfile.getresult(url)
    aidlist = readfile.getListFromString(data)
    return aidlist