Skip to content

Instantly share code, notes, and snippets.

View tbrittoborges's full-sized avatar

Thiago Britto Borges tbrittoborges

View GitHub Profile
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))
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 / pdb_pandas.py
Last active March 20, 2024 09:17
guide to read .pdb files with pandas
import pandas as pd
colspecs = [(0, 6), (6, 11), (12, 16), (16, 17), (17, 20), (21, 22), (22, 26),
(26, 27), (30, 38), (38, 46), (46, 54), (54, 60), (60, 66), (76, 78),
(78, 80)]
names = ['ATOM', 'serial', 'name', 'altloc', 'resname', 'chainid', 'resseq',
'icode', 'x', 'y', 'z', 'occupancy', 'tempfactor', 'element', 'charge']
pdb = pd.read_fwf(pdb_path, names=names, colspecs=colspecs)
@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 / 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))
@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