Skip to content

Instantly share code, notes, and snippets.

@asalt
asalt / maxquant_separate_experiments.py
Created September 12, 2018 01:12
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
asalt / make_iter.py
Last active March 10, 2016 21:49
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):
@wraps(func)
@asalt
asalt / latex_hide_figure.tex
Created January 21, 2016 21:15
How to hide whole sections in a latex document.
%http://tex.stackexchange.com/questions/77920/comment-package-excludecomment-gives-error
\documentclass[12pt]{article}
\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
\ifshow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#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
asalt / gist:73375c0533be2fb49932
Created July 7, 2015 20:57
Sample of how to use positional, optional, keyword, and optional keyword arguments for a function
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))
for key in d.keys():
acc = ''
gi = 0
taxonfaa=None
homolo = None
for sublst in d[key]:
if 'NP' in sublst[3]:
if sublst[2] > gi:
acc = sublst[3]
gi = sublst[2]
@asalt
asalt / Counter implementation
Created June 17, 2015 15:20
Count and use uniques
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
asalt / simple dictionary creation
Last active August 29, 2015 14:23
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.
d = {}
with open('myfile.ext','rU') as f:
for line in f:
linesplit = line.split('\t')
try:
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] )