Skip to content

Instantly share code, notes, and snippets.

asalt /
Created Sep 12, 2018
Simple script to separate MaxQuant experiments
Simple script to separate MaxQuant experiments
import os
import sys
import numpy as np
import pandas as pd
def main(f):
df = pd.read_table(f)
asalt /
Last active Mar 10, 2016
Decorator to make a specific argument an iterator
from functools import wraps
def make_iterable(argn=0, exceptions=[]):
"""Check to make sure an argument is an iterator.
Default argument is args[0]
Add exceptions that you wish to enclose in an iterator by providing an
iterator of their type.
Ironically, exceptions must be encapsulated in an iterator"""
def decorate(func):
asalt / latex_hide_figure.tex
Created Jan 21, 2016
How to hide whole sections in a latex document.
View latex_hide_figure.tex
\usepackage{todonotes} % \missingfigure
\usepackage{comment} % to exclude whole sections when I want to
\newif\ifshow % toggle true or false based on if want to hide section
%\showtrue % show the sections
\showfalse % hide the sections
View Dictionaries_demo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View filechecker
#check if files in directory aren't in log of previously encountered log
from time import sleep
def filechecker():
print '{} : Checking for new files...'.format(time.ctime())
try : log = open('filelog.log','r+U') #open log file in append mode
except : log = open('filelog.log','ab+') # if it doesn't exist, create it
files = [line.strip('\n') for line in log.readlines()] # list of all files in log
for f in os.listdir(inputdir): # iterate through all files in directory
asalt / gist:73375c0533be2fb49932
Created Jul 7, 2015
Sample of how to use positional, optional, keyword, and optional keyword arguments for a function
View gist:73375c0533be2fb49932
def func_ex(p_arg, *args, preset_guy = 'billy', **kwargs):
Example function on how to pass required positional, optional positional,
keyword arguments, and optional keyword arguments
print('positional argument value is : {}'.format(p_arg))
for arg in args:
print('Another arg is here boys : \n{}'.format(arg))
View gist:9141838a74588dc0ef93
for key in d.keys():
acc = ''
gi = 0
homolo = None
for sublst in d[key]:
if 'NP' in sublst[3]:
if sublst[2] > gi:
acc = sublst[3]
gi = sublst[2]
asalt / Counter implementation
Created Jun 17, 2015
Count and use uniques
View Counter implementation
from collections import Counter
# construct counter to count the number of occurances of each fasta
cnt = Counter()
with inputfile as f:
for line in f:
linesplit = line.split('\t')
cnt[linesplit[fasta_pos]] += 1 #establish counter, count occurrances of each fasta file
with inputfile as f:
asalt / simple dictionary creation
Last active Aug 29, 2015
Simple way to build a dictionary that has a list of lists as values. Good for removing redundancies (keys) but preserving redundancies in the values.
View simple dictionary creation
d = {}
with open('myfile.ext','rU') as f:
for line in f:
linesplit = line.split('\t')
d[linesplit[fasta_pos]].append( [x for x in linesplit[other_positions] ) #list comprehension
except KeyError:
d[linesplit[fasta_pos]] = []
d[linesplit[fasta_pos]].append( [x for x in linesplit[other_positions] )