Skip to content

Instantly share code, notes, and snippets.

:octocat:
on it!

Carlo Mazzaferro carlomazzaferro

:octocat:
on it!
Block or report user

Report or block carlomazzaferro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@carlomazzaferro
carlomazzaferro / docstring.py
Created Nov 22, 2018
Inheriting docstrings from a top level function with decorators
View docstring.py
"""
This is particularly useful when using sphinx autodoc, when you have functions that share the same functionality
(say a cli command that wraps a function) and you don't want to rewrite the docstrings for each of them.
"""
def register_docstrings(parent=None):
def doc_decorator(func):
func.__doc__ = parent.__doc__ + func.__doc__
return func
return doc_decorator
@carlomazzaferro
carlomazzaferro / perceptron.py
Last active Feb 1, 2017
OOP approach to creating a predictive model using perceptron learning in Python.
View perceptron.py
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
class Perceptron(object):
def __init__(self, train, labels, learning_rate, iterations):
self.train = train
self.labels = labels
@carlomazzaferro
carlomazzaferro / fasta_parser.py
Created Dec 2, 2016
Parsing fasta file to python lists: protein ID, peptide sequence
View fasta_parser.py
def create_separate_lists(fasta_file):
"""
Creates 2 lists from a fasta file
:param fasta_file: file
:return: one list for the IDs in the file and one list for the proteins/peptides in it
"""
with open(fasta_file) as infile:
all_list = []
peptide = ""
lines = infile.readlines()
You can’t perform that action at this time.