Skip to content

Instantly share code, notes, and snippets.

@pfurio
pfurio / audit_login.py
Last active Nov 30, 2017
OpenCGA: Extract number of times every user logged in in a month
View audit_login.py
#!/usr/bin/env python
from pymongo import MongoClient
from bson import ObjectId
import datetime
import argparse
parser = argparse.ArgumentParser(description='Get the number of times each user have logged in during a period of time.')
parser.add_argument('host', metavar='host', help='Mongo host and port. Example: localhost:27017.')
# parser.add_argument('database', metavar='database', help='Mongo database name. Example: opencga_catalog.')
@pfurio
pfurio / #Opencga migration 1.1.x to 1.2.0
Last active Sep 15, 2017
OpenCGA migration scripts to move from release 1.1.x to 1.2.0
View #Opencga migration 1.1.x to 1.2.0
// 1. Load the function from https://gist.github.com/pfurio/f7cd90af08e0073699f0beeeef1958ba
// 2. Load all the scripts present in the gist in the CATALOG database
@pfurio
pfurio / removeSessions.js
Last active Jun 23, 2017
Remove old sessions (OpenCGA version < 1.2)
View removeSessions.js
// Extracted from https://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object
Date.prototype.opencgaDate = function() {
// We will get the current day minus 7 days
this.setDate(this.getDate() - 7);
var mm = this.getMonth() + 1; // getMonth() is zero-based
var dd = this.getDate();
return [this.getFullYear(),
(mm>9 ? '' : '0') + mm,
(dd>9 ? '' : '0') + dd,
@pfurio
pfurio / opencga-1.1.0-migration.js
Last active May 17, 2017
Opencga 1.1.0 migration
View opencga-1.1.0-migration.js
// Use migration script https://gist.github.com/pfurio/f7cd90af08e0073699f0beeeef1958ba
/*
Migrate NUMERIC variables to DOUBLE https://github.com/opencb/opencga/issues/545
*/
// This function receives an array of variables (not variableSet),
// and will modify NUMERIC variables to DOUBLE recursively
function modifyNumeric(variables) {
var modified = false;
@pfurio
pfurio / permissionMigration.js
Last active Feb 17, 2017
RC3 - 1.0.0-final catalog permission migration. This will need first https://gist.github.com/pfurio/f7cd90af08e0073699f0beeeef1958ba
View permissionMigration.js
migrateCollection("metadata", {}, {config: 1, acl: 1}, function (bulk, doc) {
var id = doc._id;
var permissions = ["VIEW_FILE_HEADERS", "VIEW_FILE_CONTENTS", "VIEW_FILES", "WRITE_FILES", "VIEW_JOBS", "WRITE_JOBS"];
doc.acl[0].permissions = permissions;
doc.config.acl[0].permissions = permissions;
bulk.find({_id: id}).update({$set: {"acl": doc.acl, "config.acl": doc.config.acl}});
});
@pfurio
pfurio / migrateCollection.js
Last active May 16, 2017
Base migration script
View migrateCollection.js
function migrateCollection(collection, query, projection, migrateFunc) {
var bulk = db.getCollection(collection).initializeOrderedBulkOp();
var count = 0;
var bulkSize = 500;
db.getCollection(collection).find(query,projection).forEach(function(doc) {
migrateFunc(bulk, doc);
if ( bulk.nUpdateOps + bulk.nInsertOps + bulk.nRemoveOps >= bulkSize ) {
count += bulk.nUpdateOps + bulk.nInsertOps + bulk.nRemoveOps;
print("Execute bulk! " + count);
bulk.execute();
@pfurio
pfurio / readPeaks.py
Created May 13, 2013
Get the counts for DNAse-seq experiments
View readPeaks.py
# -*- coding: utf-8 -*-
# Author: Pedro Furió Tarí
# Data: 06/05/2013
#
# This script will take a sorted and indexed bam file and return different text files with the counts
# Useful when doing a trimming step for pair-end. After trimming, we have to make sure that we have the pairs correctly paired
import getopt, sys, os.path
import pysam