예제 #1
0
    for c in chr_list:
        chrQuery = {'chr': c}
        updateDict = {'CHR': ''.join(['chr', c])}
        setDict = {'$set': updateDict}
        print 'Adding chr prefix for CHR fields containing %s' % (c)
        mongo.update(collection_name, chrQuery, setDict)

    distinct = mongo.distinct(collection_name, 'chr')
    print 'chromosomes updated to:'
    print distinct

    print 'Done in %i seconds' % (time.time() - starttime)



if __name__ == "__main__":
    annotation_name = 'annotations'

    p = Parameters.parameter()
    mongo = Mongo_Connector.MongoConnector(p.get('server'), p.get('port'), p.get('default_database'))
    # mongo.ensure_index(annotation_name, 'chr')  # don't index just on chromosome name

    chromosome_list = [str(i) for i in range(1, 22)]    # Create an expected list of chromosomes
    chromosome_list.append('X')
    chromosome_list.append('Y')
    print 'Adding prefix chr to chromosome field in methyl450 arrays...'
    AddChrPrefix(annotation_name, chromosome_list)
    mongo.close()


sys.path.insert(0, _root_dir + os.sep + "CommonUtils")
import Parameters
import Mongo_Connector

def gene_to_lower():
    '''append chr prefix.'''
    starttime = time.time()
    cursor = mongodb.find('ensgenes', {}, {"name":1, "_id":0})
    for gene in cursor:
        # print "gene.name = %s" % (gene['name'])
        mongodb.update('ensgenes', {"name":gene['name']}, {'$set': {'namelc':gene['name'].lower()}})
    print 'Done in %i seconds' % (time.time() - starttime)




if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    # parser.add_argument("csvbeta", help = "The file name of the CSV beta file to import", type = str)
    parser.add_argument("-dbconfig", help = "An optional file to specify the database location - default is database.conf in MongoDB directory", type = str, default = None)
    parser.add_argument("-dbname", help = "name of the Database in the Mongo implementation to use - default is provided in the database.conf file specified", type = str, default = None)
    args = parser.parse_args()
    p = Parameters.parameter(args.dbconfig)
    if args.dbname:
        p.set("default_database", args.dbname)
    mongodb = Mongo_Connector.MongoConnector(p.get('server'), p.get('port'), p.get('default_database'))
    gene_to_lower()
    mongodb.close()