Exemplo n.º 1
0
 def gettoid(self):
     adict = self.mapped
     idlist = []
     for i in adict:
         temp = adict[i]  #each mapped record is a list
         idlist += temp
         #for v in temp:
         #    idlist+=[v]
     idlist = cmn.unify(idlist)
     return idlist
Exemplo n.º 2
0
def detail_goserver(r_dict, d_dict, fromdb, todb, alist):
    try:  #the normal way
        record = Entrez.read(Entrez.elink(dbfrom=fromdb, db=todb, id=alist))
        r_dict, d_dict = detail_map_dict(r_dict, d_dict, record)
        del record
        #print 'I am normal!\n'
    except:
        #first try do it one by one
        for aa in alist:
            try:
                print('try it one by one, here I am in %s .\n' % aa)
                record = Entrez.read(
                    Entrez.elink(dbfrom=fromdb, db=todb, id=aa))
                r_dict, d_dict = detail_map_dict(r_dict, d_dict, record)
                del record
                #print 'I succeed at my first trial!\n'
            except:
                #if one still fail, try sometimes
                print('I need try more times on %s .\n' % aa)
                flag = False
                count = 0  #times trying
                while (flag == False and count < 3):
                    count += 1
                    print('trying my %s times...\n' % count)
                    try:
                        time.sleep(2)  #interval between times
                        record = Entrez.read(
                            Entrez.elink(dbfrom=fromdb, db=todb, id=aa))
                        r_dict, d_dict = detail_map_dict(
                            r_dict, d_dict, record)
                        del record
                        flag = True
                        #print 'yes, I have done it!\n'
                    except:
                        flag = False
                #well, the server doesn't like me...
                if flag == False:
                    print('something wrong with this id: %s\n' % aa)

    for key in r_dict:
        r_dict[key] = cmn.unify(r_dict[key])
    return r_dict, d_dict
Exemplo n.º 3
0
def old_goserver(r_dict,
                 fromdb,
                 todb,
                 alist,
                 linkname=None,
                 recr=False,
                 recording=False,
                 times=0):
    try:  #the normal way
        #if True:
        if recording:
            if recr == False:  #not in recursive loop
                r_dict, alist = local_fetch(r_dict, alist,
                                            "%s_%s" % (fromdb, todb))
        if alist != []:
            record = visit_Entrez(fromdb=fromdb,
                                  todb=todb,
                                  alist=alist,
                                  linkname=linkname)
        #print record
        r_dict = map_dict(fromdb, todb, r_dict, record, recording=recording)
        del record
        #print 'I am normal!\n'
    #else:
    except:
        #first try do it one by one
        #for aa in alist:
        if len(alist) == 1:
            aa = alist[0]
            #try:
            #    print 'try it one by one, here I am in %s .\n' % aa
            #    record=Entrez.read(Entrez.elink(dbfrom=fromdb,db=todb,id=aa))
            #    r_dict=map_dict(fromdb,todb,r_dict,record,exclusion)
            #    del record
            #print 'I succeed at my first trial!\n'
            #except:
            #if one still fail, try sometimes
            if True:
                print('I need try more times on %s .\n' % aa)
                flag = False
                count = 0  #times trying
                while (flag == False and count < 3):
                    count += 1
                    print('trying my %s times...\n' % count)
                    try:
                        time.sleep(3)  #interval between times
                        record = visit_Entrez(fromdb=fromdb,
                                              todb=todb,
                                              alist=alist,
                                              linkname=linkname)

                        r_dict = map_dict(fromdb,
                                          todb,
                                          r_dict,
                                          record,
                                          recording=recording)
                        del record
                        flag = True
                        #print 'yes, I have done it!\n'
                    except:
                        flag = False
                #well, the server doesn't like me...
                if flag == False:
                    print('something wrong with this id: %s\n' % aa)
        elif times < 3:
            #if the length is not one yet, divide and do again
            #only go into recursion for 3 loop
            times += 1
            try:
                midpoint = len(alist) / 2
                aalist = alist[:midpoint]
                ablist = alist[midpoint:]
                r_dict = goserver(r_dict,
                                  fromdb,
                                  todb,
                                  aalist,
                                  linkname=linkname,
                                  recr=True,
                                  recording=recording,
                                  times=times)
                r_dict = goserver(r_dict,
                                  fromdb,
                                  todb,
                                  ablist,
                                  linkname=linkname,
                                  recr=True,
                                  recording=recording,
                                  times=times)
            except RuntimeError as theError:
                if theError == "maximum recursion depth exceeded":
                    for item in alist:
                        r_dict = goserver(r_dict,
                                          fromdb,
                                          todb, [item],
                                          linkname=linkname,
                                          recr=True,
                                          recording=recording)
        else:  #more than 3 times
            for item in alist:
                r_dict = goserver(r_dict,
                                  fromdb,
                                  todb, [item],
                                  linkname=linkname,
                                  recr=True,
                                  recording=recording,
                                  times=4)

    for key in r_dict:
        r_dict[key] = cmn.unify(r_dict[key])
    return r_dict