-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from knights-lab/release-v1.0.7
Release v1.0.7
- Loading branch information
Showing
13 changed files
with
324 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df = pd.read_csv(\"/home/benjamin/code/rep94/idmapping.RefSeq.ko.dat\", sep=\"\\t\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"df" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# usage: python me.py \ | ||
# alignment.burst.otu.txt db.tax sheared_bayes.txt | ||
|
||
import os | ||
import sys | ||
import csv | ||
import pandas as pd | ||
import numpy as np | ||
from scipy.sparse import csr_matrix | ||
|
||
with open(sys.argv[1], 'r') as inf: | ||
csv_inf = csv.reader(inf, delimiter="\t") | ||
columns = next(csv_inf) | ||
columns = dict(zip(columns[1:], range(len(columns)))) | ||
indptr = [0] | ||
indices = np.array([], dtype=int) | ||
data = np.array([], dtype=int) | ||
names = [] | ||
for ix, row in enumerate(csv_inf): | ||
if ix % 1000 == 0: | ||
print(ix) | ||
names.append(row[0]) | ||
np_row = np.array(row[1:], dtype=int) | ||
temp_indx = [np_row > 0] | ||
data = np.concatenate((data, np_row[temp_indx])) | ||
indices = np.concatenate((indices, np.where(temp_indx)[1])) | ||
indptr.append(indices.shape[0]) | ||
|
||
csr = csr_matrix((data, indices, indptr), dtype=int).T | ||
|
||
with open(sys.argv[2]) as inf: | ||
csv_inf = csv.reader(inf, delimiter='\t') | ||
name2taxonomy = dict(csv_inf) | ||
|
||
cols_tax = [name2taxonomy[name] for name in names] | ||
rows_tax = [name2taxonomy[_.replace(".", "_", 1)] for _ in sorted(columns, key=columns.get)] | ||
|
||
def index_lca(str1, str2): | ||
for i, (s1, s2) in enumerate(zip(str1.split(';'), str2.split(';'))): | ||
if s1 != s2: | ||
return i | ||
return 8 | ||
|
||
dat = np.zeros((len(rows_tax), 9), dtype=int) | ||
for i, row_name in enumerate(rows_tax): | ||
row = csr.getrow(i) | ||
for j, indx in enumerate(row.indices): | ||
dat[i, index_lca(rows_tax[i], cols_tax[indx])] += row.data[j] | ||
|
||
print(str(dat[:, 0].sum())) | ||
|
||
df = pd.DataFrame(dat, index=rows_tax) | ||
df['sum'] = dat.sum(axis=1) | ||
df.drop(0, axis=1, inplace=True) | ||
df.to_csv(sys.argv[3], header=False, sep='\t') | ||
|
||
uniqueness_rate_per_level = np.zeros(8, dtype=float) | ||
for i in range(0, 8): | ||
# Take the sum of those columns | ||
num_hits = df.iloc[:, i].sum() | ||
# Total number of possible hits | ||
total_hits = df['sum'].sum() | ||
# Uniqueness Rate | ||
uniqueness_rate_per_level[i] = num_hits/total_hits | ||
levels = ['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species', 'strain'] | ||
list(zip(levels, uniqueness_rate_per_level)) | ||
print(uniqueness_rate_per_level.sum()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
https://s3.us-east-2.amazonaws.com/shogun-db/metadata.yaml | ||
https://s3.us-east-2.amazonaws.com/shogun-db/rep82.fna | ||
https://s3.us-east-2.amazonaws.com/shogun-db/rep82.tax | ||
https://s3.us-east-2.amazonaws.com/shogun-db/sheared_bayes.txt | ||
https://s3.us-east-2.amazonaws.com/shogun-db/utree/rep82.gg.ctr | ||
https://s3.us-east-2.amazonaws.com/shogun-db/utree/rep82.gg.log | ||
https://s3.us-east-2.amazonaws.com/shogun-db/function/ko-enzyme-annotations.txt | ||
https://s3.us-east-2.amazonaws.com/shogun-db/function/ko-module-annotations.txt | ||
https://s3.us-east-2.amazonaws.com/shogun-db/function/ko-pathway-annotations.txt | ||
https://s3.us-east-2.amazonaws.com/shogun-db/function/ko-species2ko.80pct.txt | ||
https://s3.us-east-2.amazonaws.com/shogun-db/function/ko-species2ko.txt | ||
https://s3.us-east-2.amazonaws.com/shogun-db/function/ko-strain2ko.txt | ||
https://s3.us-east-2.amazonaws.com/shogun-db/filter/humanD252.edx | ||
https://s3.us-east-2.amazonaws.com/shogun-db/filter/humanD252.acx | ||
https://s3.us-east-2.amazonaws.com/shogun-db/burst/rep82.edx | ||
https://s3.us-east-2.amazonaws.com/shogun-db/burst/rep82.acx | ||
https://s3.us-east-2.amazonaws.com/shogun-db/bt2/rep82.1.bt2l | ||
https://s3.us-east-2.amazonaws.com/shogun-db/bt2/rep82.2.bt2l | ||
https://s3.us-east-2.amazonaws.com/shogun-db/bt2/rep82.3.bt2l | ||
https://s3.us-east-2.amazonaws.com/shogun-db/bt2/rep82.4.bt2l | ||
https://s3.us-east-2.amazonaws.com/shogun-db/bt2/rep82.rev.1.bt2l | ||
https://s3.us-east-2.amazonaws.com/shogun-db/bt2/rep82.rev.2.bt2l |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# usage: taxmap gene.py | ||
|
||
import sys | ||
import csv | ||
import re | ||
|
||
RefSeq2Uniprot = dict() | ||
Uniprot2KO = dict() | ||
|
||
with open(sys.argv[1], 'r') as inf: | ||
csv_inf = csv.reader(inf, delimiter="\t") | ||
for i, row in enumerate(csv_inf): | ||
if row[1] == "RefSeq": | ||
RefSeq2Uniprot[row[2]] = row[0] | ||
elif row[1] == "KO": | ||
Uniprot2KO[row[0]] = row[2] | ||
|
||
with open(sys.argv[2], 'r') as inf: | ||
for line in inf: | ||
title_search = re.search('\[protein_id=(.*?)\]', line, re.IGNORECASE) | ||
output_str = line[1:] + "\t" | ||
if title_search: | ||
title = title_search.group(1) | ||
|
||
if title in RefSeq2Uniprot: | ||
uniprot_id = RefSeq2Uniprot[title] | ||
if uniprot_id in Uniprot2KO: | ||
ko_id = Uniprot2KO[uniprot_id] | ||
output_str += ko_id | ||
print(output_str) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.