Skip to content

Instantly share code, notes, and snippets.

View MrCreosote's full-sized avatar

MrCreosote

  • Lawrence Berkeley National Laboratory
View GitHub Profile
import datetime, time, functools, operator, types
default_fudge = datetime.timedelta(seconds=0, microseconds=0, days=0)
def deep_eq(_v1, _v2, datetime_fudge=default_fudge, _assert=False):
"""
Tests for deep equality between two python data structures recursing
into sub-structures if necessary. Works with all python types including
iterators and generators. This function was dreampt up to test API responses
but could be used for anything. Be careful. With deeply nested structures
@MrCreosote
MrCreosote / hideWS.py
Last active February 11, 2016 03:27
Hide public workspaces via the administration interface
'''
Makes the specified workspaces non-public.
Parameters:
wsclient - an initialized workspace client. The user logged into the client
must be a workspace administrator.
wslist - a list of workspace IDs and / or names.
'''
@MrCreosote
MrCreosote / gist:ffdd173574014196f8775abe7fa1ac46
Created February 11, 2017 01:44
EqualsVerifier missing instruction
import org.junit.Test;
import nl.jqno.equalsverifier.EqualsVerifier;
public class EqualsVerifierTesting {
private static class Foo {
private final String s;
import os
import sys
from pymongo.mongo_client import MongoClient
WS_MONGO_PWD = 'WS_MONGO_PWD'
MONGO_COL_WSOBJS = 'workspaceObjVersions'
def get_ws_obj_collection():
import os
import sys
from pymongo.mongo_client import MongoClient
WS_MONGO_PWD = 'WS_MONGO_PWD'
MONGO_COL_WSOBJS = 'workspaceObjVersions'
def get_ws_obj_collection(argv):
@MrCreosote
MrCreosote / stochastic_sortedness.py
Created June 22, 2022 22:33
Stochastic measure of the sortedness of a list
import random
def stochastic_sortedness(list_, num_samples):
''' Based on https://stackoverflow.com/a/16994740/643675 '''
if len(list_) < 2:
return 0
# a 2 item list works, but is a pretty dumb thing to pass to this function *shrug*
maxindex = len(list_) - 1
score = 0
@MrCreosote
MrCreosote / copy_assemblies_to_env.py
Last active April 7, 2023 01:31
Copy assemblies from one KBase environment to another
import os
import random
import requests
import sys
import tempfile
import time
"""
Issues:
"""
Totally gross Q&D implementation of mapping microtrait traits to gene / hmm names.
"""
_RULE2_TRAIT = "./microtrait/data-raw/microtrait_rule2trait.txt"
_SUBSTRATE2_RULE = "./microtrait/data-raw/microtrait_substrate2rule.txt"
_RULE_UNWRAPPED = "./microtrait/data-raw/microtrait_ruleunwrapped.txt"
_OUT = "./traits2genes.tsv"
@MrCreosote
MrCreosote / hacky_images_in_narratives.md
Last active February 12, 2024 19:19
Hackily add images to a Narrative and store said images in KBase
  • Note: this is not a reasonable general solution for images in narratives because:
    • Even if all the steps below were automated for the user, it suffers from the so called "copy of a copy" problem. Namely, if the narrative is copied by a different user and the user loses access to the source narrative, the narrative will no longer be able to access the report object embedded in the HtmlFileSetService URL.
    • The HTMLFileSetService dynamic url is hardcoded into the narrative markdown text and it's, well, dynamic. It can change at any time at which point the images will 404.

Procedure:

  • Add all your images to a zip file
  • Using your kbase token, upload the zip file to Shock
24/07/17 21:30:49 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
24/07/17 21:30:49 INFO DefaultNoHARMFailoverProxyProvider: Connecting to ResourceManager at yarn-resourcemanager/172.26.0.3:8032
24/07/17 21:30:49 INFO Configuration: resource-types.xml not found
24/07/17 21:30:49 INFO ResourceUtils: Unable to find 'resource-types.xml'.
24/07/17 21:30:49 INFO Client: Verifying our application has not requested more than the maximum memory capability of the cluster (8192 MB per container)
24/07/17 21:30:49 INFO Client: Will allocate AM container, with 1408 MB memory including 384 MB overhead
24/07/17 21:30:49 INFO Client: Setting up container launch context for our AM
24/07/17 21:30:49 INFO Client: Setting up the launch environment for our AM container
24/07/17 21:30:49 INFO Client: Preparing resources for our AM container
24/07/17 21:30:49 WARN Client: Neither spark.yarn.jars nor spark.yarn.archive is set, falling back to uploading lib