Skip to content

Instantly share code, notes, and snippets.

View kwcooper's full-sized avatar
🧠
User is typing...

Keiland kwcooper

🧠
User is typing...
View GitHub Profile
@kwcooper
kwcooper / watxt2csv.py
Last active September 27, 2023 12:58
To clean and convert a whatsapp txt file export to a CSV file
# To clean and convert a whatsapp txt file export to a CSV file
import pandas as pd
# read file by lines
file_path = "whatsapp.txt"
f = open(file_path, 'r')
data = f.readlines()
f.close()
@kwcooper
kwcooper / mutate_amino.py
Created December 15, 2022 03:49
Simple function to mutate a string of amino acids given their indicies
def mutate_amino(protein_str, mutations, offset=1):
''' mutations: {int>mutation_idx:str>AminoID}'''
mut_protein_str = list(protein_str)
for mut_idx in mutations.keys():
mut_protein_str[mut_idx-offset] = mutations[mut_idx] # Arg 71 His | R > H
mut_protein_str = ''.join(mut_protein_str)
return mut_protein_str
@kwcooper
kwcooper / clickedImageCoords.py
Created August 24, 2022 09:17
A simple interface to return clicked coordinates of an image
import cv2
class PointGrabber:
def __init__(self, imgPath, printCords=True):
self.points = []
self.img = cv2.imread(imgPath, 1)
self.printCords = printCords
def select_point(self, event, x, y, flags, param):
@kwcooper
kwcooper / Wald-Wolfowitz_Runs_Test.py
Created May 16, 2019 07:45
Wald-Wolfowitz Runs Test demonstration in python
# Wald-Wolfowitz Runs Test (Actual)
# *** For educational purposes only,
# use more robust code for actual analysis
import math
import scipy.stats as st # for pvalue
# Example data (Current script only works for binary ints)
L = [1,1,1,0,1,1,1,0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,0,1,0,0,1,0,0,1,1,1,0,0,0,1]
@kwcooper
kwcooper / bdayICS.py
Created March 27, 2021 23:19
Never miss a birthday! Create an ics calendar file from a spreadsheet of birthdays
# Computes an ICS file of birthdays from a spreadsheet
# spreadsheet in the format of
# Name - persons name
# Date - Birthdate in %m/%d/%Y format
# Description - some links or other info you want to add
# this is built ontop of ICSps
# https://icspy.readthedocs.io/en/stable/
# install with pip install ics
@kwcooper
kwcooper / linkGrabber.py
Created March 10, 2021 18:01
Quick script to extract links from raw text, then clean them
import re
import pandas as pd
# kwc 210310
data_fName = 'linkGrabberData.txt'
saveName = 'linkedinLinks.csv'
re_exp = '(((//)|(\\\\))+([\w\d:#@%/;$()~_?\+-=\\\.&](#!)?)*)'
@kwcooper
kwcooper / extIP.py
Last active December 31, 2020 21:30
Very simple external IP plugin for the landscape-sysinfo linux package
# Modified 190812 k
# Be sure to add to the list of packages in deployment.py
# /usr/lib/python3/dist-packages/landscape/sysinfo/deployment.py
from twisted.internet.defer import succeed
from requests import get
current_instance = None
@kwcooper
kwcooper / violinPlot.py
Created December 4, 2020 04:26
create a violin plot with matplotlib
import matplotlib.pyplot as plt
# kwc 201208
# Create synthetic data for each plot
np.random.seed(10)
synData_1 = np.random.normal(100, 10, 200)
synData_2 = np.random.normal(80, 30, 200)
synData_3 = np.random.normal(90, 20, 200)
synData_4 = np.random.normal(70, 25, 200)
@kwcooper
kwcooper / groupbylist.py
Created October 1, 2020 05:29
Group one list by another list with itertools and python 3+
from itertools import groupby
l1 = [1,1,1,2,2,2,2,2,1,1,1,0,0,0]
l2 = range(len(l1))
[(k, list(group)) for k, group in groupby(l2, key=lambda _, ig=iter(l1): next(ig))]
# Returns [(1, [0, 1, 2]), (2, [3, 4, 5, 6, 7]), (1, [8, 9, 10]), (0, [11, 12, 13])]
@kwcooper
kwcooper / barplot.py
Created April 23, 2020 07:23
Create a simple bar plot so I don't have to keep writing it
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')
# Create test data
a, b = np.random.randint(10, 25, 30), np.random.randint(0, 8, 30)
a_mu, b_mu = np.mean(a), np.mean(b)
a_std, b_std = np.std(a), np.std(b)