Skip to content

Instantly share code, notes, and snippets.

View tbrittoborges's full-sized avatar
🎯

Thiago Britto Borges tbrittoborges

🎯
View GitHub Profile
import matplotlib
matplotlib.use("Agg")
import pyplot as plt
plt.plot([1, 2, 3])
plt.savefig("something.png")
_ref = "10.1371/journal.pone.0038772"
norm_vdw_volume = {'A': 1.00, 'M': 4.43, 'C': 2.43, 'N': 2.95, 'D': 2.78, 'P': 2.72, 'E': 3.78, 'Q': 3.95, 'F': 5.89, 'R': 6.13,
'G': 0.00, 'S': 1.60, 'H': 4.66, 'T': 2.60, 'I': 4.00, 'V': 3.00, 'K': 4.77, 'W': 8.08, 'L': 4.00, 'Y': 6.47}
def remove_description_from_fasta(input, output, regex):
with open(input,) as input_stream, open(output , 'w') as output_stream:
for line in input_stream:
if line.startswith('>'):
if regex in line:
output_stream.write(line)
write = True
else:
write = False
elif write:
@tbrittoborges
tbrittoborges / variant_fetch.py
Created June 12, 2015 14:28
ensembl + thiago code for fetching variants.
#!/usr/bin/env python
import requests
import sys
import utils
__author__ = 'tbrittoborges'
"""
Created on 14:45 04/11/2014 2014
Given a list of UniProt accession id, return all missense variants.
All variants means:
def get_url_or_retry(url, retry_in=(), wait=1, json=False, header={}, **params):
"""
Fetch an url using Requests or retry fetching it if the server is
complaining with retry_in error.
:param url: url to be fetched as a string
:param wait: sleeping between tries in seconds
:param params: request.get kwargs.
:return: url content or url content in json data structure.
"""
if json:
@tbrittoborges
tbrittoborges / pandas_Series_to_fasta.py
Created December 16, 2015 18:59
print a pandas column in the fasta format.
print '>\n' + '\n> \n'.join(list(df.query(...).sequence_column))
def is_prime(N):
for x in xrange(2, N):
if N % x == 0:
return False
return True
def sum_prime(N):
return sum(x for x in xrange(N) if is_prime(x))
@tbrittoborges
tbrittoborges / automated_github_issue.py
Last active February 17, 2016 18:03
automatically sends a github issue
import requests
data = {"title": "Found a bug", # str
"body": "I'm having a problem with this.", # str
"assignee": None, # username str or None
"milestone": 1, # int
"labels": ['label1']} # list of str
def submit_github_issue(data, token, username, repo):
headers = {'Content-Type':'application/json',
@tbrittoborges
tbrittoborges / fetch_uniprot_gff.py
Last active February 19, 2016 18:32
Load an Uniprot GFF directly to a pandas.DataFrame
from urlparse import parse_qs
import pandas as pd
def _fetch_uniprot_gff(identifier):
"""
Retrieve UniProt data from the GFF file
:param identifier: UniProt accession identifier
:type identifier: str
@tbrittoborges
tbrittoborges / bioinfo_bits.py
Created February 22, 2016 12:02
python interesting bits of bioinformatics
#
import operator
sequence = "ACGACTGATCGATCGATCGATGCATCGATCGACGAT"
random_positions = random.sample(xrange(len(sequence)), 30)
get_positions = operator.itemgetter(*random_positions)
get_positions(sequence)
('T', 'C', 'G', 'C', 'A', 'C', 'C', 'T', 'A', 'T', 'G', 'T', 'A', 'T', 'C', 'C', 'T', 'T', 'A', 'G', 'T', 'A', 'A', 'A', 'C', 'G', 'G', 'C', 'G', 'A')
from itertools import groupby