Skip to content

Instantly share code, notes, and snippets.

View daviddamilola's full-sized avatar
🏠
Working from home

oluwasusi david damilola daviddamilola

🏠
Working from home
View GitHub Profile
@daviddamilola
daviddamilola / page_rank.py
Created March 31, 2024 02:29
Page Ranking Algorigthm
import numpy as np
import numpy.linalg as la
from readonly.PageRankFunctions import *
np.set_printoptions(suppress=True)
def pageRank(linkMatrix, d) :
n = linkMatrix.shape[0]
M = d * linkMatrix + (1-d)/n * np.ones([n, n]) # np.ones() is the J matrix, with ones for each entry.
r = 100 * np.ones(n) / n # Sets up this vector (n entries of 1/n × 100 each)
lastR = r
# print(loadFile('./Downloads/Vibrio_cholerae.txt', 'CTTGATCAT'))
"""
FindClumps(Text, k, L, t)
Patterns ← an array of strings of length 0
n ← |Text|
for every integer i between 0 and n − L
Window ← Text(i, L)
freqMap ← FrequencyTable(Window, k)
def indexOfPatternMatch (pattern, genome):
indexes = []
patternLength = len(pattern)
for (index, _) in enumerate(genome):
if genome[index:(patternLength+index)] == pattern:
indexes.append(index)
return " ".join(str(item) for item in indexes)
def loadGenome(path, pattern):
file = open(path, 'r')
testInput = 'AAAACCCGGT'
def getReverseComplement (DnaString):
allowedTypesMap = {'A': 'T', 'G': 'C', 'T':'A', 'C': 'G'}
result = [allowedTypesMap[char] for char in (DnaString)]
return ("".join(result))[::-1]
print(getReverseComplement(testInput))
@daviddamilola
daviddamilola / k-merFrequency.js
Last active September 27, 2023 14:30
Pattern count
/**
ALGORITHM:
PatternCount(Text, Pattern)
count ← 0
for i ← 0 to |Text| − |Pattern|
if Text(i, |Pattern|) = Pattern
count ← count + 1
return count
**/
import { useLayoutEffect, useRef, MutableRefObject } from 'react';
const useFlipAnimation = (
elemRef: MutableRefObject<HTMLDivElement | null>,
layoutChangeFn: (x: boolean) => void,
whenToRun: boolean
) => {
const justMounted = useRef(true);
useLayoutEffect(() => {
if (justMounted.current) {
@daviddamilola
daviddamilola / getMinDiff.js
Last active May 28, 2021 07:41
get min diff between time items in array
const getDiff = (date1, date2) => {
let diff = date1 - date2
const result = (diff/60)
return result;
}
const parseToSeconds = (time)=> {
const hrsMins = time.split(':')
const secHrs = parseInt(hrsMins[0],10) * 60 * 60
const secMins = parseInt(hrsMins[1],10) * 60
@daviddamilola
daviddamilola / removeInstance.js
Created April 16, 2021 21:27
returns the length new array after removing provided instance
const removeInstance = (array=[], val=null) => {
if(!Array.isArray(array)) return 0;
if(!val) return array.length;
let currIndex = array.indexOf(val);
while(currIndex !== -1){
array.splice(currIndex, 1)
currIndex = array.indexOf(val);
}
return array.length
}
export default function usePromise(api) {
const [state, dispatch] = useReducer(
(state, action) => {
switch (action.type) {
case 'LOADING':
return { ...state, loading: true }
case 'RESOLVED':
return { ...state, loading: false, response: action.response, error: null }
case 'ERROR':
return { ...state, loading: false, response: null, error: action.error }
@daviddamilola
daviddamilola / permu_string.py
Created April 11, 2021 20:29
possible permutations of a given string
def bitStr(n, s):
if n == 1: return s
return [ digit + bits for digit in bitStr(1,s) for bits in bitStr(n- 1,s)]
print (bitStr(3,'abc'))