index int64 | repo_name string | branch_name string | path string | content string | import_graph string |
|---|---|---|---|---|---|
44,557 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/lce/lce_table.py | import pandas as pd
from deconstruct_lc import tools_lc
def lce_example():
examples = ['QQQQQQ', 'DDDYDD', 'NNNNRR', 'RERERE', 'PGAPPP', 'LLSSTS',
'AADDFF', 'RQNGGG', 'SPESLL', 'LDELTI', 'GFKAPT']
lces = []
for example in examples:
s_entropy = tools_lc.shannon(example)
lces.append(s_entropy)
df_dict = {'Shannon information entropy': lces, 'Example region': examples}
df = pd.DataFrame(df_dict, columns=['Shannon information entropy', 'Example region'])
return df
def main():
df = lce_example()
print(df)
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,558 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_bc/write_go.py | from datetime import datetime
import os
import pandas as pd
from Bio import SeqIO
from deconstruct_lc import read_config
from deconstruct_lc.data_bc import pull_uni
class WriteGO(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.minlen = config['dataprep'].getint('minlen')
self.maxlen = config['dataprep'].getint('maxlen')
self.fd = os.path.join(data_dp, 'bc_prep')
self.now = datetime.now().strftime("%y%m%d")
self.cb_fp = os.path.join(self.fd, '{}quickgo_bc.xlsx'.format(
self.now))
self.fasta_in = os.path.join(self.fd, 'quickgo_bc.fasta')
self.fasta_len = os.path.join(self.fd, 'quickgo_bc_len.fasta')
self.pids_fp = os.path.join(self.fd, '{}pids.txt'.format(self.now))
# Alternatively spliced proteins must be dealt with separately
self.pids_alt_fp = os.path.join(self.fd, '{}pids_alt.txt'.format(
self.now))
self.alt_fasta = os.path.join(self.fd,
'{}quickgo_bc_alt.fasta'.format(self.now))
def go_to_ss(self):
pid_gene_org = self.create_org_dict()
writer = pd.ExcelWriter(self.cb_fp, engine='xlsxwriter')
fns = ['Cajal_bodies', 'Centrosome', 'Cytoplasmic_Stress_Granule',
'Nuclear_Speckles', 'Nuclear_Stress_Granule', 'Nucleolus',
'P_Body', 'P_granule', 'Paraspeckle', 'PML_Body']
for sheet in fns:
df_dict = {'Protein ID': [], 'Reference': [], 'Source': [], 'Gene ID': [], 'Organism': []}
go_fp = os.path.join(self.fd, '{}.tsv'.format(sheet))
go_df = pd.read_csv(go_fp, sep='\t', comment='!', header=None)
go_ids = set(list(go_df[1]))
for go_id in go_ids: # Take just the first entry info
fgo_df = go_df[go_df[1] == go_id]
if go_id not in pid_gene_org:
go_id = go_id.split('-')[0]
gene = pid_gene_org[go_id][0]
org = pid_gene_org[go_id][1]
pmid = list(fgo_df[4])[0]
source = list(fgo_df[9])[0]
df_dict['Protein ID'].append(go_id)
df_dict['Reference'].append(pmid)
df_dict['Source'].append(source)
df_dict['Gene ID'].append(gene)
df_dict['Organism'].append(org)
df_out = pd.DataFrame(df_dict, columns=['Protein ID', 'Gene ID', 'Organism', 'Reference', 'Source'])
df_out.to_excel(writer, sheet_name=sheet, index=False)
def create_org_dict(self):
pid_gene_org = {}
with open(self.fasta_in, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
rec_id = record.id.split('|')
pid = rec_id[1]
gene_org = rec_id[2]
gene = gene_org.split('_')[0]
org = gene_org.split('_')[1]
pid_gene_org[pid] = (gene, org)
return pid_gene_org
def get_pids_from_cb(self):
fns = self.get_sheets()
all_pids = []
for sheet in fns:
df_in = pd.read_excel(self.cb_fp, sheetname=sheet)
all_pids += list(df_in['Protein ID'])
return set(all_pids)
def get_pids_from_qg(self):
all_pids = []
fns = ['Cajal_bodies', 'Centrosome', 'Cytoplasmic_Stress_Granule',
'Nuclear_Speckles', 'Nuclear_Stress_Granule', 'Nucleolus',
'P_Body', 'P_granule', 'Paraspeckle', 'PML_Body']
for fn in fns:
go_fp = os.path.join(self.fd, '{}.tsv'.format(fn))
go_df = pd.read_csv(go_fp, sep='\t', comment='!', header=None)
go_ids = set(list(go_df[1]))
all_pids += go_ids
return set(all_pids)
def write_pids(self, pids):
with open(self.pids_fp, 'w') as fo, open(self.pids_alt_fp, 'w') as fao:
for pid in pids:
if '-' in pid:
fao.write('{}\n'.format(pid))
else:
fo.write('{}\n'.format(pid))
def read_pids(self, fp):
pids = []
with open(fp, 'r') as fpi:
for line in fpi:
pids.append(line.strip())
return pids
def get_sheets(self):
ex = pd.ExcelFile(self.cb_fp)
sheet_names = ex.sheet_names
return sorted(sheet_names)
def filter_fasta(self):
"""Filter CB fasta for length"""
new_records = []
with open(self.fasta_in, 'r') as cb_in:
for seq_rec in SeqIO.parse(cb_in, 'fasta'):
sequence = str(seq_rec.seq)
prot_len = len(sequence)
if self.minlen <= prot_len <= self.maxlen:
if self.standard_aa(sequence):
new_records.append(seq_rec)
with open(self.fasta_len, 'w') as seq_fo:
SeqIO.write(new_records, seq_fo, 'fasta')
count = 0
with open(self.fasta_len, 'r') as handle:
for _ in SeqIO.parse(handle, 'fasta'):
count += 1
print('There are {} records'.format(count))
def standard_aa(self, sequence):
aas = 'ADKERNTSQYFLIVMCWHGP'
for c in sequence:
if c not in aas:
return False
return True
def main():
lg = WriteGO()
pids = lg.get_pids_from_qg()
lg.write_pids(pids)
alt_pids = lg.read_pids(lg.pids_alt_fp)
pull_uni.write_fasta(alt_pids, lg.alt_fasta)
###########################################################################
# Here the PID list must be manually uploaded to uniprot to get the #
# fasta file and then concatenated with the alt pids #
# Do this before creating the spreadsheet and filtering the fasta file #
###########################################################################
# lg.go_to_ss()
# lg.filter_fasta()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,559 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_pdb/run.py | from deconstruct_lc import read_config
from deconstruct_lc.data_pdb.ssdis_to_fasta import SsDis
from deconstruct_lc.data_pdb.filter_pdb import PdbFasta
from deconstruct_lc.data_pdb.norm_all_to_tsv import FastaTsv
from deconstruct_lc.data_pdb.write_pdb_analysis import PdbAnalysis
class RunPdbPrep(object):
def __init__(self):
self.config = read_config.read_config()
def run_ssdis(self):
"""
Convert ss_dis.txt to three fasta files: disorder, secondary structure,
and sequence
"""
ssd = SsDis(self.config)
ssd.seq_dis_to_fasta()
ssd.ss_to_fasta()
ssd.verify_ss_dis_to_fasta()
def run_filterpdb(self):
"""
Filter pdb by x-ray only, eukaryote only, standard amino acid alphabet,
and then create two files, one including sequences that have missing
residues, and one that does not.
"""
pdb = PdbFasta(self.config)
pdb.create_pdb_miss()
pdb.create_pdb_nomiss()
def run_allnormtsv(self):
"""
Write tsv files that include secondary structure for the norm and all
datasets. The all dataset will be used to create the PDB analysis dataset.
"""
ft = FastaTsv(self.config)
ft.write_tsv()
def run_pdbanalysis(self):
pa = PdbAnalysis(self.config)
pa.write_analysis()
def main():
rr = RunPdbPrep()
rr.run_ssdis()
rr.run_filterpdb()
rr.run_allnormtsv()
rr.run_pdbanalysis()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,560 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/remove_structure/read_pfam.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from deconstruct_lc import read_config
class Pfam(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.pfam_fp = os.path.join(data_dp, 'pfam', 'Pfam-A.regions.uniprot.tsv')
self.sgd_uni_fp = os.path.join(data_dp, 'proteomes', 'yeast_pd.xlsx')
self.puncta = os.path.join(data_dp, 'experiment', 'marcotte_puncta_proteins.xlsx')
self.puncta_map_excel = os.path.join(data_dp, 'experiment', 'puncta_map.xlsx')
self.nopuncta_map = os.path.join(data_dp, 'experiment', 'nopuncta_map.tsv')
self.nopuncta_map_excel = os.path.join(data_dp, 'experiment', 'nopuncta_map.xlsx')
self.pfam_puncta = os.path.join(data_dp, 'experiment', 'puncta_pfam.tsv')
self.pfam_nopuncta = os.path.join(data_dp, 'experiment', 'nopuncta_pfam.tsv')
self.puncta_uni = os.path.join(data_dp, 'experiment', 'puncta_uni.txt')
self.nopuncta_uni = os.path.join(data_dp, 'experiment', 'nopuncta_uni.txt')
def read_file(self):
"""
uniprot_acc
pfamA_acc
seq_start
seq_end
"""
unis = self.get_nopuncta_uni()
sdf = pd.DataFrame()
for i, chunk in enumerate(pd.read_csv(self.pfam_fp, sep='\t', chunksize=100000)):
print(i)
ndf = chunk[chunk['uniprot_acc'].isin(unis)]
ndf = ndf[['uniprot_acc', 'pfamA_acc', 'seq_start', 'seq_end']]
sdf = pd.concat([sdf, ndf])
sdf.to_csv(self.pfam_nopuncta, sep='\t')
def get_puncta_uni(self):
df = pd.read_excel(self.puncta_map, sheetname='puncta_map')
unis = list(df['Uni_ID'])
return unis
def get_nopuncta_uni(self):
df = pd.read_excel(self.nopuncta_map_excel, sheetname='nopuncta_map')
unis = list(df['Uni_ID'])
return unis
def write_nopuncta_map(self):
puncta = pd.read_excel(self.puncta, sheetname='NoPuncta')
no_puncta_orfs = list(puncta['ORF'])
df = pd.read_excel(self.sgd_uni_fp, sep='\t')
df = df[df['ORF'].isin(no_puncta_orfs)]
df.to_csv(self.nopuncta_map, sep='\t')
def write_uni(self):
pdf = pd.read_excel(self.puncta_map_excel, sheetname='puncta_map')
punis = set(list(pdf['Uni_ID']))
with open(self.puncta_uni, 'w') as fo:
for puni in punis:
fo.write(puni+'\n')
npdf = pd.read_excel(self.nopuncta_map_excel, sheetname='nopuncta_map')
npunis = set(list(npdf['Uni_ID']))
with open(self.nopuncta_uni, 'w') as fo:
for npuni in npunis:
fo.write(npuni+'\n')
def main():
p = Pfam()
p.write_uni()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,561 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/rohit/plot_scores.py | import os
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc.display.display_lc import Display
class PlotRohit(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.dp = os.path.join(data_dp, 'FUS')
def read_fasta(self):
ns = NormScore()
files = os.listdir(self.dp)
files = [afile for afile in files if '.fasta' in afile]
seqs = []
sizes = []
for afile in files:
seq = tools_fasta.fasta_to_seq(os.path.join(self.dp, afile))
seqs.append(seq[0])
lc_scores = ns.lc_norm_score(seqs)
for score in lc_scores:
sizes.append(score*.8)
labels = []
for file, score in zip(files, lc_scores):
labels.append(file.split('_')[0] + ' ' + str(score).split('.')[0])
arg, tyr = self.arg_tyr(seqs)
df = pd.DataFrame({'Num_Arg': arg, 'Num_Tyr': tyr, 'group': labels})
p1 = sns.regplot(data=df, x='Num_Tyr', y='Num_Arg', fit_reg=False,
color="skyblue", scatter_kws={"s": sizes})
for line in range(0, df.shape[0]):
p1.text(df.Num_Tyr[line] + 0.2, df.Num_Arg[line], df.group[line],
horizontalalignment='left', size='medium', color='black',
weight='semibold')
#sns.plt.show()
fasta_in = os.path.join(self.dp, 'HNRNPA1_P09651.fasta')
fn_out = os.path.join(self.dp, 'HNRNPA1.html')
dis = Display(fasta_in, fn_out, color=True)
dis.write_body()
#fig, ax = plt.subplots()
#for i, txt in enumerate(labels):
# ax.annotate(txt, (tyr[i], arg[i]))
#ax.scatter(tyr, arg, alpha=0.5, sizes=sizes)
#plt.show()
def arg_tyr(self, seqs):
arg = []
tyr = []
for seq in seqs:
arg.append(seq.count('R'))
tyr.append(seq.count('Y'))
return arg, tyr
def main():
pr = PlotRohit()
pr.read_fasta()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,562 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_stats/write_data_train.py | import configparser
import os
import pandas as pd
from deconstruct_lc import tools_fasta
config = configparser.ConfigParser()
cfg_fp = os.path.join(os.path.join(os.path.dirname(__file__), '..',
'config.cfg'))
config.read_file(open(cfg_fp, 'r'))
class WriteDataTrain(object):
def __init__(self):
self.data_dp = config['filepaths']['data_dp']
self.pdb_dp = os.path.join(self.data_dp, 'pdb_prep')
self.bc_dp = os.path.join(self.data_dp, 'bc_prep')
self.pdb_fpi = os.path.join(self.pdb_dp, 'pdb_train_cd90.fasta')
self.bc_fpi = os.path.join(self.bc_dp, 'bc_train_cd90.fasta')
self.train_fpo = os.path.join(self.data_dp, 'train.tsv')
def train_df(self):
pdb_pids, pdb_seqs = tools_fasta.fasta_to_id_seq(self.pdb_fpi)
pdb_lens = tools_fasta.get_lengths(pdb_seqs)
bc_pids, bc_seqs = tools_fasta.fasta_to_id_seq(self.bc_fpi)
bc_lens = tools_fasta.get_lengths(bc_seqs)
lens = bc_lens + pdb_lens
pids = bc_pids + pdb_pids
seqs = bc_seqs + pdb_seqs
y = [0]*len(bc_pids) + [1]*len(pdb_pids)
df_dict = {'Protein ID': pids, 'Sequence': seqs, 'Length': lens,
'y': y}
cols = ['Protein ID', 'y', 'Sequence', 'Length']
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(self.train_fpo, sep='\t')
def main():
wt = WriteDataTrain()
wt.train_df()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,563 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_stats/comp_in_out.py | import os
import matplotlib.pyplot as plt
import pandas as pd
from Bio.SeqUtils.ProtParam import ProteinAnalysis
from deconstruct_lc import read_config
from deconstruct_lc import tools_lc
class CompStats(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.train_fpi = os.path.join(data_dp, 'train.tsv')
self.k = config['score'].getint('k')
self.lca = config['score'].get('lca')
self.lce = config['score'].getfloat('lce')
def comp_lc(self):
"""What is the composition inside LCE motifs?
Put all LCE motifs into a single string, and do fractions"""
bc_seqs = self.get_seqs(0)
pdb_seqs = self.get_seqs(1)
all_lca_seqs, all_lce_seqs, all_lc_seqs = self.all_lc_seqs(pdb_seqs)
aas = 'SGEQAPDTNKRLHVYFIMCW'
aas_list = [aa for aa in aas]
ind = range(len(aas))
lca_bins = self.get_aa_bins(all_lca_seqs)
lce_bins = self.get_aa_bins(all_lce_seqs)
lc_bins = self.get_aa_bins(all_lc_seqs)
plt.bar(ind, lca_bins, color='darkblue', alpha=0.7, label='LCA')
plt.bar(ind, lce_bins, color='orange', alpha=0.7, label='LCE')
plt.bar(ind, lc_bins, color='black', alpha=0.7, label='LC')
plt.xticks(ind, aas_list)
plt.legend()
plt.xlabel('Amino Acids')
plt.ylabel('Relative Fraction in full dataset')
plt.show()
def get_seqs(self, y):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
df = df[df['y'] == y]
seqs = list(df['Sequence'])
return seqs
def get_aa_bins(self, seq):
aas = 'SGEQAPDTNKRLHVYFIMCW'
pa = ProteinAnalysis(seq)
bc_dict = pa.get_amino_acids_percent()
aa_bins = []
for aa in aas:
aa_bins.append(bc_dict[aa])
return aa_bins
def all_lc_seqs(self, seqs):
all_lca_seqs = ''
all_lce_seqs = ''
all_lc_seqs = ''
for seq in seqs:
lca_seq, lce_seq, lc_seq = self.lc_seqs(seq)
all_lca_seqs += lca_seq
all_lce_seqs += lce_seq
all_lc_seqs += lc_seq
return all_lca_seqs, all_lce_seqs, all_lc_seqs
def lc_seqs(self, seq):
lca, lce, lc = self.get_lc_inds(seq)
lca_seq = ''
lce_seq = ''
lc_seq = ''
for i, aa in enumerate(seq):
if i in lca:
lca_seq += aa
if i in lce:
lce_seq += aa
if i in lc:
lc_seq += aa
return lca_seq, lce_seq, lc_seq
def get_lc_inds(self, seq):
lce_inds = tools_lc.lce_to_indexes(seq, self.k, self.lce)
lca_inds = tools_lc.lca_to_indexes(seq, self.k, self.lca)
lca = lca_inds - lce_inds
lce = lce_inds - lca_inds
lc = lca_inds & lce_inds
return lca, lce, lc
def main():
cs = CompStats()
cs.comp_lc()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,564 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_proteomes/data_proteome_composition.py | from Bio import SeqIO
from Bio.SeqUtils.ProtParam import ProteinAnalysis
from collections import defaultdict
import os
import pandas as pd
from deconstruct_lc import read_config
class LcProteome(object):
"""
For each proteome, record the amino acid composition for that proteome as
a continuous sequence string.
"""
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.seg_dpi = os.path.join(data_dp, 'proteomes', 'euk_seg')
self.fns = os.listdir(self.seg_dpi)
self.fpo = os.path.join(data_dp, 'analysis_proteomes', 'lc_composition.tsv')
def write_all_comps(self):
aa_order = 'SGEQAPDTNKRLHVYFIMCW'
all_perc = defaultdict(list)
for fasta_in in self.fns:
aa_dict = self._one_organism(fasta_in)
for aa in aa_order:
all_perc[aa].append(aa_dict[aa])
cols = ['Filename'] + [aa for aa in aa_order]
all_perc['Filename'] = self.fns
df = pd.DataFrame(all_perc, columns=cols)
df.to_csv(self.fpo, sep='\t')
def _one_organism(self, fasta_in):
all_aa = ''
fasta_in = os.path.join(self.seg_dpi, fasta_in)
with open(fasta_in, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
sequence = str(record.seq)
for aa in sequence:
if aa.islower():
all_aa += aa
analyzed_sequence = ProteinAnalysis(all_aa)
return analyzed_sequence.get_amino_acids_percent()
def main():
lcp = LcProteome()
lcp.write_all_comps()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,565 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/old/experiment/pilot.py | import os
import pandas as pd
from deconstruct_lc import read_config
class Pilot(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.fpi = os.path.join(data_dp, 'experiment', '180614_glucose_starvation_2h.xlsx')
self.fpo = os.path.join(data_dp, 'experiment', 'pilot.tsv')
self.yeast_scores = os.path.join(data_dp, 'scores', 'all_yeast.tsv')
def read_file(self):
df = pd.read_excel(self.fpi, sheetname='Hoja1')
print(df.head())
yeast_df = pd.read_csv(self.yeast_scores, sep='\t', index_col=['ORF'])
yeast_df = yeast_df[['Score']]
yeast_dict = yeast_df.to_dict()
yeast_dict['Score']['S288C'] = 'na'
scores = []
df_orfs = df['ORF']
for orf in df_orfs:
scores.append(yeast_dict['Score'][orf])
df['Score'] = scores
df.to_csv(self.fpo, sep='\t')
def main():
p = Pilot()
p.read_file()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,566 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_pdb/motif_pdb.py | import configparser
import os
from Bio import SeqIO
import random
import matplotlib.pyplot as plt
from scipy.stats.stats import pearsonr
import numpy as np
import pandas as pd
from deconstruct_lc import motif_seq
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
config = configparser.ConfigParser()
cfg_fp = os.path.join(os.path.join(os.path.dirname(__file__), '..',
'config.cfg'))
config.read_file(open(cfg_fp, 'r'))
class MissMotif(object):
"""
Plot 1: LC bins vs. fraction of protein with miss residue and avg
missing residue when present (plot_lc_vs_miss)
Plot 2: LC bins vs. missing residues with fixed length
Plot 3: LC bins vs. LC motif in missing residues (done)
Do missing residues occur more frequently within blobs?
"""
def __init__(self):
self.pdb_dp = os.path.join(config['filepaths']['data_dp'], 'pdb_prep')
self.pdb_an_dp = os.path.join(config['filepaths']['data_dp'],
'pdb_analysis')
self.pdb_an_fp = os.path.join(self.pdb_dp, 'pdb_analysis.tsv')
self.k_lca = 6
self.k_lce = 6
self.alph_lca = 'SGEQAPDTNKR'
self.thresh_lce = 1.6
self.lca_label = '{}_{}'.format(self.k_lca, self.alph_lca)
self.lce_label = '{}_{}'.format(self.k_lce, self.thresh_lce)
self.lc_vs_miss_fp = os.path.join(self.pdb_an_dp, 'lc_vs_miss.tsv')
def plot_mean(self):
mean_mm, std_mm, mean_mp, std_mp = self.mean_data()
x = list(range(len(mean_mm)))
labels = ['0-5', '5-10', '10-15', '15-20', '20-25', '25-30',
'30-35', '35-40', '40-45', '45-50', '50+']
plt.errorbar(x, mean_mm, std_mm, linestyle='None', marker='o',
capsize=3, label='Fraction missing residues in LC motif')
plt.errorbar(x, mean_mp, std_mp, linestyle='None', marker='o',
capsize=3, label='Fraction residues in LC motif')
plt.xticks(x, labels, rotation=45)
plt.xlim([-1, len(x)+1])
#plt.ylim([0, 0.8])
plt.xlabel('LC motifs')
plt.legend(loc=4)
plt.show()
def motif_vs_coverage(self):
df = pd.read_csv(self.pdb_an_fp, sep='\t', index_col=0)
bin = range(100, 1000, 100)
all_motif_percs = []
all_motif_stds = []
x = []
for i in bin:
motif_percs = []
print(i)
ndf = df[(df['Length'] >= i) & (df['Length'] < i + 100)]
for i, row in ndf.iterrows():
seq = row['Sequence']
ind_in = self.get_inds(seq)
motif_percs.append(len(ind_in) / len(seq))
x.append(i)
all_motif_percs.append(np.mean(motif_percs))
all_motif_stds.append(np.std(motif_percs))
print(all_motif_percs)
print(all_motif_stds)
def coverage_random(self):
df = pd.read_csv(self.pdb_an_fp, sep='\t', index_col=0)
bin = range(100, 1000, 100)
all_motif_percs = []
all_motif_stds = []
x = []
for i in bin:
motif_percs = []
print(i)
ndf = df[(df['Length'] >= i) & (df['Length'] < i + 100)]
aseq = list(ndf['Sequence'])
seqs = self.create_random(aseq)
for seq in seqs:
ind_in = self.get_inds(seq)
motif_percs.append(len(ind_in) / len(seq))
x.append(i)
all_motif_percs.append(np.mean(motif_percs))
all_motif_stds.append(np.std(motif_percs))
print(all_motif_percs)
print(all_motif_stds)
def create_random(self, seqs):
nseqs = []
for seq in seqs:
lseq = [a for a in seq]
random.shuffle(lseq)
nseqs.append(''.join(lseq))
return nseqs
def plot_coverage(self):
tmean = [0.23613392480397224, 0.24129299067670479, 0.20363240784003156,
0.21521984605747985, 0.21560380306075025, 0.2126832223655015,
0.20074931437836224, 0.19808298265652774, 0.20585607288722238]
tstd = [0.098707938782962051, 0.093531289182195776,
0.065869324533671433,
0.059857030693938475, 0.055764428149622389, 0.052605567548994127,
0.056823970944672043, 0.0423112359041719, 0.033929398744321125]
x = [100, 200, 300, 400, 500, 600, 700, 800, 900]
plt.xlim([0, 1000])
plt.errorbar(x, tmean, tstd, linestyle='None', marker='o',
capsize=3)
plt.show()
def plot_fix_len(self):
df = pd.read_csv(self.pdb_an_fp, sep='\t', index_col=0)
df = df[(df['Length'] >= 400) & (df['Length'] < 600)]
labels = ['0-5', '5-10', '10-15', '15-20', '20-25', '25-30',
'30-35', '35-40', '40-45', '45-50', '50+']
bins = range(0, 50, 5)
frac_w_miss = []
num_miss = []
std_num_miss = []
for i in bins:
print(i)
ndf = df[(df['LCA+LCE'] >= i) & (df['LCA+LCE'] < i + 5)]
nm_ndf = ndf[ndf['Miss Count'] > 0]
frac_w_miss.append(len(nm_ndf)/len(ndf))
num_miss.append(np.mean(list(nm_ndf['Miss Count'])))
std_num_miss.append(np.std(list(nm_ndf['Miss Count'])))
ndf = df[(df['LCA+LCE'] >= 50)]
nm_ndf = ndf[ndf['Miss Count'] > 0]
frac_w_miss.append(len(nm_ndf) / len(ndf))
num_miss.append(np.mean(list(nm_ndf['Miss Count'])))
std_num_miss.append(np.std(list(nm_ndf['Miss Count'])))
x = list(range(len(frac_w_miss)))
plt.xticks(x, labels, rotation=45)
plt.xlim([-1, len(x)+1])
plt.errorbar(x, num_miss, std_num_miss, linestyle='None', marker='o',
capsize=3, label='Average missing residues')
plt.ylabel('Average Missing Residues')
plt.xlabel('LC motifs')
plt.ylim([0,200])
plt.show()
plt.ylabel('Fraction of proteins with missing residues')
plt.scatter(x, frac_w_miss)
plt.plot(x, frac_w_miss)
plt.show()
def plot_box_whisker(self):
"""I'm not sure if a boxplot is better"""
df = pd.read_csv(self.pdb_an_fp, sep='\t', index_col=0)
bins = range(45, 50, 5)
mm = []
mp = []
for i in bins:
print(i)
ndf = df[(df[self.lca_label] >= i) & (df[self.lca_label] < i+5)]
print(len(ndf))
miss_in_motifs, motif_percs = self.lc_blobs(ndf)
mm.append(miss_in_motifs)
mp.append(motif_percs)
plt.boxplot([mm, mp])
#plt.boxplot(mp)
plt.ylim([-0.1, 1.1])
plt.show()
def read_df(self):
df = pd.read_csv(self.pdb_an_fp, sep='\t', index_col=0)
bins = range(0, 50, 5)
mean_mm = []
std_mm = []
mean_mp = []
std_mp = []
for i in bins:
print(i)
ndf = df[(df['LCA+LCE'] >= i) & (df['LCA+LCE'] < i+5)]
print(len(ndf))
miss_in_motifs, motif_percs = self.lc_blobs(ndf)
mean_mm.append(np.mean(miss_in_motifs))
std_mm.append(np.std(miss_in_motifs))
mean_mp.append(np.mean(motif_percs))
std_mp.append(np.std(motif_percs))
ndf = df[(df['LCA+LCE'] >= 50)]
miss_in_motifs, motif_percs = self.lc_blobs(ndf)
mean_mm.append(np.mean(miss_in_motifs))
std_mm.append(np.std(miss_in_motifs))
mean_mp.append(np.mean(motif_percs))
std_mp.append(np.std(motif_percs))
print(mean_mm)
print(std_mm)
print(mean_mp)
print(std_mp)
plt.errorbar(bins, mean_mm, std_mm, linestyle='None', marker='o')
plt.errorbar(bins, mean_mp, std_mp, linestyle='None', marker='o')
plt.show()
def mean_data(self):
mean_mm = [0.15119716529756219, 0.2758867067395091,
0.33919911651251144,
0.38925749618984801, 0.4596892469792353, 0.45675615911402828,
0.4864237185593116, 0.47843336509996348, 0.47722958598203197,
0.52296341132184865, 0.53371100558725326]
std_mm = [0.267896467804773, 0.31001593805679722,
0.29755128257322389,
0.29214897153214725, 0.29618672624311254, 0.28878338867998538,
0.27766447616029249, 0.26516401342522217, 0.24012679453077757,
0.23249365650538631, 0.23073066874878609]
mean_mp = [0.14288089382642194, 0.19447891989162036,
0.2171816720664799,
0.23594776589707467, 0.25346468713519443, 0.26288893104698952,
0.27484725570710161, 0.27239470296870616, 0.26238778404020702,
0.27150317759143594, 0.26612460664234783]
std_mp = [0.14335880427343892, 0.11564355104930381,
0.099416983023802502,
0.090527165333543019, 0.082859300918348588, 0.083315470100230646,
0.08419892402540298, 0.077321014349445147, 0.074297419859518155,
0.064961335129703535, 0.067440855726631221]
return mean_mm, std_mm, mean_mp, std_mp
def lc_blobs(self, df):
miss_in_motifs = []
motif_percs = []
for i, row in df.iterrows():
miss = row['Missing']
seq = row['Sequence']
ind_miss = set([i for i, c in enumerate(miss) if c == 'X'])
if len(ind_miss) > 0:
ind_in = self.get_inds(seq)
miss_in_motifs.append(len(ind_in & ind_miss) / len(ind_miss))
motif_percs.append(len(ind_in)/len(seq))
return miss_in_motifs, motif_percs
def get_inds(self, seq):
lcas = motif_seq.LcSeq(seq, self.k_lca, self.alph_lca, 'lca')
lces = motif_seq.LcSeq(seq, self.k_lce, self.thresh_lce, 'lce')
lca_in, lca_out = lcas._get_motif_indexes()
lce_in, lce_out = lces._get_motif_indexes()
ind_in = lca_in.union(lce_in)
return ind_in
def main():
mm = MissMotif()
mm.coverage_random()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,567 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/run.py | from deconstruct_lc import read_config
from deconstruct_lc.params import raw_scores
from deconstruct_lc.params import raw_svm
from deconstruct_lc.params import raw_top
from deconstruct_lc.params import write_mb
from deconstruct_lc.params import raw_norm
from deconstruct_lc.params import norm_svm
from deconstruct_lc.params import ran_forest
class RunRaw(object):
def __init__(self):
self.config = read_config.read_config()
def run_raw_scores(self):
"""
Write files with the un-normalized LCA/LCE sums for each possible
LCA and LCE for each value of k
"""
pr = raw_scores.RawScores(self.config)
pr.write_lca()
pr.write_lce()
def run_svm(self):
"""
Write the accuracy as obtained by an SVC on the un-normalized LC sums
"""
rs = raw_svm.RawSvm(self.config)
rs.svm_lca_lce()
def run_rawtop(self):
"""
Write only those k, LCA, LCE combos with an un-normalized accuracy > 0.82
"""
rm = raw_top.RawTop(self.config)
rm.write_top()
def run_writemb(self):
"""
After selecting a representative set of LCA proteins by hand, calculate
the normalization parameters both for the individual LCA/LCE values,
but also in combinations
"""
mb = write_mb.WriteMb(self.config)
mb.write_mb_solo()
mb.write_mb_combos()
def run_rawnorm(self):
"""
Write the normalized scores based on the calculated normalization
parameters, when pearson's correlation coefficient was > 0.7
"""
rn = raw_norm.RawNorm(self.config)
rn.solo_norm()
rn.combo_norm()
def run_normsvm(self):
"""
Run an SVM classifier on the normalized scores for LCA/LCE and combinations
"""
ns = norm_svm.NormSvm(self.config)
ns.oned_svm()
def run_ran_forest(self):
"""
Run random forest with all parameters, and in various combinations
to check for best parameters and upper cap
"""
rf = ran_forest.BestFeatures(self.config)
rf.ran_forest()
def main():
rr = RunRaw()
rr.run_ran_forest()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,568 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/experiment/marcotte_analysis.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import chi2_contingency
from deconstruct_lc import read_config
class MarcotteAnalysis(object):
"""
Chi square analysis for marcotte data against Huh
"""
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.puncta = os.path.join(data_dp, 'experiment', 'marcotte_puncta_scores.tsv')
self.nopuncta = os.path.join(data_dp, 'experiment', 'marcotte_nopuncta_scores.tsv')
def read_files(self):
"""
All marcotte proteins are >= 100 and <= 2000
862/886 meet this condition for Huh proteins
"""
puncta_df = pd.read_csv(self.puncta, sep='\t')
puncta_df = puncta_df[(puncta_df['Length'] >= 100) & (puncta_df['Length'] <= 2000)]
nopuncta_df = pd.read_csv(self.nopuncta, sep='\t')
nopuncta_df = nopuncta_df[(nopuncta_df['Length'] >= 100) & (nopuncta_df['Length'] <= 2000)]
nopuncta_df['LC Score'].hist(bins=30, range=(-60, 250), normed=True)
puncta_df['LC Score'].hist(bins=30, range=(-60, 250), normed=True, alpha=0.5)
plt.show()
nopuncta_df['Length'].hist(bins=30, range=(100, 2000), normed=True)
puncta_df['Length'].hist(bins=30, range=(100, 2000), normed=True, alpha=0.5)
plt.show()
mlt, mm, mgt = self.get_bins(puncta_df)
hlt, hm, hgt = self.get_bins(nopuncta_df)
cont = np.array([[mlt, mm, mgt], [hlt, hm, hgt]])
print(cont)
p = chi2_contingency(cont)[1]
print(p)
def get_bins(self, df):
ndf = df[df['LC Score'] < 0]
lt = len(ndf)
ndf = df[(df['LC Score'] >= 0) & (df['LC Score'] <= 20)]
m = len(ndf)
ndf = df[df['LC Score'] > 20]
gt = len(ndf)
return lt, m, gt
def main():
ma = MarcotteAnalysis()
ma.read_files()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,569 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_pdb/ss_table.py | """Results: Neither the table nor the plots by bin are particularly compelling.
X goes up, but most other things are pretty similar without a lot of movement
Structure is about a 15 point difference"""
import matplotlib.pyplot as plt
from scipy.interpolate import spline
import os
import numpy as np
import pandas as pd
from collections import OrderedDict
from deconstruct_lc import read_config
from deconstruct_lc import motif_seq
from deconstruct_lc import tools_lc
class SsTable(object):
"""Calculate the secondary structure inside and outside of LC motifs"""
def __init__(self):
self.config = read_config.read_config()
self.data_dp = self.config['fps']['data_dp']
self.pdb_dp = os.path.join(self.data_dp, 'pdb_prep')
self.pdb_an_dp = os.path.join(self.data_dp,
'pdb_analysis')
self.an_fpi = os.path.join(self.pdb_dp, 'pdb_analysis.tsv')
self.miss_fp = os.path.join(self.pdb_an_dp, 'miss_in_out.tsv')
self.k = 6
self.lce = 1.6
self.lca = 'SGEQAPDTNKR'
def read_ss(self):
all_ss_in = ''
all_ss_out = ''
df = pd.read_csv(self.an_fpi, sep='\t', index_col=0)
for i, row in df.iterrows():
seq = row['Sequence']
ind_in, ind_out = self.get_inds(seq)
ss = row['Secondary Structure']
miss = row['Missing']
xss = self.add_x(ss, miss)
ss_in, ss_out = self.get_ss(xss, ind_in, ind_out)
all_ss_in += ss_in
all_ss_out += ss_out
all_ss = set(all_ss_in)
ss_in_dict = {}
ss_out_dict = {}
for an_ss in all_ss:
ss_in_dict[an_ss] = (all_ss_in.count(an_ss))/len(all_ss_in)
ss_out_dict[an_ss] = (all_ss_out.count(an_ss))/len(all_ss_out)
print(ss_in_dict)
print(ss_out_dict)
def get_ss(self, ss, ind_in, ind_out):
ss_in = ''
ss_out = ''
for ii in ind_in:
ss_in += ss[ii]
for io in ind_out:
ss_out += ss[io]
return ss_in, ss_out
def add_x(self, ss, miss):
nss = ''
for s, m in zip(ss, miss):
if m == 'X':
nss += m
else:
nss += s
return nss
def get_inds(self, seq):
lcas = motif_seq.LcSeq(seq, self.k, self.lca, 'lca')
lces = motif_seq.LcSeq(seq, self.k, self.lce, 'lce')
lca_in, lca_out = lcas._get_motif_indexes()
lce_in, lce_out = lces._get_motif_indexes()
ind_in = lca_in.union(lce_in)
ind_out = lca_out.union(lce_out)
return ind_in, ind_out
class PlotSs(object):
"""For each bin, take the in/out regions as whole sequences and then
calculate the fraction"""
def __init__(self):
self.config = read_config.read_config()
self.data_dp = self.config['fps']['data_dp']
self.pdb_dp = os.path.join(self.data_dp, 'pdb_prep')
self.pdb_an_dp = os.path.join(self.data_dp,
'pdb_analysis')
self.an_fpi = os.path.join(self.pdb_dp, 'pdb_analysis.tsv')
self.ss_out_fp = os.path.join(self.pdb_an_dp, 'ss_out.tsv')
self.ss_in_fp = os.path.join(self.pdb_an_dp, 'ss_in.tsv')
self.ss_one_in_fp = os.path.join(self.pdb_an_dp, 'ss_one_in.tsv')
self.ss_one_out_fp = os.path.join(self.pdb_an_dp, 'ss_one_out.tsv')
self.k = 6
self.lce = 1.6
self.lca = 'SGEQAPDTNKR'
def one_bar_plot(self):
"""Plot the average of all, but also mention that the bars go down by bins"""
df_out = pd.read_csv(self.ss_one_out_fp, sep='\t', index_col=0)
df_in = pd.read_csv(self.ss_one_in_fp, sep='\t', index_col=0)
x1 = [0]
x2 = [0.3]
h = [0.2]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_yticks([0.1, 0.4])
self.data_one_bar(df_out, x1, 1, h)
plt.legend(fontsize=12)
self.data_one_bar(df_in, x2, 1, h)
labels = ['Outside Motifs', 'Inside Motifs']
ax.set_yticklabels(labels, size=12)
plt.ylim([0, 1])
plt.xlim([0, 1.0])
plt.xlabel('Fraction Secondary Structure')
plt.tight_layout()
plt.show()
def data_one_bar(self, df, x, a, w):
missing = []
noss = []
turns = []
struct = []
for i, row in df.iterrows():
# each row is a bin
missing.append(row['X'])
noss.append(row['P'])
turns.append((row['S'] + row['T']))
struct.append((row['E'] + row['H'] + row['B'] + row['G'] + row['I']))
bot1 = (np.array(turns) + np.array(struct) + np.array(noss))[0]
bot2 = (np.array(turns) + np.array(struct))[0]
plt.barh(x, missing, color='white', left=bot1, height=w, alpha=a, label='Missing')
plt.barh(x, noss, color='darkgrey', left=bot2, height=w, alpha=a, label='Coils')
plt.barh(x, turns, color='grey', left=struct, height=w, alpha=a, label='Turns and Bends')
plt.barh(x, struct, color='black', height=w, alpha=a, label='Alpha Helix and Beta Sheet')
def bar_plot(self):
df_out = pd.read_csv(self.ss_out_fp, sep='\t', index_col=0)
df_in = pd.read_csv(self.ss_in_fp, sep='\t', index_col=0)
fig = plt.figure()
ax = fig.add_subplot(111)
x = list(range(0, 10))
x2 = [i+0.45 for i in x]
self.abar(df_in, x2, 1)
ax.legend()
#ax.legend(bbox_to_anchor=(1, 1.2))
self.abar(df_out, x, 1)
labels = ['0-5', '5-10', '10-15', '15-20', '20-25', '25-30',
'30-35', '35-40', '40-45', '45-50', '50+']
ax.set_xticks(x)
ax.set_xticklabels(labels, rotation=45, size=12)
#plt.tight_layout()
plt.ylim([0, 1.5])
plt.xlim([-1, len(x)+1])
plt.show()
def abar(self, df, x, a):
missing = []
noss = []
turns = []
struct = []
for i, row in df.iterrows():
# each row is a bin
missing.append(row['X'])
noss.append(row['P'])
turns.append((row['S'] + row['T']))
struct.append((row['E'] + row['H'] + row['B'] + row['G'] + row['I']))
plt.bar(x, struct, color='black', width=0.4, alpha=a, label='Alpha Helix and Beta Sheet')
plt.bar(x, turns, color='grey', bottom=struct, width=0.4, alpha=a, label='Turns and Bends')
plt.bar(x, noss, color='darkgrey', bottom=np.array(turns)+np.array(struct), width=0.4, alpha=a, label='Coils')
plt.bar(x, missing, color='darkred', bottom=np.array(turns)+np.array(struct)+np.array(noss), width=0.4, alpha=a, label='Missing')
plt.ylim([0, 1.1])
def read_plot(self):
df = pd.read_csv(self.ss_out_fp, sep='\t', index_col=0)
all_ss = ['P', 'X', 'T', 'S', 'H', 'E', 'B', 'G', 'I']
ss_in_dict = {}
x = list(range(0, 10))
for ss in all_ss:
ss_in_dict[ss] = list(df[ss])
print(len(ss_in_dict[ss]))
xnew = np.linspace(0, 10, 300)
power_smooth = spline(x, ss_in_dict[ss], xnew)
plt.plot(xnew, power_smooth, label=ss)
# plt.plot(ss_out_dict[ss], linestyle='--')
plt.ylim([0, 0.35])
plt.legend()
plt.show()
def one_bin(self):
df = pd.read_csv(self.an_fpi, sep='\t', index_col=0)
ss_in_dict = {'P': [], 'X': [], 'T': [], 'S': [], 'H': [], 'E': [],
'B': [], 'G': [], 'I': []}
ss_out_dict = {'P': [], 'X': [], 'T': [], 'S': [], 'H': [], 'E': [],
'B': [], 'G': [], 'I': []}
self.read_ss(df, ss_in_dict, ss_out_dict)
print(ss_in_dict)
print(ss_out_dict)
df_ssin = pd.DataFrame(ss_in_dict)
df_ssout = pd.DataFrame(ss_out_dict)
df_ssin.to_csv(self.ss_one_in_fp, sep='\t')
df_ssout.to_csv(self.ss_one_out_fp, sep='\t')
def get_bins(self):
df = pd.read_csv(self.an_fpi, sep='\t', index_col=0)
bins = range(0, 50, 5)
ss_in_dict = {'P': [], 'X': [], 'T': [], 'S': [], 'H': [], 'E': [],
'B': [], 'G': [], 'I': []}
ss_out_dict = {'P': [], 'X': [], 'T': [], 'S': [], 'H': [], 'E': [],
'B': [], 'G': [], 'I': []}
for i in list(bins):
ndf = df[(df['LC Raw'] >= i) & (df['LC Raw'] < i + 5)]
self.read_ss(ndf, ss_in_dict, ss_out_dict)
print(ss_in_dict)
print(ss_out_dict)
df_ssin = pd.DataFrame(ss_in_dict)
df_ssout = pd.DataFrame(ss_out_dict)
df_ssin.to_csv(self.ss_in_fp, sep='\t')
df_ssout.to_csv(self.ss_out_fp, sep='\t')
def read_ss(self, df, ss_in_dict, ss_out_dict):
all_ss_in = ''
all_ss_out = ''
for i, row in df.iterrows():
seq = row['Sequence']
ind_in, ind_out = self.get_inds(seq)
ss = row['Secondary Structure']
miss = row['Missing']
xss = self.add_x(ss, miss)
ss_in, ss_out = self.get_ss(xss, ind_in, ind_out)
all_ss_in += ss_in
all_ss_out += ss_out
all_ss = ['P', 'X', 'T', 'S', 'H', 'E', 'B', 'G', 'I']
for an_ss in all_ss:
ss_in_dict[an_ss].append((all_ss_in.count(an_ss))/len(all_ss_in))
ss_out_dict[an_ss].append((all_ss_out.count(an_ss))/len(all_ss_out))
def get_ss(self, ss, ind_in, ind_out):
ss_in = ''
ss_out = ''
for ii in ind_in:
ss_in += ss[ii]
for io in ind_out:
ss_out += ss[io]
return ss_in, ss_out
def add_x(self, ss, miss):
nss = ''
for s, m in zip(ss, miss):
if m == 'X':
nss += m
else:
nss += s
return nss
def get_inds(self, seq):
lcas = motif_seq.LcSeq(seq, self.k, self.lca, 'lca')
lces = motif_seq.LcSeq(seq, self.k, self.lce, 'lce')
lca_in, lca_out = lcas._get_motif_indexes()
lce_in, lce_out = lces._get_motif_indexes()
ind_in = lca_in.union(lce_in)
ind_out = lca_out.union(lce_out)
return ind_in, ind_out
class SsComp(object):
"""If it is both in motif and S/T/P/X - what do the motifs look like?"""
def __init__(self):
self.config = read_config.read_config()
self.data_dp = self.config['fps']['data_dp']
self.pdb_dp = os.path.join(self.data_dp, 'pdb_prep')
self.pdb_an_dp = os.path.join(self.data_dp,
'pdb_analysis')
self.an_fpi = os.path.join(self.pdb_dp, 'pdb_analysis.tsv')
self.ss_out_fp = os.path.join(self.pdb_an_dp, 'ss_out.tsv')
self.ss_in_fp = os.path.join(self.pdb_an_dp, 'ss_in.tsv')
self.ss_one_in_fp = os.path.join(self.pdb_an_dp, 'ss_one_in.tsv')
self.ss_one_out_fp = os.path.join(self.pdb_an_dp, 'ss_one_out.tsv')
self.k = 6
self.lce = 1.6
self.lca = 'SGEQAPDTNKR'
def comp(self):
df = pd.read_csv(self.an_fpi, sep='\t', index_col=0)
all_kmers = {}
for i, row in df.iterrows():
print(i)
seq = row['Sequence']
ss = row['Secondary Structure']
miss = row['Missing']
xss = self.add_x(ss, miss)
seq_kmers = tools_lc.seq_to_kmers(seq, self.k)
ss_kmers = tools_lc.seq_to_kmers(xss, self.k)
for seq_kmer, ss_kmer in zip(seq_kmers, ss_kmers):
if tools_lc.lca_motif(seq_kmer, self.lca) or tools_lc.lce_motif(seq_kmer, self.lce):
if set(ss_kmer) <= {'S', 'T', 'P', 'X'}:
if seq_kmer in all_kmers:
all_kmers[seq_kmer] += 1
else:
all_kmers[seq_kmer] = 1
for item in all_kmers:
if all_kmers[item] > 200:
print(item)
print(all_kmers[item])
def add_x(self, ss, miss):
nss = ''
for s, m in zip(ss, miss):
if m == 'X':
nss += m
else:
nss += s
return nss
def main():
pss = PlotSs()
pss.one_bar_plot()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,570 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/lca_lce/lca_svm_comp.py | from Bio.SeqUtils.ProtParam import ProteinAnalysis
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import localcider
from localcider.sequenceParameters import SequenceParameters
from deconstruct_lc import read_config
from deconstruct_lc import tools_lc
from deconstruct_lc.svm import svms
from deconstruct_lc import motif_seq
class LcaSvmComp(object):
"""
Results: the composition is not enough to tell apart these regions
I have made the observation that certain residues, particularly charged
residues are more highly represented in LCA motifs in BC vs. PDB.
There is a certain number of BC proteins that are below the score lines of
20, and 0. Here are my questions:
Of these proteins, do any have 0 motifs?
For those that have > 0 motifs, can we compare the amino acid composition
within the motifs to the amino acid composition within PDB motifs?
Does that help us classify within this scoring region?
"""
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.fdo = os.path.join(data_dp, 'lca_lce')
self.train_fpi = os.path.join(data_dp, 'train.tsv')
self.k = int(config['score']['k'])
self.lca = str(config['score']['lca'])
self.lce = float(config['score']['lce'])
def in_out_kappa(self):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
df = df[df['y'] == 0]
seqs = list(df['Sequence'])
for seq in seqs:
ms = motif_seq.LcSeq(seq, self.k, self.lca, 'lca')
in_seq, out_seq = ms.seq_in_motif()
SeqOb = SequenceParameters(in_seq)
print(SeqOb.get_kappa())
seqOb = SequenceParameters(out_seq)
print(seqOb.get_kappa())
print('')
def check_one_charge(self):
"""
Result. If you remove K, R, E, your classification accuracy goes to 0.71
Hypothesis: it is the LCAs with K/R/E that matter the most for
classification. So what if we only count LCAs with a charged residue?
"""
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
#df = df[df['y'] == 0]
seqs = list(df['Sequence'])
lca_counts = self.count_lca_charge(seqs)
#plt.hist(lca_counts, bins=20, range=(0, 70))
#plt.ylim([0, 900])
#plt.show()
X = np.array([lca_counts]).T
y = np.array(df['y']).T
clf = svms.linear_svc(X, y)
print(clf.score(X, y))
def count_lca_charge(self, seqs):
lca_counts = []
for seq in seqs:
lca_motifs = 0
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lca_motif(kmer, self.lca):
if not tools_lc.lce_motif(kmer, self.lce):
if ('K' in kmer) and ('R' in kmer) and ('E' in kmer):
lca_motifs += 1
lca_counts.append(lca_motifs)
return lca_counts
def create_feature_vecs(self):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
seqs = list(df['Sequence'])
y = list(df['y'])
self.feat_vec(seqs, y)
def feat_vec(self, seqs, y):
"""
For each sequence, create a feature vector that is # motifs,
and fraction for each amino acid of the LCA
"""
lca_counts, seq_kmers = self.seq_lca(seqs)
df_dict = {'seq_kmer': seq_kmers, 'lca_count': lca_counts, 'y': y}
df = pd.DataFrame(df_dict)
print(len(df))
ndf = df
#ndf = df[(df['lca_count'] > 20) & (df['lca_count'] < 30)]
print(len(ndf[ndf['y'] == 0]))
print(len(ndf[ndf['y'] == 1]))
y = np.array(ndf['y']).T
xs = []
for i, row in ndf.iterrows():
feat_vec = self.one_feat_vec(str(row['seq_kmer']))
#feat_vec = []
#feat_vec.append(int(row['lca_count']))
xs.append(feat_vec)
X = np.array(xs)
clf = svms.normal_rbf(X, y)
print(clf.score(X, y))
def one_feat_vec(self, seq_kmer):
aas = 'KRESQPANDGT'
feat_vec = []
for aa in aas:
if seq_kmer.count(aa) > 0:
feat_vec.append(seq_kmer.count(aa)/len(seq_kmer))
else:
feat_vec.append(0)
return feat_vec
def seq_lca(self, seqs):
seq_kmers = []
lca_counts = []
for seq in seqs:
lca_motifs = 0
kmer_str = ''
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lca_motif(kmer, self.lca):
kmer_str += kmer
lca_motifs += 1
lca_counts.append(lca_motifs)
seq_kmers.append(kmer_str)
return lca_counts, seq_kmers
def main():
ls = LcaSvmComp()
ls.in_out_kappa()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,571 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/kelil/run_display.py | import os
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc.kelil.display_motif import Display
class MotifDisplay(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.bc_fp = os.path.join(data_dp, 'bc_analysis', 'bc_all_score.tsv')
self.red_motif_fp = os.path.join(data_dp, 'kelil', 'rep_motifs_red.tsv')
self.body_dp = os.path.join(data_dp, 'bc_analysis')
self.kelil_dp = os.path.join(data_dp, 'kelil')
self.allbc_out = os.path.join(data_dp, 'kelil', 'bc_all_motifs.tsv')
def by_body(self):
fns = ['Cajal_bodies_score.tsv', 'Centrosome_score.tsv',
'Cytoplasmic_Stress_Granule_score.tsv', 'Nuclear_Speckles_score.tsv',
'Nuclear_Stress_Granule_score.tsv', 'Nucleolus_score.tsv',
'P_Body_score.tsv', 'Paraspeckle_score.tsv',
'PML_Body_score.tsv']
dm = Display(os.path.join(self.kelil_dp, 'Nucleolus_Serine.html'))
for fn in ['Nucleolus_score.tsv']:
print(fn)
df = pd.read_csv(os.path.join(self.body_dp, fn), sep='\t')
df = df[df['Organism'] == 'HUMAN']
pids = list(df['Protein ID'])
seqs = list(df['Sequence'])
dm.write_body(pids, seqs)
def by_score(self):
df = pd.read_csv(self.bc_fp, sep='\t')
df = df[df['Organism'] == 'HUMAN']
low_df = df[df['LC Score'] < 0]
hi_df = df[df['LC Score'] > 20]
low_pids = list(low_df['Protein ID'])
hi_pids = list(hi_df['Protein ID'])
low_seqs = list(low_df['Sequence'])
hi_seqs = list(hi_df['Sequence'])
print(len(low_pids))
print(len(hi_pids))
dm = Display(os.path.join(self.kelil_dp, 'HighScore_Serine.html'))
dm.write_body(hi_pids, hi_seqs)
dm = Display(os.path.join(self.kelil_dp, 'LowScore_Serine.html'))
dm.write_body(low_pids, low_seqs)
def score_fun(self):
pass
def main():
md = MotifDisplay()
md.by_score()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,572 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_pdb/ssdis_to_fasta.py | from Bio import SeqIO
from Bio.Alphabet import IUPAC
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
import os
from deconstruct_lc import tools_fasta
class SsDis(object):
def __init__(self, config):
data_dp = config['fps']['data_dp']
pdb_dp = os.path.join(data_dp, 'data_pdb')
self.ss_dis_fp = os.path.join(pdb_dp, 'outside_data', 'ss_dis.txt')
self.all_dis_fp = os.path.join(pdb_dp, 'all_dis.fasta')
self.all_seq_fp = os.path.join(pdb_dp, 'all_seqs.fasta')
self.all_ss_fp = os.path.join(pdb_dp, 'all_ss.fasta')
def seq_dis_to_fasta(self):
"""
Read ss_dis.txt and create fasta files for sequence and disorder.
"""
sequence = []
disorder = []
with open(self.ss_dis_fp, 'r') as handle:
for record in SeqIO.parse(handle, 'fasta'):
rid = str(record.id)
if 'disorder' in rid:
disorder.append(record)
elif 'sequence' in rid:
sequence.append(record)
else:
pass
with open(self.all_seq_fp, 'w') as output_sequence:
SeqIO.write(sequence, output_sequence, 'fasta')
with open(self.all_dis_fp, 'w') as output_disorder:
SeqIO.write(disorder, output_disorder, 'fasta')
print("Done writing disorder and sequence files")
def ss_to_fasta(self):
"""
Read ss_dis.text. For the secondary structure file, add 'P' where
there is a blank
"""
ss_fp = self.ss_dis_fp
ss_fpo = self.all_ss_fp
new_fasta = []
with open(ss_fp, 'r') as ss_fi:
for line in ss_fi:
if 'secstr' in line:
nid = line[1:].strip()
line = next(ss_fi)
nseq = ''
while line[0] != '>':
nseq += line[:-1]
line = next(ss_fi)
new_seq = self._add_p(nseq)
new_record = SeqRecord(Seq(new_seq, IUPAC.protein), id=nid,
description='')
new_fasta.append(new_record)
with open(ss_fpo, 'w') as output_handle:
SeqIO.write(new_fasta, output_handle, 'fasta')
print("Done writing secondary structure")
def _add_p(self, sequence):
new_seq = ''
for aa in sequence:
if aa == ' ':
new_seq += 'P'
else:
new_seq += aa
return new_seq
def verify_ss_dis_to_fasta(self):
"""
Confirm that protein IDs and sequence lengths are the same
"""
total_entries = 0
with open(self.all_seq_fp, 'r') as seq_fasta:
with open(self.all_dis_fp, 'r') as dis_fasta:
with open(self.all_ss_fp, 'r') as ss_fasta:
for seq_rec, dis_rec, ss_rec in \
zip(SeqIO.parse(seq_fasta, 'fasta'),
SeqIO.parse(dis_fasta, 'fasta'),
SeqIO.parse(ss_fasta, 'fasta')):
seq_id = tools_fasta.id_cleanup(seq_rec.id)
dis_id = tools_fasta.id_cleanup(dis_rec.id)
ss_id = tools_fasta.id_cleanup(ss_rec.id)
assert seq_id == dis_id == ss_id
assert len(seq_rec.seq) == len(dis_rec.seq) == len(
ss_rec.seq)
total_entries += 1
print("ss_dis fasta files verified.")
print("There are {} total entries from ss_dis.txt".format(total_entries)) | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,573 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_bc/score_profile.py | import os
import pandas as pd
from Bio import SeqIO
from deconstruct_lc import read_config
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc.analysis_bc.write_bc_score import BcScore
from deconstruct_lc import tools_fasta
class ScoreProfile(object):
def __init__(self):
self.config = read_config.read_config()
self.data_dp = self.config['fps']['data_dp']
self.bc_dp = os.path.join(self.data_dp, 'bc_prep')
self.bc_an_dp = os.path.join(self.data_dp, 'bc_analysis')
# Use fasta file with all bc sequences
self.fasta = os.path.join(self.bc_dp, 'quickgo_bc.fasta')
self.bc_ss = os.path.join(self.bc_dp, 'quickgo_bc.xlsx')
self.bc_score_fp = os.path.join(self.bc_an_dp, 'bc_all_score.tsv')
def open_files(self):
bc = BcScore()
bc_names = bc.get_sheets()
for name in bc_names:
fn = os.path.join(self.bc_an_dp, '{}_score.tsv'.format(name))
df_in = pd.read_csv(fn, sep='\t', index_col=0)
ndf = df_in[df_in['Organism'] == 'YEAST']
if len(ndf) > 0:
print(len(ndf))
print(name)
sdf = ndf[ndf['LC Score'] < 0]
print(len(sdf)/len(ndf))
sdf = ndf[(ndf['LC Score'] >= 0) & (ndf['LC Score'] < 20)]
print(len(sdf) / len(ndf))
sdf = ndf[(ndf['LC Score'] >= 20)]
print(len(sdf) / len(ndf))
def main():
sp = ScoreProfile()
sp.open_files()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,574 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/old/experiment/sandbox.py | """
Look at some specific examples of proteins
"""
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
def main():
"""420-552"""
k = 6
lce = 1.6
lca = 'SGEQAPDTNKR'
seq = tools_fasta.fasta_to_seq('../laf1.fasta')[0]
print(seq)
disp = tools_lc.display_lc(seq, k, lca, lce)
print(disp)
print('')
#seq = seq[0:420] + 'X'*132 + seq[552:]
#print(seq)
#disp = tools_lc.display_lc(seq, k, lca, lce)
#print(disp)
lc_count = tools_lc.count_lc_motifs(seq, k, lca, lce)
print(lc_count)
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,575 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/old/experiment/marcotte.py | """
Write puncta yes/no, write scores,
make sure all puncta present in set
"""
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import statsmodels.stats.power as smp
from scipy.stats import chi2_contingency
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc.display import display_lc
class Puncta(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.puncta_fp = os.path.join(data_dp, 'experiment', 'marcotte_puncta_proteins.xlsx')
self.allproteins_fp = os.path.join(data_dp, 'experiment', 'marcotte_proteins.xlsx')
self.orf_trans = os.path.join(data_dp, 'proteomes', 'orf_trans.fasta')
def check_puncta(self):
puncta = pd.read_excel(self.puncta_fp, sheetname='ST1')
all = pd.read_excel(self.allproteins_fp, sheetname='Sheet1')
puncta_orf = list(puncta['ORF'])
all_orf = list(all['Gene Systematic Name'])
puncta = []
all = []
for item in puncta_orf:
puncta.append(item[0:7])
for item in all_orf:
all.append(item[0:7])
puncta = set(puncta)
all = set(all)
print(len(puncta-all))
def main():
p = Puncta()
p.check_puncta()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,576 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/read_config.py | import configparser
import os
def read_config():
config = configparser.ConfigParser()
cfg_fp = os.path.join(os.path.join(os.path.dirname(__file__),
'config.cfg'))
config.read_file(open(cfg_fp, 'r'))
return config
def read_test_config():
config = configparser.ConfigParser()
cfg_fp = os.path.join(os.path.join(os.path.dirname(__file__),
'config_test.cfg'))
config.read_file(open(cfg_fp, 'r'))
return config
def main():
pass
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,577 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/scores/plot_proteome_scores.py | import matplotlib.pyplot as plt
import matplotlib.patches as patches
import os
import pandas as pd
from deconstruct_lc import read_config
import numpy as np
class PlotScores(object):
def __init__(self):
self.config = read_config.read_config()
self.data_dp = self.config['fps']['data_dp']
self.fpi = os.path.join(self.data_dp, 'scores', 'pdb_bc_scores.tsv')
def plot_bg(self):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.add_patch(patches.Rectangle((-30, 0), 30, 5, facecolor='grey'))
ax.add_patch(patches.Rectangle((0, 0), 20, 5, facecolor='darkgrey'))
ax.add_patch(patches.Rectangle((20, 0), 100, 5, facecolor='white'))
ax.set_xlim([-30 ,120])
ax.set_ylim([0, 4])
plt.show()
def matplot_box_plots(self):
"""
For doing background:
https://stackoverflow.com/questions/18215276/how-to-fill-rainbow-color-under-a-curve-in-python-matplotlib
"""
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
#df = df[(df['Proteome'] == 'BC') | (df['Proteome'] == 'PDB')]
bc_scores = list(df[df['Proteome'] == 'BC']['LC Score'])
pdb_scores = list(df[df['Proteome'] == 'PDB']['LC Score'])
#data = np.concatenate((bc_scores, pdb_scores), 0)
fig = plt.figure(figsize=(7.5, 3))
ax = fig.add_subplot(111)
#fig.set_facecolor('white')
#ax.grid(False)
ax.add_patch(patches.Rectangle((-30, 0), 30, 6, facecolor='grey'))
ax.add_patch(patches.Rectangle((0, 0), 20, 6, facecolor='darkgrey'))
ax.add_patch(patches.Rectangle((20, 0), 100, 6, facecolor='white'))
ax.set_xlim([-30 ,110])
ax.set_ylim([0, 4])
labs = ['PDB', 'Yeast', 'Yeast Nucleolus', 'Yeast Stress Granule', 'Yeast P Body']
bp = {'color': 'black'}
wp = {'color': 'black', 'linestyle':'-'}
meanprops = dict(marker='o',
markeredgecolor='black',
markerfacecolor='black',
markersize=3)
medianprops = dict(linestyle='-', color='black')
all_scores = self.get_scores()
ax.boxplot(all_scores,
vert=False,
whis=[5, 95],
labels=labs,
widths=0.5,
showmeans=True,
showfliers=False,
boxprops=bp,
whiskerprops=wp,
meanprops=meanprops,
medianprops=medianprops)
#plt.xlim([-30, 120])
plt.xticks(np.arange(-30, 111, 10))
plt.xlabel('LC score')
plt.tick_params(axis='both', left='on', top='on', right='on',
bottom='on', labelleft='off', labeltop='off',
labelright='on', labelbottom='on')
plt.tight_layout()
plt.show()
def get_scores(self):
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
yeast = list(df[df['Proteome'] == 'Yeast']['LC Score'])
yeast_sg = list(df[(df['Proteome'] == 'Cytoplasmic_Stress_Granule') &
(df['Organism'] == 'YEAST')]['LC Score'])
yeast_pb = list(df[(df['Proteome'] == 'P_Body') &
(df['Organism'] == 'YEAST')]['LC Score'])
yeast_nuc = list(df[(df['Proteome'] == 'Nucleolus') &
(df['Organism'] == 'YEAST')]['LC Score'])
pdb = list(df[df['Proteome'] == 'PDB']['LC Score'])
return [pdb, yeast, yeast_nuc, yeast_sg, yeast_pb]
def main():
ps = PlotScores()
ps.matplot_box_plots()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,578 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/old/puncta/puncta_scores.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import statsmodels.stats.power as smp
from scipy.stats import chi2_contingency
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc.display import display_lc
class PunctaScores(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.puncta_fp = os.path.join(data_dp, 'puncta', 'marcotte', 'puncta_proteins.xlsx')
self.orf_trans = os.path.join(data_dp, 'proteomes', 'orf_trans.fasta')
self.agg_fp = os.path.join(data_dp, 'puncta', 'oconnel_agg_list')
def agg_vs_puncta(self):
ns = NormScore()
labels = ['Foci (180)', 'Aggregates (117)', 'Foci-Aggregates (158)',
'Aggregates-Foci (95)', 'Aggregates&Foci (22)']
agg_orfs = set(self.read_agg())
puncta_orfs = set(self.get_ids('ST1'))
agg = ns.lc_norm_score(self.get_seqs(agg_orfs))
puncta = ns.lc_norm_score(self.get_seqs(puncta_orfs))
puncta_agg = ns.lc_norm_score(self.get_seqs(puncta_orfs - agg_orfs))
agg_puncta = ns.lc_norm_score(self.get_seqs(agg_orfs - puncta_orfs))
puncta_and_agg = ns.lc_norm_score(self.get_seqs(puncta_orfs&agg_orfs))
all_scores = [puncta, agg, puncta_agg, agg_puncta, puncta_and_agg]
self.matplot_box_plots(all_scores, labels)
def matplot_box_plots(self, scores, labs):
"""
For doing background:
https://stackoverflow.com/questions/18215276/how-to-fill-rainbow-color-under-a-curve-in-python-matplotlib
"""
fig = plt.figure(figsize=(7.5, 3))
ax = fig.add_subplot(111)
ax.add_patch(patches.Rectangle((-30, 0), 30, 6, facecolor='grey'))
ax.add_patch(patches.Rectangle((0, 0), 20, 6, facecolor='darkgrey'))
ax.add_patch(patches.Rectangle((20, 0), 100, 6, facecolor='white'))
ax.set_xlim([-30 ,110])
ax.set_ylim([0, 4])
bp = {'color': 'black'}
wp = {'color': 'black', 'linestyle':'-'}
meanprops = dict(marker='o',
markeredgecolor='black',
markerfacecolor='black',
markersize=3)
medianprops = dict(linestyle='-', color='black')
ax.boxplot(scores,
vert=False,
whis=[5, 95],
widths=0.5,
labels=labs,
showmeans=True,
showfliers=False,
boxprops=bp,
whiskerprops=wp,
meanprops=meanprops,
medianprops=medianprops)
plt.xticks(np.arange(-30, 111, 10))
plt.xlabel('LC score')
plt.tick_params(axis='both', left='on', top='on', right='on',
bottom='on', labelleft='off', labeltop='off',
labelright='on', labelbottom='on')
plt.tight_layout()
plt.show()
def read_agg(self):
orfs = []
with open(self.agg_fp, 'r') as fi:
for line in fi:
orf = line.strip()
orfs.append(orf)
return orfs
def run_plot(self):
#st3_scores = self.insol_remove_puncta()
st1_scores = self.get_scores('ST1')
st2_scores = self.get_scores('ST2')
st3_scores = self.get_scores('ST3')
all_scores = [st1_scores, st2_scores, st3_scores]
labs = ['ST1 (puncta)', 'ST2 (no puncta)', 'ST3 (insoluble->soluble)']
self.matplot_box_plots(all_scores, labs)
def cont_table_power(self):
rows = 5
cols = 2
df = (rows - 1) * (cols - 1)
nbins = df + 1
alpha = 0.05
power = 0.8
st1_scores = self.get_scores('ST1')
st2_scores = self.get_scores('ST2')
col1 = self.bin_three(st1_scores)
col2 = self.bin_three(st2_scores)
n = sum(col1) + sum(col2)
print(n)
ct = np.array([col1, col2]).T
print(ct)
chi2, p, dof, ex = chi2_contingency(ct, correction=False)
es = np.sqrt(chi2 / n * df) # cramer's v
print(es) # medium effect
sample_size = smp.GofChisquarePower().solve_power(es, n_bins=nbins, alpha=alpha,
power=power)
print(sample_size)
def bin_scores(self, scores):
bins = [0, 0, 0]
for score in scores:
if score <= 0:
bins[0] += 1
elif 20 >= score > 0:
bins[1] += 1
else:
bins[2] += 1
return bins
def bin_two(self, scores):
bins = [0, 0]
for score in scores:
if score <= 0:
bins[0] += 1
else:
bins[1] += 1
return bins
def bin_three(self, scores):
bins = [0, 0, 0, 0, 0]
for score in scores:
if score <= -20:
bins[0] += 1
elif -20 < score <= -10:
bins[1] += 1
elif -10 < score <= 0:
bins[2] += 1
elif 0 < score <= 20:
bins[3] += 1
elif score > 20:
bins[4] += 1
else:
print("Binning Problem")
return bins
def run_display(self):
st1_ids = self.get_ids('ST1')
st2_ids = self.get_ids('ST2')
st3_ids = self.get_ids('ST3')
st1_seqs, st1_genes = tools_fasta.get_yeast_seq_gene_from_ids(self.orf_trans, st1_ids)
st2_seqs, st2_genes = tools_fasta.get_yeast_seq_gene_from_ids(self.orf_trans, st2_ids)
st3_seqs, st2_genes = tools_fasta.get_yeast_seq_gene_from_ids(self.orf_trans, st3_ids)
disp = display_lc.Display(st1_seqs, 'st1.html')
disp.write_body()
disp = display_lc.Display(st2_seqs, 'st2.html')
disp.write_body()
disp = display_lc.Display(st3_seqs, 'st3.html')
disp.write_body()
disp = display_lc.Display(st1_seqs, 'st1_color.html', color=True)
disp.write_body()
disp = display_lc.Display(st2_seqs, 'st2_color.html', color=True)
disp.write_body()
disp = display_lc.Display(st3_seqs, 'st3_color.html', color=True)
disp.write_body()
def insol_remove_puncta(self):
st3_ids = self.get_ids('ST3')
print(len(st3_ids))
st1_ids = self.get_ids('ST1')
no_puncta = set(st3_ids) - set(st1_ids)
print(len(no_puncta))
seqs = self.get_seqs(no_puncta)
ns = NormScore()
scores = ns.lc_norm_score(seqs)
return scores
def get_scores(self, sn):
orf_ids = self.get_ids(sn)
seqs = self.get_seqs(orf_ids)
ns = NormScore()
scores = ns.lc_norm_score(seqs)
return scores
def get_ids(self, sn):
df = pd.read_excel(self.puncta_fp, sheetname=sn)
orf_ids = list(df['ORF'])
return orf_ids
def calc_scores(self, seqs):
ns = NormScore()
scores = ns.lc_norm_score(seqs)
return scores
def get_seqs(self, orf_ids):
seqs = tools_fasta.get_yeast_seq_from_ids(self.orf_trans, orf_ids)
return seqs
def main():
ps = PunctaScores()
ps.agg_vs_puncta()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,579 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_pdb/norm_all_to_tsv.py | from Bio import SeqIO
import os
from deconstruct_lc import tools_fasta
class FastaTsv(object):
def __init__(self, config):
data_dp = config['fps']['data_dp']
pdb_dp = os.path.join(data_dp, 'data_pdb')
self.norm_fpi = os.path.join(pdb_dp, 'pdb_norm_cd100.fasta')
self.all_fpi = os.path.join(pdb_dp, 'pdb_all.fasta')
self.norm_fpo = os.path.join(pdb_dp, 'pdb_norm_cd100.tsv')
self.all_fpo = os.path.join(pdb_dp, 'pdb_all.tsv')
self.all_seq = os.path.join(pdb_dp, 'all_seqs.fasta')
self.all_dis = os.path.join(pdb_dp, 'all_dis.fasta')
self.all_ss = os.path.join(pdb_dp, 'all_ss.fasta')
def write_tsv(self):
self.write_full(self.all_fpi, self.all_fpo)
self.write_full(self.norm_fpi, self.norm_fpo)
def write_full(self, fasta, fpo):
"""
Write sequence, missing, secondary structure if in the list of pids.
"""
all_pids = self.get_pids(fasta)
with open(self.all_seq, 'r') as seq_fi, \
open(self.all_dis, 'r') as dis_fi, \
open(self.all_ss, 'r') as ss_fi:
with open(fpo, 'w') as fo:
fo.write('Protein ID\tSequence\tMissing\tSecondary '
'Structure\n')
for seq_rec, dis_rec, ss_rec in zip(SeqIO.parse(seq_fi, 'fasta'),
SeqIO.parse(dis_fi, 'fasta'),
SeqIO.parse(ss_fi, 'fasta')):
pid = tools_fasta.id_cleanup(seq_rec.id)
if pid in all_pids:
seq = str(seq_rec.seq)
mseq = str(dis_rec.seq)
ss_seq = str(ss_rec.seq)
assert len(seq) == len(mseq) == len(ss_seq)
fo.write('{}\t{}\t{}\t{}\n'.format(pid, seq, mseq,
ss_seq))
def get_pids(self, fasta):
pids, seqs = tools_fasta.fasta_to_id_seq(fasta)
return pids
| {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,580 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/kelil/motif_search.py | import os
import pandas as pd
from deconstruct_lc import read_config
class MotifSearch(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.motif_fp = os.path.join(data_dp, 'kelil', 'REPEATING_MOTIFS.dat')
self.bc_fp = os.path.join(data_dp, 'bc_analysis', 'bc_all_score.tsv')
self.red_motif_fp = os.path.join(data_dp, 'kelil', 'rep_motifs_red.tsv')
self.body_dp = os.path.join(data_dp, 'bc_analysis')
self.kelil_dp = os.path.join(data_dp, 'kelil')
self.allbc_out = os.path.join(data_dp, 'kelil', 'bc_all_motifs.tsv')
def motifs_human(self):
hum_pids = self.read_bc()
df = pd.read_csv(self.red_motif_fp, sep='\t', index_col=0)
df = df[df['PID'].isin(hum_pids)]
df = df['MOT'].value_counts()
df.to_csv(self.allbc_out, sep='\t')
def read_motifs(self):
df = self.get_motif_ids()
df.to_csv(self.red_motif_fp, sep='\t')
def get_motif_ids(self):
df = pd.read_csv(self.motif_fp, sep='\t')
reps = list(df['REP'])
motifs = df['MOT']
pids = []
for i, row in df.iterrows():
rpid = row['PRO']
pid = rpid.split('|')[1]
pids.append(pid)
if i %100 == 0:
print(i)
ndf = pd.DataFrame({'PID': pids, 'REP': reps, 'MOT': motifs})
return ndf
def read_bc(self):
df = pd.read_csv(self.bc_fp, sep='\t')
df = df[df['Organism'] == 'HUMAN']
return list(set(df['Protein ID']))
def by_body(self):
fns = ['Cajal_bodies_score.tsv', 'Centrosome_score.tsv',
'Cytoplasmic_Stress_Granule_score.tsv', 'Nuclear_Speckles_score.tsv',
'Nuclear_Stress_Granule_score.tsv', 'Nucleolus_score.tsv',
'P_Body_score.tsv', 'Paraspeckle_score.tsv',
'PML_Body_score.tsv']
mot_df = pd.read_csv(self.red_motif_fp, sep='\t', index_col=0)
for fn in fns:
print(fn)
df = pd.read_csv(os.path.join(self.body_dp, fn), sep='\t')
df = df[df['Organism'] == 'HUMAN']
hum_pids = df['Protein ID']
nmot_df = mot_df[mot_df['PID'].isin(hum_pids)]
ndf = nmot_df['MOT'].value_counts()
fno = 'motifs_' + fn[:-9] + '.tsv'
fpo = os.path.join(self.kelil_dp, fno)
ndf.to_csv(fpo, sep='\t')
def by_score(self):
df = pd.read_csv(self.bc_fp, sep='\t')
df = df[df['Organism'] == 'HUMAN']
low_df = df[df['LC Score'] < 0]
med_df = df[(df['LC Score'] >= 0) & (df['LC Score'] <= 20)]
hi_df = df[df['LC Score'] > 20]
low_pids = list(low_df['Protein ID'])
med_pids = list(med_df['Protein ID'])
hi_pids = list(hi_df['Protein ID'])
print(len(low_pids))
print(len(med_pids))
print(len(hi_pids))
# low_fp = os.path.join(self.kelil_dp, 'low_score_motifs.tsv')
# med_fp = os.path.join(self.kelil_dp, 'med_score_motifs.tsv')
# hi_fp = os.path.join(self.kelil_dp, 'high_score_motifs.tsv')
#
# mot_df = pd.read_csv(self.red_motif_fp, sep='\t', index_col=0)
#
# low_mot_df = mot_df[mot_df['PID'].isin(low_pids)]
# low_mot_df = low_mot_df['MOT'].value_counts()
# low_mot_df.to_csv(hi_fp, sep='\t')
#
# med_mot_df = mot_df[mot_df['PID'].isin(med_pids)]
# med_mot_df = med_mot_df['MOT'].value_counts()
# med_mot_df.to_csv(med_fp, sep='\t')
#
# hi_mot_df = mot_df[mot_df['PID'].isin(hi_pids)]
# hi_mot_df = hi_mot_df['MOT'].value_counts()
# hi_mot_df.to_csv(low_fp, sep='\t')
def main():
ms = MotifSearch()
ms.by_score()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,581 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/old/experiment/write_yeast.py | import os
import pandas as pd
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
class WriteNorm(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.orf_trans = os.path.join(data_dp, 'proteomes', 'orf_trans.fasta')
self.yeast_scores = os.path.join(data_dp, 'scores', 'all_yeast.tsv')
def write_yeast(self):
pids, genes, seqs, descs = tools_fasta.get_pid_gene_desc_seq(self.orf_trans)
ns = NormScore()
scores = ns.lc_norm_score(seqs)
lengths = [len(seq) for seq in seqs]
df_dict = {'ORF': pids, 'Gene': genes, 'Score': scores, 'Sequence': seqs, 'Length': lengths}
df = pd.DataFrame(df_dict, columns=['ORF', 'Gene', 'Score', 'Sequence', 'Length'])
df.to_csv(self.yeast_scores, sep='\t')
def main():
wn = WriteNorm()
wn.write_yeast()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,582 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_pdb/lc_lens.py | import configparser
import os
from Bio import SeqIO
import random
import matplotlib.pyplot as plt
from scipy.stats.stats import pearsonr
import numpy as np
import pandas as pd
from deconstruct_lc import motif_seq
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
config = configparser.ConfigParser()
cfg_fp = os.path.join(os.path.join(os.path.dirname(__file__), '..',
'config.cfg'))
config.read_file(open(cfg_fp, 'r'))
class LcLens(object):
"""
What is the relationship between the lc score and the longest continuous
length?
"""
def __init__(self):
self.dp = os.path.join(config['filepaths']['data_dp'])
self.pdb_dp = os.path.join(config['filepaths']['data_dp'], 'pdb_prep')
self.pdb_an_dp = os.path.join(config['filepaths']['data_dp'],
'pdb_analysis')
self.pdb_an_fp = os.path.join(self.pdb_dp, 'pdb_analysis.tsv')
self.train_fp = os.path.join(self.dp, 'train.tsv')
self.k_lca = 6
self.k_lce = 6
self.alph_lca = 'SGEQAPDTNKR'
self.thresh_lce = 1.6
self.lca_label = '{}_{}'.format(self.k_lca, self.alph_lca)
self.lce_label = '{}_{}'.format(self.k_lce, self.thresh_lce)
def lens_vs_lc(self):
df = pd.read_csv(self.pdb_an_fp, sep='\t', index_col=0)
ndf = df[(df['LC'] >= 30)]
seqs = ndf['Sequence']
all_lens = []
for seq in seqs:
lens = tools_lc.lc_to_lens(seq, self.k_lca, self.alph_lca,
self.thresh_lce)
if len(lens) > 0:
all_lens.append(max(lens))
print(np.mean(all_lens))
plt.hist(all_lens, bins=50)
plt.show()
def bc_pdb_lens(self):
df = pd.read_csv(self.train_fp, sep='\t', index_col=0)
bc_df = df[df['y'] == 0]
pdb_df = df[df['y'] == 1]
pdb_df = pdb_df[pdb_df['LC'] > 30]
bc_seqs = bc_df['Sequence']
pdb_seqs = pdb_df['Sequence']
all_bc_lens = []
all_pdb_lens = []
for bc_seq in bc_seqs:
bc_lens = tools_lc.lc_to_lens(bc_seq, self.k_lca, self.alph_lca,
self.thresh_lce)
if len(bc_lens) > 0:
all_bc_lens.append(max(bc_lens))
for pdb_seq in pdb_seqs:
pdb_lens = tools_lc.lc_to_lens(pdb_seq, self.k_lca,
self.alph_lca, self.thresh_lce)
if len(pdb_lens) > 0:
all_pdb_lens.append(max(pdb_lens))
#plt.hist(all_bc_lens, bins=50)
plt.hist(all_pdb_lens, bins=50)
plt.show()
def main():
ll = LcLens()
ll.lens_vs_lc()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,583 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/kappa/in_out_kappa.py | from Bio.SeqUtils.ProtParam import ProteinAnalysis
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from deconstruct_lc.kappa import kappa
from deconstruct_lc import read_config
from deconstruct_lc import tools_lc
from deconstruct_lc.svm import svms
from deconstruct_lc import motif_seq
from deconstruct_lc.scores import norm_score
class InOutKappa(object):
"""
Results: the composition is not enough to tell apart these regions
I have made the observation that certain residues, particularly charged
residues are more highly represented in LCA motifs in BC vs. PDB.
There is a certain number of BC proteins that are below the score lines of
20, and 0. Here are my questions:
Of these proteins, do any have 0 motifs?
For those that have > 0 motifs, can we compare the amino acid composition
within the motifs to the amino acid composition within PDB motifs?
Does that help us classify within this scoring region?
"""
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.fdo = os.path.join(data_dp, 'lca_lce')
self.train_fpi = os.path.join(data_dp, 'train.tsv')
self.k = int(config['score']['k'])
self.lca = str(config['score']['lca'])
self.lce = float(config['score']['lce'])
def in_out_kappa(self):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
df = df[df['y'] == 0]
seqs = list(df['Sequence'])
all_deltas = []
net_charges = []
frac_charges = []
for seq in seqs:
ms = motif_seq.LcSeq(seq, self.k, self.lca, 'lca')
in_seq, out_seq = ms.seq_in_motif()
in_kmer, out_kmer = ms.overlapping_kmer_in_motif()
if len(in_kmer) > 20:
ka = kappa.KappaKmers(out_kmer, out_seq)
if ka.FCR() > 0.1:
delta = ka.deltaForm()
net_charges.append(ka.NCPR())
print(out_seq)
print(delta)
all_deltas.append(delta)
frac_charges.append(ka.FCR())
#plt.hist(net_charges)
plt.scatter(net_charges, all_deltas, alpha=0.5, color='grey')
#plt.ylim([0, 0.35])
plt.ylim([0, 0.5])
plt.xlim([-0.8, 0.8])
#plt.xlim([0, 0.4])
plt.xlabel('Net charge per residue', size=14)
plt.ylabel('Charge Asymmetry (Delta)', size=14)
plt.title('Outside LC Motifs')
plt.show()
def normal_charge_properties(self):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
df = df[df['y'] == 0]
seqs = list(df['Sequence'])
all_deltas = []
net_charges = []
frac_charges = []
all_seq_in = ''
for seq in seqs:
ms = motif_seq.LcSeq(seq, self.k, self.lca, 'lca')
in_seq, out_seq = ms.seq_in_motif()
in_kmer, out_kmer = ms.overlapping_kmer_in_motif()
if len(in_kmer) > 20:
ka = kappa.KappaKmers(out_kmer, out_seq)
delta = ka.deltaForm()
if ka.NCPR() > -0.1 and ka.NCPR() < 0.1 :
if delta < 0.1:
ns = norm_score.NormScore()
score = ns.lc_norm_score([seq])[0]
if score > 20:
if ka.FCR() < 0.2:
all_seq_in += in_seq
analysed_seq = ProteinAnalysis(all_seq_in)
aa_perc = analysed_seq.get_amino_acids_percent()
print(aa_perc)
def main():
ls = InOutKappa()
ls.normal_charge_properties()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,584 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/lidice/plot_distances.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
from deconstruct_lc import read_config
class Distance(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.fpi = os.path.join(data_dp, '..', 'lidice', 'distance locus-NE.xlsx')
def read_file(self):
df = pd.read_excel(self.fpi, sheetname='Hoja1')
wt_active = df['WT active']
wt_repressed = df['WT repressed'].dropna()
grsIII = df['grsI,II'].dropna()
self.plot_norm(wt_repressed, 'WT repressed')
self.plot_norm(wt_active, 'WT active')
self.plot_norm(grsIII, 'grsI,II$\Delta$')
plt.xlabel('Distance locus-NE')
plt.ylabel('P(D)')
plt.legend()
plt.show()
def plot_norm(self, data, label):
lnspc = np.linspace(-1.5, 1, len(data))
m, s = stats.norm.fit(data)
print(m)
pdf_g = stats.norm.pdf(lnspc, m, s)
plt.plot(lnspc, pdf_g, label=label, lw=2)
def main():
d = Distance()
d.read_file()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,585 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/old/puncta/eisosome_scores.py | import os
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.display.display_lc import Display
class EisosomeScores(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.orf_trans = os.path.join(data_dp, 'proteomes', 'orf_trans.fasta')
self.eis_ids = os.path.join(data_dp, 'puncta', 'eisosome_annotations.txt')
self.fasta_fp = os.path.join(data_dp, 'puncta', 'eisosome_fasta.fsa')
self.display_fp = os.path.join(data_dp, 'puncta', 'eisosome.html')
def display(self):
ds = Display(self.fasta_fp, self.display_fp, color=True)
ds.write_body()
def write_fasta(self):
df = pd.read_csv(self.eis_ids, sep='\t', header=7)
pids = set(list(df['Gene Systematic Name']))
tools_fasta.yeast_write_fasta_from_ids(self.orf_trans, pids, self.fasta_fp)
def main():
es = EisosomeScores()
es.display()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,586 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/tools_fasta.py | import re
from Bio import SeqIO
def fasta_to_seq(fasta_fp, minlen=0, maxlen=float('inf'), unique=False):
"""
Return a list of sequences from the given fasta file.
if unique = True, this function will only include the first unique
sequence in the file.
"""
sequences = []
with open(fasta_fp, 'r') as file_in:
for record in SeqIO.parse(file_in, 'fasta'):
sequence = str(record.seq)
if minlen <= len(sequence) <= maxlen:
if unique:
if sequence not in sequences:
sequences.append(sequence)
else:
sequences.append(sequence)
return sequences
def fasta_to_id_seq(fasta_fp, minlen=0, maxlen=float('inf'), unique=False):
"""
Return a list of ids and a list of the corresponding sequences from a
fasta file.
if unique = True, this function will only include the first unique
sequence and id in the file.
"""
sequences = []
pids = []
with open(fasta_fp, 'r') as file_in:
for record in SeqIO.parse(file_in, 'fasta'):
sequence = str(record.seq)
if minlen <= len(sequence) <= maxlen:
pid = id_cleanup(str(record.id))
if unique:
if sequence not in sequences:
pids.append(pid)
sequences.append(sequence)
else:
pids.append(pid)
sequences.append(sequence)
return pids, sequences
def fasta_to_head_seq(fasta_fp, minlen=0, maxlen=float('inf'), unique=False):
sequences = []
headers = []
with open(fasta_fp, 'r') as file_in:
for record in SeqIO.parse(file_in, 'fasta'):
sequence = str(record.seq)
if minlen <= len(sequence) <= maxlen:
desc = str(record.description)
if unique:
if sequence not in sequences:
headers.append(desc)
sequences.append(sequence)
else:
headers.append(desc)
sequences.append(sequence)
return headers, sequences
def id_cleanup(protein_id):
if '|' in protein_id:
nid = protein_id.split('|')[1]
elif ':' in protein_id:
ps = protein_id.split(':')
nid = '{}_{}'.format(ps[0], ps[1])
else:
nid = protein_id
return nid
def get_pid_gene_desc_seq(fasta_fp):
"""This is specific to yeast fasta files"""
pids = []
genes = []
seqs = []
descs = []
with open(fasta_fp, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
full_description = str(record.description)
fd_sp = full_description.split(',')
pid = str(record.id)
gene = fd_sp[0].split(' ')[1]
seq = str(record.seq)
fd_sp_q = full_description.split('"')
desc = fd_sp_q[1]
pids.append(pid)
genes.append(gene)
seqs.append(seq)
descs.append(desc)
return pids, genes, seqs, descs
def get_yeast_seq_from_ids(orf_trans_fp, orf_ids):
sequences = []
npids = []
with open(orf_trans_fp, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
pid = str(record.id)
if pid in orf_ids:
npids.append(pid)
sequences.append(str(record.seq))
return npids, sequences
def get_yeast_seq_gene_from_ids(orf_trans_fp, orf_ids):
sequences = []
genes = []
orfs = []
with open(orf_trans_fp, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
pid = str(record.id)
if pid in orf_ids:
full_description = str(record.description)
fd_sp = full_description.split(',')
gene = fd_sp[0].split(' ')[1]
sequences.append(str(record.seq))
genes.append(gene)
orfs.append(pid)
return sequences, genes, orfs
def get_yeast_desc_from_ids(orf_trans_fp, orf_ids):
sequences = []
genes = []
orfs = []
descriptions = []
with open(orf_trans_fp, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
pid = str(record.id)
if pid in orf_ids:
full_description = str(record.description)
descriptions.append(full_description)
fd_sp = full_description.split(',')
gene = fd_sp[0].split(' ')[1]
sequences.append(str(record.seq))
genes.append(gene)
orfs.append(pid)
return sequences, genes, orfs, descriptions
def get_one_yeast_desc(orf_trans_fp, orf_id):
with open(orf_trans_fp, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
pid = str(record.id)
if pid == orf_id:
seq = record.seq
desc = str(record.description)
return seq, desc
return None
def yeast_write_fasta_from_ids(orf_trans_fp, orf_ids, fasta_out):
records = []
with open(orf_trans_fp, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
pid = str(record.id)
if pid in orf_ids:
records.append(record)
SeqIO.write(records, fasta_out, "fasta")
def get_lengths(seqs):
lengths = [len(seq) for seq in seqs]
return lengths
def remove_all_histags(seqs):
nseqs = []
for seq in seqs:
nseqs.append(remove_histag(seq))
return nseqs
def remove_histag(seq):
"""If H*6 or greater, remove from sequence"""
regex = r'H{6}H*'
#nseq = re.sub(regex, '', seq)
match = re.finditer(regex, seq)
indexes = []
for item in match:
indexes.append(item.start())
indexes.append(item.end())
nseq = seq[:indexes[0]]
for i in range(1,len(indexes)-1, 2):
nseq += seq[indexes[i]:indexes[i+1]]
nseq += seq[indexes[-1]:]
return nseq
| {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,587 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/examples/sup35.py | import os
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.display import display_lc
from deconstruct_lc.scores.norm_score import NormScore
class Sup35(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.sup_fp = os.path.join(data_dp, 'examples', 'S288C_YDR172W_SUP35_protein.fsa')
def format_seq(self):
seq = tools_fasta.fasta_to_seq(self.sup_fp)
disp = display_lc.Display(seq, 'sup35.html')
disp.write_body()
def score_by_section(self):
seq = tools_fasta.fasta_to_seq(self.sup_fp)[0][0:-1]
ns = NormScore()
nm_domain = seq[0:253]
c_domain = seq[253:]
mc_domain = seq[123:]
print(nm_domain)
print(c_domain)
print(mc_domain)
print(ns.lc_norm_score([nm_domain]))
print(ns.lc_norm_score([c_domain]))
print(ns.lc_norm_score([mc_domain]))
def main():
sup = Sup35()
sup.score_by_section()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,588 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_bc/write_bc_score.py | from Bio import SeqIO
import os
import pandas as pd
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
class BcScore(object):
"""Write individual BC files with pid, org, seq, lc score, length"""
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
bc_dp = os.path.join(data_dp, 'data_bc')
self.bc_an_dp = os.path.join(data_dp, 'bc_analysis')
# Use fasta file with all bc sequences
self.fasta = os.path.join(bc_dp, 'quickgo_bc.fasta')
self.bc_ss = os.path.join(bc_dp, 'quickgo_bc.xlsx')
self.bc_score_fp = os.path.join(self.bc_an_dp, 'bc_all_score.tsv')
def compile_bcs(self):
bc_pids = self.create_bc_dict()
df_in = pd.read_csv(self.bc_score_fp, sep='\t', index_col=0)
for bc in bc_pids:
fno = '{}_score.tsv'.format(bc)
fpo = os.path.join(self.bc_an_dp, fno)
pids = bc_pids[bc]
ndf = df_in[df_in['Protein ID'].isin(pids)]
ndf.to_csv(fpo, sep='\t')
def write_all_scores(self):
"""Write ID, length, score from fasta file"""
df_dict = {'Protein ID': [], 'Sequence': [], 'Organism': []}
with open(self.fasta, 'r') as fi:
for record in SeqIO.parse(fi, 'fasta'):
rec_id = record.id.split('|')
pid = rec_id[1]
gene_org = rec_id[2]
org = gene_org.split('_')[1]
seq = str(record.seq)
df_dict['Protein ID'].append(pid)
df_dict['Sequence'].append(seq)
df_dict['Organism'].append(org)
seqs = df_dict['Sequence']
ns = NormScore()
scores = ns.lc_norm_score(seqs)
lengths = tools_fasta.get_lengths(seqs)
df_dict['LC Score'] = scores
df_dict['Length'] = lengths
cols = ['Protein ID', 'Organism', 'Length', 'LC Score', 'Sequence']
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(self.bc_score_fp, sep='\t')
def create_bc_dict(self):
fns = self.get_sheets()
bc_pids = {}
for sheet in fns:
df_in = pd.read_excel(self.bc_ss, sheetname=sheet)
bc_pids[sheet] = list(df_in['Protein ID'])
return bc_pids
def get_sheets(self):
ex = pd.ExcelFile(self.bc_ss)
sheet_names = ex.sheet_names
return sorted(sheet_names)
def main():
bc = BcScore()
bc.write_all_scores()
bc.compile_bcs()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,589 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/kappa/kappa.py | import numpy as np
class KappaKmers(object):
#...................................................................................#
def __init__(self, kmers, seq):
"""
seq = amino acid sequence as a string
"""
self.seq = seq
self.len = len(seq)
self.kmers = kmers
self.kmer_charges = self.kmerChargePattern()
self.chargePattern = self.seqChargePattern()
def seqChargePattern(self):
charges = {'K': 1, 'R': 1, 'D': -1, 'E': -1}
nseq = []
for aa in self.seq:
if aa in charges:
nseq.append(charges[aa])
else:
nseq.append(0)
return np.array(nseq)
def kmerChargePattern(self):
charges = {'K': 1, 'R': 1, 'D': -1, 'E': -1}
kmer_charges = []
for kmer in self.kmers:
nkmer = []
for aa in kmer:
if aa in charges:
nkmer.append(charges[aa])
else:
nkmer.append(0)
kmer_charges.append(nkmer)
return np.array(kmer_charges)
#...................................................................................#
def deltaForm(self):
""" Calculate the delta value as defined in REF 1
"""
bloblen = 6
sigma = self.sigma()
nblobs = len(self.kmer_charges)
ans = 0
for kmer in self.kmer_charges:
# get the blob charge pattern list
blob = kmer
# calculate a bunch of parameters for the blob
# with the blob sigma value being the ultimate
# goal
bpos = np.where(blob > 0)[0].size
bneg = np.where(blob < 0)[0].size
bncpr = (bpos - bneg) / (bloblen + 0.0)
bfcr = (bpos + bneg) / (bloblen + 0.0)
if(bfcr == 0):
bsig = 0
else:
bsig = bncpr**2 / bfcr
# calculate the square deviation of the
# blob sigma from the sequence sigma and
# weight by the number of blobs in the sequence
ans += (sigma - bsig)**2 / nblobs
return ans
#...................................................................................#
def sigma(self):
""" Returns the sigma value for a sequence
\sigma = \dfrac{NCPR^2}{FCR}
When the sequence has one or more charged residues
sigma = (NCPR^2)/FCR
When the sequence has no charged residues
sigma = 0
"""
if(self.countNeut() == self.len):
return 0
else:
return self.NCPR()**2 / self.FCR()
# ...................................................................................#
def FCR(self):
return (self.countPos() + self.countNeg()) / (self.len + 0.0)
# ...................................................................................#
def NCPR(self):
""" Get the net charge per residue of the sequence """
return (self.countPos() - self.countNeg()) / (self.len + 0.0)
#...................................................................................#
def countPos(self):
""" Get the number of positive residues in the sequence """
return len(np.where(self.chargePattern > 0)[0])
#...................................................................................#
def countNeg(self):
""" Get the number of negative residues in the sequence """
return len(np.where(self.chargePattern < 0)[0])
#...................................................................................#
def countNeut(self):
""" Get the number of neutral residues in the sequence """
return len(np.where(self.chargePattern == 0)[0])
def main():
pass
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,590 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/complementarity/complementarity.py | """
The goal here is to see if the blobs that I'm measuring might have some kind
of complementarity.
Ideally, it would be good to check this within a droplet, however, maybe a
good place to start is within the protein.
It wouldn't be too hard to check within a droplet. I could check within
stress granules for instance. I could see which proteins seem to interact
with each other and see if they have complementary blobs.
But maybe first see if I find *anything* within the proteins. I should find
something.
So what would complementarity look like? Well I have a list of complementary amino acids.
I am going to start by looking in the motifs.
Start with charge complementarity within a stretch
"""
import configparser
import os
import pandas as pd
from deconstruct_lc.complementarity import motif_seq
config = configparser.ConfigParser()
cfg_fp = os.path.join(os.path.join(os.path.dirname(__file__), '..',
'config.cfg'))
config.read_file(open(cfg_fp, 'r'))
class Complementarity(object):
def __init__(self, nmo_fpi, lca_label, lce_label):
self.nmo_fpi = nmo_fpi
self.lca_label = lca_label
self.lce_label = lce_label
def check_comp(self):
"""What motifs occur together?"""
nmo_df = pd.read_csv(self.nmo_fpi, sep='\t', index_col=0)
nmo_df = nmo_df[(nmo_df[self.lca_label] > 100)]
nmo_df = nmo_df.sort_values(by=[self.lca_label])
nmo_df = nmo_df.reset_index(drop=True)
for i, row in nmo_df.iterrows():
sequence = row['Sequence']
print(sequence)
print(row['Protein ID'])
ms = motif_seq.LcSeq(sequence, 6, 'SGEQAPDTNKR', 'lca')
motifs = ms.list_motifs()
print(len(motifs))
alphs = self.get_motif_comp(motifs)
print(alphs)
def get_motif_comp(self, motifs):
alphs = {'ST': 0, 'ED': 0, 'RK': 0, 'QN': 0, 'GA': 0, 'P': 0, 'ev': 0}
for motif in motifs:
flag = True
ch = self.get_net_charge(motif)
if ch <= -1:
alphs['ED'] += 1
flag = False
if ch >= 1:
alphs['RK'] += 1
flag = False
if motif.count('P') >= 3:
alphs['P'] += 1
flag = False
if (motif.count('Q') + motif.count('N')) >= 3:
alphs['QN'] += 1
flag = False
if (motif.count('S') + motif.count('T')) >= 3:
alphs['ST'] += 1
flag = False
if (motif.count('G') + motif.count('A')) >= 4:
alphs['GA'] += 1
flag = False
if flag:
alphs['ev'] += 1
return alphs
def get_net_charge(self, motif):
charges = {'E': -1, 'D': -1, 'R': 1, 'K': 1}
charge_total = 0
for aa in motif:
if aa in charges:
charge_total += charges[aa]
return charge_total
class Pipeline(object):
def __init__(self):
self.base_fp = self.fd = os.path.join(config['filepaths'][
'data_fp'], 'scores')
self.nmo_fpi = os.path.join(self.base_fp,
'quickgo_cb_cd90_6_SGEQAPDTNKR_6_1.6_norm.tsv')
self.lca_label = '6_SGEQAPDTNKR'
self.lce_label = '6_1.6'
def run_charge(self):
comp = Complementarity(self.nmo_fpi, self.lca_label, self.lce_label)
comp.check_comp()
def main():
pipe = Pipeline()
pipe.run_charge()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,591 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/chi2/run_chi2.py | import os
import numpy as np
import pandas as pd
from scipy.stats import chi2_contingency
from itertools import combinations
from deconstruct_lc import read_config
from deconstruct_lc.chi2 import create_contingency
def format_cont(row1, row2):
return np.array([list(row1), list(row2)])
def write_bc_vs_bg(bcs, fpo, organism):
adict = {'BC': [], 'pval': []}
for bc in bcs:
bcc = create_contingency.BcProteome(bc, organism)
bc_cont, org_cont = bcc.get_cont_table()
if sum(list(bc_cont)) > 10:
ct = format_cont(bc_cont, org_cont)
pval = chi2_contingency(ct)[1]
adict['BC'].append(bc)
adict['pval'].append(pval)
df_out = pd.DataFrame(adict, columns=['BC', 'pval'])
df_out.to_csv(fpo, sep='\t')
def run_bc_vs_bg():
bcs = ['Nuclear_Stress_Granule', 'Nucleolus', 'P_granule', 'PDB',
'PML_Body', 'P_Body', 'Nuclear_Speckles', 'Cytoplasmic_Stress_Granule',
'Cajal_bodies', 'Paraspeckle', 'Centrosome']
# Compare BC to background
config = read_config.read_config()
data_dp = config['fps']['data_dp']
yeast_fpo = os.path.join(data_dp, 'chi2', 'bc_vs_yeast.tsv')
human_fpo = os.path.join(data_dp, 'chi2', 'bc_vs_human.tsv')
write_bc_vs_bg(bcs, yeast_fpo, 'Yeast')
write_bc_vs_bg(bcs, human_fpo, 'Human')
def write_bc_vs_bc(bcs, fpo, organism):
combs = list(combinations(bcs, 2))
adict = {'BC': [], 'pval': []}
for comb in combs:
bc1 = comb[0]
bc2 = comb[1]
bcc1 = create_contingency.BcProteome(bc1, organism)
bc1_cont, org_cont = bcc1.get_cont_table()
bcc2 = create_contingency.BcProteome(bc2, organism)
bc2_cont, org_cont = bcc2.get_cont_table()
if sum(list(bc1_cont)) > 10 and sum(list(bc2_cont)) > 10:
ct = format_cont(bc1_cont, bc2_cont)
pval = chi2_contingency(ct)[1]
adict['BC'].append(comb)
adict['pval'].append(pval)
df_out = pd.DataFrame(adict, columns=['BC', 'pval'])
df_out.to_csv(fpo, sep='\t')
def run_bc_vs_bc():
bcs = ['Nuclear_Stress_Granule', 'Nucleolus', 'P_granule', 'PDB',
'PML_Body', 'P_Body', 'Nuclear_Speckles', 'Cytoplasmic_Stress_Granule',
'Cajal_bodies', 'Paraspeckle', 'Centrosome']
# Compare BC to each other
config = read_config.read_config()
data_dp = config['fps']['data_dp']
yeast_fpo = os.path.join(data_dp, 'chi2', 'bc_vs_bc_yeast.tsv')
human_fpo = os.path.join(data_dp, 'chi2', 'bc_vs_bc_human.tsv')
write_bc_vs_bc(bcs, yeast_fpo, 'Yeast')
write_bc_vs_bc(bcs, human_fpo, 'Human')
def main():
bcs = ['Nuclear_Stress_Granule', 'Nucleolus', 'P_granule', 'PDB',
'PML_Body', 'P_Body', 'Nuclear_Speckles', 'Cytoplasmic_Stress_Granule',
'Cajal_bodies', 'Paraspeckle', 'Centrosome']
# Compare BC to each other
run_bc_vs_bc()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,592 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/tools_lc.py | """
Created by Shelly DeForte, Michnick Lab, University of Montreal 2018
"""
import math
from deconstruct_lc import tools
# Count motifs for one sequence ###############################################
def count_lc_motifs(sequence, k, lca, lce):
"""Count the number of LCA || LCE motifs of length k in a sequence"""
kmers = seq_to_kmers(sequence, k)
motif_count = 0
for kmer in kmers:
if lca_motif(kmer, lca):
motif_count += 1
elif lce_motif(kmer, lce):
motif_count += 1
else:
pass
return motif_count
def count_lca_motifs(sequence, k, lca):
"""Count the number of LCA motifs of length k in a sequence"""
kmers = seq_to_kmers(sequence, k)
motif_count = 0
for kmer in kmers:
if lca_motif(kmer, lca):
motif_count += 1
return motif_count
def count_lce_motifs(sequence, k, threshold):
"""Count the number of LCE motifs of length k in a sequence"""
kmers = seq_to_kmers(sequence, k)
motif_count = 0
for kmer in kmers:
if lce_motif(kmer, threshold):
motif_count += 1
return motif_count
def count_lca_and_lce(sequence, k, lca, lce):
"""Count the number of LCA & LCE motifs of length k in a sequence"""
kmers = seq_to_kmers(sequence, k)
motif_count = 0
for kmer in kmers:
if lca_motif(kmer, lca):
if lce_motif(kmer, lce):
motif_count += 1
return motif_count
def count_lca_not_lce(sequence, k, lca, lce):
"""Count the number of LCA & ~LCE motifs of length k in a sequence"""
kmers = seq_to_kmers(sequence, k)
motif_count = 0
for kmer in kmers:
if lca_motif(kmer, lca):
if not lce_motif(kmer, lce):
motif_count += 1
return motif_count
def count_not_lca_lce(sequence, k, lca, lce):
"""Count the number of ~LCA & LCE motifs of length k in a sequence"""
kmers = seq_to_kmers(sequence, k)
motif_count = 0
for kmer in kmers:
if not lca_motif(kmer, lca):
if lce_motif(kmer, lce):
motif_count += 1
return motif_count
def count_lc_motifs_nomiss(seq, miss_seq, k, lca, lce):
"""Count LC motifs only if there are no missing residues"""
kmers = seq_to_kmers_nomiss(seq, miss_seq, k)
motif_count = 0
for kmer in kmers:
if lca_motif(kmer, lca):
motif_count += 1
elif lce_motif(kmer, lce):
motif_count += 1
else:
pass
return motif_count
###############################################################################
def seq_to_kmers(sequence, k):
"""Given a sequence, return a list of all overlapping k-mers"""
i = 0
len_sequence = len(sequence)
kmers = []
while i+k <= len_sequence:
kmers.append(sequence[i:i+k])
i += 1
return kmers
def seq_to_kmers_nomiss(seq, miss_seq, k):
"""Only return kmers without a missing residue"""
seq_kmers = seq_to_kmers(seq, k)
miss_kmers = seq_to_kmers(miss_seq, k)
new_kmers = []
for seq_kmer, miss_kmer in zip(seq_kmers, miss_kmers):
if miss_kmer.count('X') == 0:
new_kmers.append(seq_kmer)
return new_kmers
def calc_lc_motifs(sequences, k, lca, lce):
"""Calculate the total number of unique lca or lce motifs
k must be the same"""
motif_counts = []
for sequence in sequences:
motif_count = count_lc_motifs(sequence, k, lca, lce)
motif_counts.append(motif_count)
return motif_counts
def calc_lc_motifs_nomiss(seqs, miss_seqs, k, lca, lce):
motif_counts = []
for seq, miss_seq in zip(seqs, miss_seqs):
motif_count = count_lc_motifs_nomiss(seq, miss_seq, k, lca, lce)
motif_counts.append(motif_count)
return motif_counts
def lc_to_indexes(sequence, k, lca, lce):
kmers = seq_to_kmers(sequence, k)
ind_in = set()
for i, kmer in enumerate(kmers):
if lca_motif(kmer, lca):
for j in range(i, i+k):
ind_in.add(j)
elif lce_motif(kmer, lce):
for j in range(i, i+k):
ind_in.add(j)
else:
pass
return ind_in
def lc_to_lens(sequence, k, lca, lce):
"""Returns a list of the lengths of the LC intervals"""
ind_in = lc_to_indexes(sequence, k, lca, lce)
intervals = tools.ints_to_ranges(sorted(list(ind_in)))
lens = []
for inter in intervals:
lens.append((inter[1]-inter[0])+1)
return lens
def lca_motif(kmer, lca):
"""Checks to see if the sequence contains only those amino acids as
defined in the lca (a string)'"""
in_motif = set(lca)
if set(kmer) <= in_motif:
return True
else:
return False
def lce_motif(kmer, threshold):
"""Checks if the sequence is les than or equal to the threshold in its
shannon entropy score"""
h = shannon(kmer)
if h <= threshold:
return True
else:
return False
def shannon(astring):
"""Calculates shannon entropy for any string with log base 2"""
entropy = 0
len_str = float(len(astring))
unique = set(astring)
for c in unique:
p_x = float(astring.count(c))/len_str
entropy += p_x*math.log(p_x, 2)
if not entropy == 0.0:
entropy = -(entropy)
return entropy
def lca_to_indexes(sequence, k, lca):
kmers = seq_to_kmers(sequence, k)
indexes = set()
for i, kmer in enumerate(kmers):
if lca_motif(kmer, lca):
for j in range(i, i+k):
indexes.add(j)
return indexes
def lce_to_indexes(sequence, k, lce):
kmers = seq_to_kmers(sequence, k)
indexes = set()
for i, kmer in enumerate(kmers):
if lce_motif(kmer, lce):
for j in range(i, i+k):
indexes.add(j)
return indexes
def lca_to_interval(sequence, k, lca):
"""
Returns inclusive interval, where all numbers are in the motif, ie (0, 6)
and not (0, 7)
"""
kmers = seq_to_kmers(sequence, k)
indexes = set()
for i, kmer in enumerate(kmers):
if lca_motif(kmer, lca):
for j in range(i, i+k):
indexes.add(j)
intervals = tools.ints_to_ranges(sorted(list(indexes)))
return intervals
def lce_to_interval(sequence, k, lce):
kmers = seq_to_kmers(sequence, k)
indexes = set()
for i, kmer in enumerate(kmers):
if lce_motif(kmer, lce):
for j in range(i, i+k):
indexes.add(j)
intervals = tools.ints_to_ranges(sorted(list(indexes)))
return intervals
def display_lce(sequence, thresh_lce, k_lce):
"""Given a sequence, mark the motifs with a 'O'"""
kmers_lce = seq_to_kmers(sequence, k_lce)
indexes = set()
for i, kmer in enumerate(kmers_lce):
if lce_motif(kmer, thresh_lce):
for item in range(i, i+k_lce):
indexes.add(item)
new_sequence = ''
for i, let in enumerate(sequence):
if i in indexes:
new_sequence += 'O'
else:
new_sequence += let
return new_sequence
def display_lca(sequence, alph_lca, k_lca):
"""Given a sequence, mark the motifs with a 'O'"""
kmers_lca = seq_to_kmers(sequence, k_lca)
indexes = set()
for i, kmer in enumerate(kmers_lca):
if lca_motif(kmer, alph_lca):
for item in range(i, i+k_lca):
indexes.add(item)
new_sequence = ''
for i, let in enumerate(sequence):
if i in indexes:
new_sequence += 'O'
else:
new_sequence += let
return new_sequence
def display_lc(sequence, k, lca, lce):
inds = lc_to_indexes(sequence, k, lca, lce)
new_sequence = ''
for i, let in enumerate(sequence):
if i in inds:
new_sequence += '-'
else:
new_sequence += let
return new_sequence
def calc_lce_motifs(sequences, k, lce):
"""Given a list of sequences, return a list of motif counts for each
sequence"""
motif_counts = []
for sequence in sequences:
motif_count = count_lce_motifs(sequence, k, lce)
motif_counts.append(motif_count)
return motif_counts
def calc_lca_motifs(sequences, k, lca):
"""Given a list of sequences, return a list of motif counts for each
sequence"""
motif_counts = []
for sequence in sequences:
motif_count = count_lca_motifs(sequence, k, lca)
motif_counts.append(motif_count)
return motif_counts
def main():
pass
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,593 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/experiment/display_marcotte.py | import matplotlib.pyplot as plt
import matplotlib.patches as patches
import os
import pandas as pd
from deconstruct_lc import read_config
import numpy as np
class PlotScores(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.puncta = os.path.join(data_dp, 'experiment', 'marcotte_puncta_scores.tsv')
self.nopuncta = os.path.join(data_dp, 'experiment', 'marcotte_nopuncta_scores.tsv')
def plot_bg(self):
fig = plt.figure()
ax = fig.add_subplot(111)
ax.add_patch(patches.Rectangle((-30, 0), 30, 5, facecolor='grey'))
ax.add_patch(patches.Rectangle((0, 0), 20, 5, facecolor='darkgrey'))
ax.add_patch(patches.Rectangle((20, 0), 100, 5, facecolor='white'))
ax.set_xlim([-30 ,120])
ax.set_ylim([0, 4])
plt.show()
def matplot_box_plots(self):
"""
For doing background:
https://stackoverflow.com/questions/18215276/how-to-fill-rainbow-color-under-a-curve-in-python-matplotlib
"""
puncta_df = pd.read_csv(self.puncta, sep='\t', index_col=0)
nopuncta_df = pd.read_csv(self.nopuncta, sep='\t', index_col=0)
puncta_scores = list(puncta_df['LC Score'])
nopuncta_scores = list(nopuncta_df['LC Score'])
fig = plt.figure(figsize=(7.5, 3))
ax = fig.add_subplot(111)
#fig.set_facecolor('white')
#ax.grid(False)
ax.add_patch(patches.Rectangle((-30, 0), 30, 6, facecolor='grey'))
ax.add_patch(patches.Rectangle((0, 0), 20, 6, facecolor='darkgrey'))
ax.add_patch(patches.Rectangle((20, 0), 100, 6, facecolor='white'))
ax.set_xlim([-30 ,110])
ax.set_ylim([0, 4])
labs = ['Does not Form Puncta', 'Forms Puncta']
bp = {'color': 'black'}
wp = {'color': 'black', 'linestyle':'-'}
meanprops = dict(marker='o',
markeredgecolor='black',
markerfacecolor='black',
markersize=3)
medianprops = dict(linestyle='-', color='black')
all_scores = [nopuncta_scores, puncta_scores]
ax.boxplot(all_scores,
vert=False,
whis=[5, 95],
labels=labs,
widths=0.5,
showmeans=True,
showfliers=False,
boxprops=bp,
whiskerprops=wp,
meanprops=meanprops,
medianprops=medianprops)
#plt.xlim([-30, 120])
plt.xticks(np.arange(-30, 111, 10))
plt.xlabel('LC score')
plt.tick_params(axis='both', left='on', top='on', right='on',
bottom='on', labelleft='off', labeltop='off',
labelright='on', labelbottom='on')
plt.tight_layout()
plt.show()
def main():
ps = PlotScores()
ps.matplot_box_plots()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,594 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/remove_structure/remove_pfam.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
from deconstruct_lc.scores.norm_score import NormScore
class RemovePfam(object):
def __init__(self):
config = read_config.read_config()
self.data_dp = os.path.join(config['fps']['data_dp'])
self.puncta = os.path.join(self.data_dp, 'experiment', 'puncta_uni.fasta')
self.nopuncta = os.path.join(self.data_dp, 'experiment', 'nopuncta_uni.fasta')
self.pfam_puncta = os.path.join(self.data_dp, 'experiment', 'puncta_pfam.tsv')
self.pfam_nopuncta = os.path.join(self.data_dp, 'experiment', 'nopuncta_pfam.tsv')
self.k = 6
self.lce = 1.6
self.lca = 'SGEQAPDTNKR'
self.lc_m = 0.06744064704548541
self.lc_b = 16.5
def run_percent_pfam(self):
puncta_perc = os.path.join(self.data_dp, 'experiment', 'puncta_percent_pfam.tsv')
self.percent_pfam(self.puncta, self.pfam_puncta, puncta_perc)
nopuncta_perc = os.path.join(self.data_dp, 'experiment', 'nopuncta_percent_pfam.tsv')
self.percent_pfam(self.nopuncta, self.pfam_nopuncta, nopuncta_perc)
def percent_pfam(self, fasta_fp, pfam_fp, fpo):
df = pd.read_csv(pfam_fp, sep='\t')
pids, seqs = tools_fasta.fasta_to_id_seq(fasta_fp)
frac_pfam = []
for id, seq in zip(pids, seqs):
ndf = df[df['uniprot_acc'] == id]
ndf = ndf.sort_values(by='seq_start')
segmented = self.segment_seq(seq, ndf)
len_seg = 0
for seg in segmented:
len_seg += len(seg)
frac_pfam.append(float(len(seq) - len_seg)/float(len(seq)))
ns = NormScore()
scores = ns.lc_norm_score(seqs)
df_out = pd.DataFrame({'Uniprot ID': pids, 'LC Score': scores,
'Pfam Fraction': frac_pfam}, columns=['Uniprot ID', 'LC Score', 'Pfam Fraction'])
df_out = df_out.sort_values(by='LC Score', ascending=False)
df_out.to_csv(fpo, sep='\t')
print(np.mean(frac_pfam))
def run_with_pfam(self):
puncta_out = os.path.join(self.data_dp, 'experiment', 'puncta_nopfam.tsv')
self.with_pfam(self.puncta, self.pfam_puncta, puncta_out)
nopuncta_out = os.path.join(self.data_dp, 'experiment', 'nopuncta_nopfam.tsv')
self.with_pfam(self.nopuncta, self.pfam_nopuncta, nopuncta_out)
def with_pfam(self, fasta_fp, pfam_fp, fpo):
"""
How many proteins in the set have pfam domains?
What is the fraction occupied by pfam domains?"""
df = pd.read_csv(pfam_fp, sep='\t')
pfam_ids = list(set(df['uniprot_acc']))
pids, seqs = tools_fasta.fasta_to_id_seq(fasta_fp)
print(len(pids))
nopfam_ids = list(set(pids) - set(pfam_ids))
nopfam_seqs = []
for pid, seq in zip(pids, seqs):
if pid in nopfam_ids:
nopfam_seqs.append(seq)
ns = NormScore()
scores = ns.lc_norm_score(nopfam_seqs)
df_out = pd.DataFrame({'UniProt ID': nopfam_ids, 'LC Score': scores}, columns=['UniProt ID', 'LC Score'])
df_out = df_out.sort_values(by='LC Score', ascending=False)
df_out.to_csv(fpo, sep='\t')
def fetch_score(self, df, pids):
scores = []
for pid in pids:
df = df[df['Protein ID'] == pid]
scores.append(list(df['LC Score'])[0])
return scores
def score_in_pfam(self):
ids, seqs = tools_fasta.fasta_to_id_seq(self.nopuncta)
df = pd.read_csv(self.pfam_nopuncta, sep='\t', index_col=0)
below = 0
above = 0
norm_scores = []
fl_norm_scores = []
for id, seq in zip(ids, seqs):
ndf = df[df['uniprot_acc'] == id]
ndf = ndf.sort_values(by='seq_start')
segmented = self.pfam_segments(seq, ndf)
total = 0
for item in segmented:
total += len(item)
if total >= 100:
above += 1
fl_score, fl_length = self.get_segment_scores([seq])
fl_norm = self.norm_function([fl_score], [fl_length])
raw_score, length = self.get_segment_scores(segmented)
norm_score = self.norm_function([raw_score], [length])
norm_scores.append(norm_score[0])
fl_norm_scores.append(fl_norm[0])
else:
below += 1
print(above)
print(below)
print(np.mean(norm_scores))
print(np.mean(fl_norm_scores))
print(np.median(norm_scores))
print(np.median(fl_norm_scores))
plt.hist(fl_norm_scores, alpha=0.5, bins=20, range=(-100, 200), label='Full length scores')
plt.hist(norm_scores, alpha=0.5, bins=20, range=(-100, 200), label='Inside Pfam scores')
plt.legend()
plt.show()
def run(self):
ids, seqs = tools_fasta.fasta_to_id_seq(self.puncta)
df = pd.read_csv(self.pfam_puncta, sep='\t', index_col=0)
new_seqs = []
below = 0
above = 0
norm_scores = []
fl_norm_scores = []
for id, seq in zip(ids, seqs):
ndf = df[df['uniprot_acc'] == id]
ndf = ndf.sort_values(by='seq_start')
segmented = self.segment_seq(seq, ndf)
total = 0
for item in segmented:
total += len(item)
if total >= 100:
above += 1
fl_score, fl_length = self.get_segment_scores([seq])
fl_norm = self.norm_function([fl_score], [fl_length])
raw_score, length = self.get_segment_scores(segmented)
norm_score = self.norm_function([raw_score], [length])
norm_scores.append(norm_score[0])
fl_norm_scores.append(fl_norm[0])
else:
below += 1
print(above)
print(below)
print(np.mean(norm_scores))
print(np.mean(fl_norm_scores))
print(np.median(norm_scores))
print(np.median(fl_norm_scores))
plt.hist(fl_norm_scores, alpha=0.5, bins=20, range=(-100, 200), label='Full length scores')
plt.hist(norm_scores, alpha=0.5, bins=20, range=(-100, 200), label='Outside Pfam scores')
plt.legend()
plt.show()
def pfam_segments(self, seq, df):
new_seq = []
for i, row in df.iterrows():
new_seq.append(seq[row['seq_start']: row['seq_end']+1])
return new_seq
def segment_seq(self, seq, df):
"""Given intervals, pull out the domain, and segment around it"""
start = 0
new_seq = []
for i, row in df.iterrows():
new_seq.append(seq[start:row['seq_start']])
start = row['seq_end'] + 1
new_seq.append(seq[start:])
return new_seq
def pfam_in_common(self):
df = pd.read_csv(self.pfam_puncta, sep='\t', index_col=0)
print(df['pfamA_acc'].value_counts())
def get_segment_scores(self, segment_seq):
total_motifs = 0
total_length = 0
for seq in segment_seq:
motifs = tools_lc.count_lc_motifs(seq, self.k, self.lca, self.lce)
total_motifs += motifs
total_length += len(seq)
return total_motifs, total_length
def norm_function(self, raw_scores, lengths):
norm_scores = []
for raw_score, length in zip(raw_scores, lengths):
norm_score = raw_score - ((self.lc_m * length) + self.lc_b)
norm_scores.append(norm_score)
return norm_scores
def main():
rp = RemovePfam()
rp.pfam_in_common()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,595 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/biogrid/format.py | import os
import pandas as pd
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc.analysis_bc.write_bc_score import BcScore
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
class FormatBiogrid(object):
def __init__(self):
config = read_config.read_config()
data = config['fps']['data_dp']
bio_dp = os.path.join(data, 'biogrid')
self.bio_fp = os.path.join(bio_dp, 'BIOGRID-ORGANISM-Saccharomyces_cerevisiae_S288c-3.4.157.mitab.txt')
self.pbody_fp = os.path.join(bio_dp, 'Pbody_annotations.txt')
self.interactions_fp = os.path.join(bio_dp, 'pbody.tsv')
self.yeast_scores = os.path.join(bio_dp, 'orf_pbody_scores.tsv')
self.yeast_fasta = os.path.join(bio_dp, 'orf_trans.fasta')
def get_pbody(self):
df = pd.read_csv(self.pbody_fp, sep='\t')
pids = list(df['Gene Systematic Name'])
return set(pids)
def read_biogrid(self):
df_in = pd.read_csv(self.interactions_fp, sep='\t')
print(len(set(df_in['A'])))
print(len(set(df_in['B'])))
def write_biogrid(self):
pbodies = self.get_pbody()
df_dict = {'A': [], 'B': []}
df = pd.read_csv(self.bio_fp, sep='\t')
for i, row in df.iterrows():
yida = row['Alt IDs Interactor A']
yidb = row['Alt IDs Interactor B']
if (len(yida.split(':')) > 3) and (len(yidb.split(':')) > 3):
pida = yida.split(':')[3].strip()
pidb = yidb.split(':')[3].strip()
if pida in pbodies and pidb in pbodies:
if pida != pidb:
df_dict['A'].append(pida)
df_dict['B'].append(pidb)
df_out = pd.DataFrame(df_dict)
df_out.drop_duplicates(inplace=True)
df_out.to_csv(self.interactions_fp, sep='\t')
print(df_dict)
print(len(df_dict['A']))
def get_scores(self):
pbodies = self.get_pbody()
pids, seqs = tools_fasta.fasta_to_id_seq(self.yeast_fasta)
pseqs = []
ppids = []
for pid, seq in zip(pids, seqs):
if pid in pbodies:
pseqs.append(seq)
ppids.append(pid)
ns = NormScore()
scores = ns.lc_norm_score(pseqs)
df_dict = {'Protein ID': ppids, 'LC Score': scores}
df_out = pd.DataFrame(df_dict)
df_out.to_csv(self.yeast_scores, sep='\t')
def main():
bg = FormatBiogrid()
bg.write_biogrid()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,596 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/experiment/format_gfp.py | import os
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.scores.norm_score import NormScore
class FormatGfp(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
experiment_dp = os.path.join(data_dp, 'experiment')
self.gfp_fp = os.path.join(experiment_dp, 'allOrfData_yeastgfp.txt')
self.marcotte_fpi = os.path.join(experiment_dp,
'marcotte_puncta_proteins.xlsx')
self.temp_out = os.path.join(experiment_dp, 'marcotte_notpuncta.tsv')
def read_files(self):
marc_df = pd.read_excel(self.marcotte_fpi, 'ST1')
marc_ids = set(marc_df['ORF'])
df = pd.read_csv(self.gfp_fp, sep='\t', index_col=False)
df = df[df['localization summary'] == 'cytoplasm']
df = df[~df['yORF'].isin(marc_ids)]
ndf = pd.DataFrame({'Gene': df['gene name'], 'ORF': df['yORF']})
ndf.to_csv(self.temp_out, sep='\t')
def main():
fg = FormatGfp()
fg.read_files()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,597 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/raw_norm.py | import os
import pandas as pd
from deconstruct_lc import tools_lc
class RawNorm(object):
"""
Read the m/b values for each representative label and write the normalized
score
"""
def __init__(self, config):
self.config = config
data_dp = self.config['fps']['data_dp']
self.param_dp = os.path.join(data_dp, 'params')
self.combos_dp = os.path.join(self.param_dp, 'combos')
self.solo_dp = os.path.join(self.param_dp, 'solo')
self.mb_solo_fp = os.path.join(self.param_dp, 'mb_solo.tsv')
train = os.path.join(data_dp, 'train.tsv')
train_df = pd.read_csv(train, sep='\t', index_col=0)
self.seqs = list(train_df['Sequence'])
self.pids = list(train_df['Protein ID'])
self.y = list(train_df['y'])
self.lengths = list(train_df['Length'])
def solo_norm(self):
df_in = pd.read_csv(self.mb_solo_fp, sep='\t', index_col=0)
df_in = df_in[df_in['pearsons'] > 0.7]
for i, row in df_in.iterrows():
fno = 'norm_{}.tsv'.format(str(row['lc label']))
fpo = os.path.join(self.solo_dp, fno)
m = float(row['m'])
b = float(row['b'])
lc_label = str(row['lc label'])
print(lc_label)
params = lc_label.split('_')
k = int(params[0])
if isinstance(params[1], str):
lca = str(params[1])
raw_scores = tools_lc.calc_lca_motifs(self.seqs, k, lca)
else:
lce = float(params[1])
raw_scores = tools_lc.calc_lce_motifs(self.seqs, k, lce)
norm_scores = self.norm_function(m, b, raw_scores, self.lengths)
df_dict = {'Norm Scores': norm_scores, 'Protein ID': self.pids,
'y': self.y}
df_out = pd.DataFrame(df_dict)
df_out.to_csv(fpo, sep='\t')
def combo_norm(self):
fns = os.listdir(self.combos_dp)
for fn in fns:
fpi = os.path.join(self.combos_dp, fn)
df_in = pd.read_csv(fpi, sep='\t', index_col=0)
df_in = df_in[df_in['pearsons'] > 0.7]
if len(df_in) > 0:
df_dict = {'Protein ID': self.pids, 'y': self.y}
fpo = os.path.join(self.combos_dp, 'norm_{}'.format(fn))
params = fn.split('_')
k = int(params[0])
lce = float(params[1])
lca = str(params[3])[:-4]
for i, row in df_in.iterrows():
lc_label = str(row['LC Type'])
m = float(row['m'])
b = float(row['b'])
norm_scores = self.get_norm_scores(m, b, lc_label, k, lca, lce)
df_dict[lc_label] = norm_scores
df_out = pd.DataFrame(df_dict)
df_out.to_csv(fpo, sep='\t')
def get_norm_scores(self, m, b, lc_label, k, lca, lce):
raw_scores = self.get_raw_scores(lc_label, k, lca, lce)
norm_scores = self.norm_function(m, b, raw_scores, self.lengths)
return norm_scores
def get_raw_scores(self, lc_label, k, lca, lce):
if lc_label == 'LCA || LCE':
scores = tools_lc.calc_lc_motifs(self.seqs, k, lca, lce)
elif lc_label == 'LCA & LCE':
scores = []
for seq in self.seqs:
scores.append(tools_lc.count_lca_and_lce(seq, k, lca, lce))
elif lc_label == 'LCA & ~LCE':
scores = []
for seq in self.seqs:
scores.append(tools_lc.count_lca_not_lce(seq, k, lca, lce))
elif lc_label == '~LCA & LCE':
scores = []
for seq in self.seqs:
scores.append(tools_lc.count_not_lca_lce(seq, k, lca, lce))
else:
raise Exception('Unexpected logical expression')
return scores
@staticmethod
def norm_function(m, b, raw_scores, lengths):
norm_scores = []
for raw_score, length in zip(raw_scores, lengths):
norm_score = raw_score - ((m * length) + b)
norm_scores.append(norm_score)
return norm_scores | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,598 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/raw_svm.py | import os
import numpy as np
import pandas as pd
from deconstruct_lc.svm import svms
class RawSvm(object):
def __init__(self, config):
data_dp = config['fps']['data_dp']
self.param_dp = os.path.join(data_dp, 'params')
self.k1 = config.getint('params', 'k1')
self.k2 = config.getint('params', 'k2')
def svm_lca_lce(self):
for k in range(self.k1, self.k2):
print("{} LCE".format(k))
lce_fpi = os.path.join(self.param_dp, 'raw_{}_lce.tsv'.format(k))
lce_fpo = os.path.join(self.param_dp, 'svm_{}_lce.tsv'.format(k))
self.raw_svm(lce_fpi, lce_fpo)
print("{} LCA".format(k))
lca_fpi = os.path.join(self.param_dp, 'raw_{}_lca.tsv'.format(k))
lca_fpo = os.path.join(self.param_dp, 'svm_{}_lca.tsv'.format(k))
self.raw_svm(lca_fpi, lca_fpo)
def raw_svm(self, fpi, fpo):
df_dict = {'SVM score': [], 'Label': []}
cols = ['Label', 'SVM score']
rem_cols = ['Protein ID', 'Length', 'y']
df_in = pd.read_csv(fpi, sep='\t', index_col=0)
k_lcs = [lab for lab in df_in.columns.values.tolist() if lab not
in rem_cols]
for i, k_lc in enumerate(k_lcs):
print(i)
print(k_lc)
raw_scores = df_in[k_lc]
X = np.array([raw_scores]).T
y = np.array(df_in['y']).T
clf = svms.linear_svc(X, y)
df_dict['SVM score'].append(clf.score(X, y))
df_dict['Label'].append(k_lc)
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(fpo, sep='\t') | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,599 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_bc/pull_uni.py | import requests
def fetch_uniprot(uniID):
"""
status codes:
200 -- The request was processed successfully
400 -- Bad request. There was a problem with your input
404 -- Not found. The resource you requested doesn't exist
410 -- Gone. The resource you requested was removed
500 -- Internal server error. Most likely a temporary problem
503 -- Service not available. The server is being updated
"""
headers = {'From': 'shelly.deforte@gmail.com'}
try:
r = requests.get(
'http://www.uniprot.org/uniprot/{}.fasta'.format(uniID),
timeout=5, headers=headers)
if r.status_code == 200:
return r
except:
return None
def write_fasta(uniIDs, fp):
with open(fp, 'w') as fpo:
for uniID in uniIDs:
fasta = fetch_uniprot(uniID)
if fasta:
fpo.write(fasta.text)
else:
raise Exception("Error pulling UniProt entry") | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,600 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/examples/sandbox.py | from deconstruct_lc import tools_lc
from deconstruct_lc.scores.norm_score import NormScore
def main():
k = 6
lce = 1.6
lca = 'SGEQAPDTNKR'
sup35 = "MSDSNQGNNQQNYQQYSQNGNQQQGNNRYQGYQAYNAQAQPAGGYYQNYQGYSGYQQGGY" \
"QQYNPDAGYQQQYNPQGGYQQYNPQGGYQQQFNPQGGRGNYKNFNYNNNLQGYQAGFQPQ" \
"SQGMSLNDFQKQQKQAAPKPKKTLKLVSSSGIKLANATKKVGTKPAESDKKEEEKSAETK" \
"EPTKEPTKVEEPVKKEEKPVQTEEKTEEKSELPKVEDLKISESTHNTNNANVTSADALIK" \
"EQEEEVDDEVVNDMFGGKDHVSLIFMGHVDAGKSTMGGNLLYLTGSVDKRTIEKYEREAK" \
"DAGRQGWYLSWVMDTNKEERNDGKTIEVGKAYFETEKRRYTILDAPGHKMYVSEMIGGAS" \
"QADVGVLVISARKGEYETGFERGGQTREHALLAKTQGVNKMVVVVNKMDDPTVNWSKERY" \
"DQCVSNVSNFLRAIGYNIKTDVVFMPVSGYSGANLKDHVDPKECPWYTGPTLLEYLDTMN" \
"HVDRHINAPFMLPIAAKMKDLGTIVEGKIESGHIKKGQSTLLMPNKTAVEIQNIYNETEN" \
"EVDMAMCGEQVKLRIKGVEEEDISPGFVLTSPKNPIKSVTKFVAQIAIVELKSIIAAGFS" \
"CVMHVHTAIEEVHIVKLLHKLEKGTNRKSKKPPAFAKKGMKVIAVLETEAPVCVETYQDY" \
"PQLGRFTLRDQGTTIAIGKIVKIAE"
#print(sup35[253])
ns = tools_lc.display_lc(sup35[253], k, lca, lce)
#print(ns)
motifs = tools_lc.count_lc_motifs(sup35[253], k, lca, lce)
#print(motifs)
norm = NormScore()
#print(norm.lc_norm_score([sup35[253]]))
ns = tools_lc.display_lc(sup35[253], k, lca, lce)
#print(ns)
pab1 = 'MADITDKTAEQLENLNIQDDQKQAATGSESQSVENSSASLYVGDLEPSVSEAHLYDIFSP' \
'IGSVSSIRVCRDAITKTSLGYAYVNFNDHEAGRKAIEQLNYTPIKGRLCRIMWSQRDPSL' \
'RKKGSGNIFIKNLHPDIDNKALYDTFSVFGDILSSKIATDENGKSKGFGFVHFEEEGAAK' \
'EAIDALNGMLLNGQEIYVAPHLSRKERDSQLEETKAHYTNLYVKNINSETTDEQFQELFA' \
'KFGPIVSASLEKDADGKLKGFGFVNYEKHEDAVKAVEALNDSELNGEKLYVGRAQKKNER' \
'MHVLKKQYEAYRLEKMAKYQGVNLFVKNLDDSVDDEKLEEEFAPYGTITSAKVMRTENGK' \
'SKGFGFVCFSTPEEATKAITEKNQQIVAGKPLYVAIAQRKDVRRSQLAQQIQARNQMRYQ' \
'QATAAAAAAAAGMPGQFMPPMFYGVMPPRGVPFNGPNPQQMNPMGGMPKNGMPPQFRNGP' \
'VYGVPPQGGFPRNANDNNQFYQQKQRQALGEQLYKKVSAKTSNEEAAGKITGMILDLPPQ' \
'EVFPLLESDELFEQHYKEASAAYESFKKEQEQQTEQA'
print(len(pab1))
wop = pab1[0:300]
#print(wop)
#print(wop)
motifs = tools_lc.count_lc_motifs(wop, k, lca, lce)
#print(motifs)
norm = NormScore()
print(norm.lc_norm_score([wop]))
ns = tools_lc.display_lc(pab1, k, lca, lce)
#print(ns)
nck = 'MAEEVVVVAKFDYVAQQEQELDIKKNERLWLLDDSKSWWRVRNSMNKTGFVPSNYVERKN' \
'SARKASIVKNLKDTLGIGKVKRKPSVPDSASPADDSFVDPGERLYDLNMPAYVKFNYMAE' \
'REDELSLIKGTKVIVMEKCSDGWWRGSYNGQVGWFPSNYVTEEGDSPLGDHVGSLSEKLA' \
'AVVNNLNTGQVLHVVQALYPFSSSNDEELNFEKGDVMDVIEKPENDPEWWKCRKINGMVG' \
'LVPKNYVTVMQNNPLTSGLEPSPPQCDYIRPSLTGKFAGNPWYYGKVTRHQAEMALNERG' \
'HEGDFLIRDSESSPNDFSVSLKAQGKNKHFKVQLKETVYCIGQRKFSTMEELVEHYKKAP' \
'IFTSEQGEKLYLVKHLS'
#norm = NormScore([nck])
#print(norm.lc_norm_score())
nwasp = 'MSSVQQQPPPPRRVTNVGSLLLTPQENESLFTFLGKKCVTMSSAVVQLYAADRNCMWSKK' \
'CSGVACLVKDNPQRSYFLRIFDIKDGKLLWEQELYNNFVYNSPRGYFHTFAGDTCQVALN' \
'FANEEEAKKFRKAVTDLLGRRQRKSEKRRDPPNGPNLPMATVDIKNPEITTNRFYGPQVN' \
'NISHTKEKKKGKAKKKRLTKADIGTPSNFQHIGHVGWDPNTGFDLNNLDPELKNLFDMCG' \
'ISEAQLKDRETSKVIYDFIEKTGGVEAVKNELRRQAPPPPPPSRGGPPPPPPPPHNSGPP' \
'PPPARGRGAPPPPPSRAPTAAPPPPPPSRPSVAVPPPPPNRMYPPPPPALPSSAPSGPPP' \
'PPPSVLGVGPVAPPPPPPPPPPPGPPPPPGLPSDGDHQVPTTAGNKAALLDQIREGAQLK' \
'KVEQNSRPVSCSGRDALLDQIRQGIQLKSVADGQESTPPTPAPTSGIVGALMEVMQKRSK' \
'AIHSSDEDEDEDDEEDFEDDDEWED'
#norm = NormScore([nwasp])
#print(norm.lc_norm_score())
nephrin = 'MALGTTLRASLLLLGLLTEGLAQLAIPASVPRGFWALPENLTVVEGASVELRCGVSTPGS' \
'AVQWAKDGLLLGPDPRIPGFPRYRLEGDPARGEFHLHIEACDLSDDAEYECQVGRSEMGP' \
'ELVSPRVILSILVPPKLLLLTPEAGTMVTWVAGQEYVVNCVSGDAKPAPDITILLSGQTI' \
'SDISANVNEGSQQKLFTVEATARVTPRSSDNRQLLVCEASSPALEAPIKASFTVNVLFPP' \
'GPPVIEWPGLDEGHVRAGQSLELPCVARGGNPLATLQWLKNGQPVSTAWGTEHTQAVARS' \
'VLVMTVRPEDHGAQLSCEAHNSVSAGTQEHGITLQVTFPPSAIIILGSASQTENKNVTLS' \
'CVSKSSRPRVLLRWWLGWRQLLPMEETVMDGLHGGHISMSNLTFLARREDNGLTLTCEAF' \
'SEAFTKETFKKSLILNVKYPAQKLWIEGPPEGQKLRAGTRVRLVCLAIGGNPEPSLMWYK' \
'DSRTVTESRLPQESRRVHLGSVEKSGSTFSRELVLVTGPSDNQAKFTCKAGQLSASTQLA' \
'VQFPPTNVTILANASALRPGDALNLTCVSVSSNPPVNLSWDKEGERLEGVAAPPRRAPFK' \
'GSAAARSVLLQVSSRDHGQRVTCRAHSAELRETVSSFYRLNVLYRPEFLGEQVLVVTAVE' \
'QGEALLPVSVSANPAPEAFNWTFRGYRLSPAGGPRHRILSSGALHLWNVTRADDGLYQLH' \
'CQNSEGTAEARLRLDVHYAPTIRALQDPTEVNVGGSVDIVCTVDANPILPGMFNWERLGE' \
'DEEDQSLDDMEKISRGPTGRLRIHHAKLAQAGAYQCIVDNGVAPPARRLLRLVVRFAPQV' \
'EHPTPLTKVAAAGDSTSSATLHCRARGVPNIVFTWTKNGVPLDLQDPRYTEHTYHQGGVH' \
'SSLLTIANVSAAQDYALFTCTATNALGSDQTNIQLVSISRPDPPSGLKVVSLTPHSVGLE' \
'WKPGFDGGLPQRFCIRYEALGTPGFHYVDVVPPQATTFTLTGLQPSTRYRVWLLASNALG' \
'DSGLADKGTQLPITTPGLHQPSGEPEDQLPTEPPSGPSGLPLLPVLFALGGLLLLSNASC' \
'VGGVLWQRRLRRLAEGISEKTEAGSEEDRVRNEYEESQWTGERDTQSSTVSTTEAEPYYR' \
'SLRDFSPQLPPTQEEVSYSRGFTGEDEDMAFPGHLYDEVERTYPPSGAWGPLYDEVQMGP' \
'WDLHWPEDTYQDPRGIYDQVAGDLDTLEPDSLPFELRGHLV'
# nicd = nephrin[1077:1242]
# norm = NormScore([nicd])
# print(norm.lc_norm_score())
# print(nicd)
# ns = tools_lc.display_lc(nicd, k, lca, lce)
# print(ns)
# motifs = tools_lc.count_lc_motifs(nicd, k, lca, lce)
# print(motifs)
# gfp = 'MSKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTL' \
# 'VTTFSYGVQCFSRYPDHMKQHDFFKSAMPEGYVQERTIFFKDDGNYKTRAEVKFEGDTLV' \
# 'NRIELKGIDFKEDGNILGHKLEYNYNSHNVYIMADKQKNGIKVNFKIRHNIEDGSVQLAD' \
# 'HYQQNTPIGDGPVLLPDNHYLSTQSALSKDPNEKRDHMVLLEFVTAAGITHGMDELYK'
# #ns = tools_lc.display_lc(nicd+gfp, k, lca, lce)
# #norm = NormScore([nicd+gfp])
# #print(norm.lc_norm_score())
# #print(ns)
fus = 'MASNDYTQQATQSYGAYPTQPGQGYSQQSSQPYGQQSYSGYSQSTDTSGYGQSSYSSYGQ' \
'SQNTGYGTQSTPQGYGSTGGYGSSQSSQSSYGQQSSYPGYGQQPAPSSTSGSYGSSSQSS' \
'SYGQPQSGSYSQQPSYGGQQQSYGQQQSYNPPQGYGQQNQY'
fus = 'MASNDYTQQATQSYGAYPTQPGQGYSQQSSQPYGQQSYSGYSQSTDTSGYGQSSYSSYGQ' \
'SQNTGYGTQSTPQGYGSTGGYGSSQSSQSSYGQQSSYPGYGQQPAPSSTSGSYGSSSQSS' \
'SYGQPQSGSYSQQPSYGGQQQSYGQQQSYNPPQGYGQQNQYNSSSGGGGGGGGGGNYGQD' \
'QSSMSSGGGSGGGYGNQDQSGGGGSGGYGQQDRGGRGRGGSGGGGGGGGGGYNRSSGGYE' \
'PRGRGGGRGGRGGMGGSDRGGFNKFGGPRDQGSRHDSEQDNSDNNTIFVQGLGENVTIES' \
'VADYFKQIGIIKTNKKTGQPMINLYTDRETGKLKGEATVSFDDPPSAKAAIDWFDGKEFS' \
'GNPIKVSFATRRADFNRGGGNGRGGRGRGGPMGRGGYGGGGSGGGGRGGFPSGGGGGGGQ' \
'QRAGDWKCPNPTCENMNFSWRNECNQCKAPKPDGPGGGPGGSHMGGNYGDDRRGGRGGYD' \
'RGGYRGRGGDRGGFRGGRGGGDRGGFGPGKMDSRGEHRQDRRERPY'
ns = tools_lc.display_lc(fus[0:214], k, lca, lce)
#print(fus[0:214])
#print(ns)
# print(fus)
norm = NormScore()
#print(norm.lc_norm_score([fus]))
pex5 = 'MDVGSCSVGNNPLAQLHKHTQQNKSLQFNQKNNGRLNESPLQGTNKPGISEAFISNVNAI' \
'SQENMANMQRFINGEPLIDDKRRMEIGPSSGRLPPFSNVHSLQTSANPTQIKGVNDISHW' \
'SQEFQGSNSIQNRNADTGNSEKAWQRGSTTASSRFQYPNTMMNNYAYASMNSLSGSRLQS' \
'PAFMNQQQSGRSKEGVNEQEQQPWTDQFEKLEKEVSENLDINDEIEKEENVSEVEQNKPE' \
'TVEKEEGVYGDQYQSDFQEVWDSIHKDAEEVLPSELVNDDLNLGEDYLKYLGGRVNGNIE' \
'YAFQSNNEYFNNPNAYKIGCLLMENGAKLSEAALAFEAAVKEKPDHVDAWLRLGLVQTQN' \
'EKELNGISALEECLKLDPKNLEAMKTLAISYINEGYDMSAFTMLDKWAETKYPEIWSRIK' \
'QQDDKFQKEKGFTHIDMNAHITKQFLQLANNLSTIDPEIQLCLGLLFYTKDDFDKTIDCF' \
'ESALRVNPNDELMWNRLGASLANSNRSEEAIQAYHRALQLKPSFVRARYNLAVSSMNIGC' \
'FKEAAGYLLSVLSMHEVNTNNKKGDVGSLLNTYNDTVIETLKRVFIAMNRDDLLQEVKPG' \
'MDLKRFKGEFSF'
norm = NormScore()
#print(len(pex5))
#print(norm.lc_norm_score([pex5[0:300]]))
#print(pex5)
ns = tools_lc.display_lc(pex5, k, lca, lce)
#print(ns)
pex13 = 'MSSTAVPRPKPWETSASLEEPQRNAQSLSAMMTSNQQDSRPTEESNNSNSASESAPEVLP' \
'RPAALNSSGTYGESNTIPGIYGNSNYGIPYDNNPYSMNSIYGNSIGRYGYGGSYYGNNYG' \
'SFYGGGYGAGAGYGMNNGSGLGESTKATFQLIESLIGAVTGFAQMLESTYMATHNSFFTM' \
'ISVAEQFGNLKEMLGSFFGIFAIMKFLKKILYRATKGRLGIPPKNFAESEGSKNKLIEDF' \
'QKFNDSGTINSNEKATRRKISWKPLLFFLMAVFGFPYLLNKFITKLQTSGTIRASQGNGS' \
'EPIDPSKLEFARALYDFVPENPEMEVALKKGDLMAILSKKDPLGRDSDWWKVRTKNGNIG' \
'YIPYNYIEIIKRRKKIEHVDDETRTH'
#print(norm.lc_norm_score([pex13]))
pex14 = 'MSDVVSKDRKALFDSAVSFLKDESIKDAPLLKKIEFLKSKGLTEKEIEIAMKEPKKDGIV' \
'GDEVSKKIGSTENRASQDMYLYEAMPPTLPHRDWKDYFVMATATAGLLYGAYEVTRRYVI' \
'PNILPEAKSKLEGDKKEIDDQFSKIDTVLNAIEAEQAEFRKKESETLKELSDTIAELKQA' \
'LVQTTRSREKIEDEFRIVKLEVVNMQNTIDKFVSDNDGMQELNNIQKEMESLKSLMNNRM' \
'ESGNAQDNRLFSISPNGIPGIDTIPSASEILAKMGMQEESDKEKENGSDANKDDNAVPAW' \
'KKAREQTIDSNASIPEWQKNTAANEISVPDWQNGQVEDSIP'
#print(norm.lc_norm_score([pex14]))
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,601 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/complementarity/sliding_fraction.py | """
Plot omega, sliding net charge
plot sliding fraction of Q/N, S/T, A/G, P
"""
import os
import pandas as pd
import matplotlib.pyplot as plt
from deconstruct_lc import tools_lc
from deconstruct_lc.complementarity import motif_seq
class Fraction(object):
def __init__(self):
self.k = 6
self.lca = 'SGEQAPDTNKR'
self.lce = 1.6
def process_seq(self, seq, k):
kmers = tools_lc.seq_to_kmers(seq, k)
qn = self.alph_fracs(kmers, 'QN')
st = self.alph_fracs(kmers, 'ST')
ag = self.alph_fracs(kmers, 'AG')
p = self.alph_fracs(kmers, 'P')
ed = self.alph_fracs(kmers, 'ED')
kr = self.alph_fracs(kmers, 'KR')
f = self.alph_fracs(kmers, 'F')
r = self.alph_fracs(kmers, 'R')
#plt.plot(qn, label='QN')
plt.plot(st, label='ST')
#plt.plot(ag, label='AG')
#plt.plot(r, label='R')
#plt.plot(f, label='F')
lca_x, lca_y, lce_x, lce_y = self.get_motif_index(seq)
plt.scatter(lca_x, lca_y, color='black', s=2)
plt.scatter(lce_x, lce_y, color='red', s=2)
#plt.plot(ed, label='ED')
#plt.plot(kr, label='KR')
plt.plot(p, label='P')
plt.legend()
plt.show()
def alph_fracs(self, kmers, alph):
fracs = []
for kmer in kmers:
frac = self.get_frac(kmer, alph)
fracs.append(frac)
return fracs
def get_frac(self, kmer, alph):
tot_count = 0
for aa in alph:
tot_count += kmer.count(aa)
assert tot_count <= len(kmer)
frac = float(tot_count)/float(len(kmer))
return frac
def get_motif_index(self, sequence):
mot = motif_seq.LcSeq(sequence, self.k, self.lca, 'lca')
ind_in, ind_out = mot._get_motif_indexes()
lca_x = list(ind_in)
lca_y = [1]*(len(lca_x))
mot = motif_seq.LcSeq(sequence, self.k, self.lce, 'lce')
ind_in, ind_out = mot._get_motif_indexes()
lce_x = list(ind_in)
lce_y = [1.1]*(len(lce_x))
return lca_x, lca_y, lce_x, lce_y
class Pipeline(object):
def __init__(self):
self.base_fp = os.path.join(os.path.dirname(__file__), '..', 'data')
self.nmo_fpi = os.path.join(self.base_fp, 'scores',
'nmo_6_SGEQAPDTNKR_6_1.6_seq_scores.tsv')
self.pdb_fpi = os.path.join(self.base_fp, 'scores',
'pdb_nomiss_cd50_6_SGEQAPDTNKR_6_1.6_seq_scores.tsv')
self.lca_label = '6_SGEQAPDTNKR'
self.lce_label = '6_1.6'
def sandbox(self):
label = self.lca_label
df = pd.read_csv(self.nmo_fpi, sep='\t', index_col=0)
df = df[(df[label] > 30)]
df = df.sort_values(by=[label])
df = df.reset_index(drop=True)
for i, row in df.iterrows():
sequence = row['Sequence']
print(len(sequence))
print(row[label])
print(row['Protein ID'])
frac = Fraction()
frac.process_seq(sequence, 6)
def main():
pipe = Pipeline()
pipe.sandbox()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,602 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_pdb/miss_score.py | import matplotlib.pyplot as plt
import os
import numpy as np
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc import motif_seq
class MissScore(object):
def __init__(self):
self.config = read_config.read_config()
self.data_dp = self.config['fps']['data_dp']
self.pdb_dp = os.path.join(self.data_dp, 'pdb_prep')
self.pdb_an_dp = os.path.join(self.data_dp,
'pdb_analysis')
self.an_fpi = os.path.join(self.pdb_dp, 'pdb_analysis.tsv')
self.miss_fp = os.path.join(self.pdb_an_dp, 'miss_in_out.tsv')
self.k = 6
self.lce = 1.6
self.lca = 'SGEQAPDTNKR'
def plot_all(self):
"""
subplot(nrows, ncolumns, index)
"""
fig = plt.figure()
pos2 = list(range(1, 33, 3))
x = [i + 0.5 for i in pos2]
ax1 = fig.add_subplot(211)
ax2 = ax1.twinx()
self.frac_miss_box(ax1, ax2, x)
ax3 = fig.add_subplot(212)
ax1.set_xlim([0, 33])
ax2.set_xlim([0, 33])
ax3.set_xlim([0, 33])
self.plot_inout_box(ax3, x)
plt.tight_layout()
plt.show()
def frac_miss_box(self, ax1, ax2, x):
# note labels in boxplots
frac_miss, miss_counts = self.frac_count_data()
self.plot_frac(ax1, x, frac_miss)
self.plot_count(ax2, x, miss_counts)
ax1.tick_params('y', colors='black')
ax1.set_ylim([0.75, 1.0])
ax1.tick_params(axis='x', which='both', labelbottom='off')
ax2.tick_params(axis='x', which='both', labelbottom='off')
ax2.set_ylim([0, 260])
def plot_frac(self, ax, x, frac_miss):
top_color = 'peru'
ax.plot(x, frac_miss,
color='grey')
ax.scatter(x, frac_miss,
marker='o',
color=top_color,
s=20)
ax.set_ylabel('Fraction w/ Missing',
color=top_color,
size=12)
def plot_count(self, ax, x, miss_counts):
bot_color = 'maroon'
bp = {'color': 'grey'}
wp = {'color': 'grey',
'linestyle':'-'}
medianprops = dict(linestyle='-',
color='black')
meanpointprops = dict(marker='D',
markeredgecolor=bot_color,
markerfacecolor=bot_color,
markersize=3)
ax.boxplot(miss_counts,
vert=True,
positions=x,
whis=[5, 95],
widths=1,
showfliers=False,
showmeans=True,
boxprops=bp,
whiskerprops=wp,
medianprops=medianprops,
meanprops=meanpointprops)
ax.set_ylabel('Mean Missing',
color=bot_color,
size=12)
def frac_count_data(self):
df = pd.read_csv(self.an_fpi, sep='\t', index_col=0)
bins = range(0, 50, 5)
miss_counts = []
frac_miss = []
for i in bins:
ndf = df[(df['LC Raw'] >= i) & (df['LC Raw'] < i + 5)]
nm_ndf = ndf[ndf['Miss Count'] > 0]
miss_counts.append(list(nm_ndf['Miss Count']))
frac_miss.append(len(nm_ndf) / len(ndf))
ndf = df[(df['LC Raw'] >= 50)]
nm_ndf = ndf[ndf['Miss Count'] > 0]
miss_counts.append(list(nm_ndf['Miss Count']))
frac_miss.append(len(nm_ndf) / len(ndf))
return frac_miss, miss_counts
def plot_inout_box(self, ax3, x):
top_color = 'peru'
bot_color = 'maroon'
labels = ['0-5', '5-10', '10-15', '15-20', '20-25', '25-30',
'30-35', '35-40', '40-45', '45-50', '50+']
motif_perc, miss_in, all_box = self.inout_data()
pos1 = list(range(2, 34, 3))
pos2 = list(range(1, 33, 3))
miss_in_means = []
for item in miss_in:
miss_in_means.append(np.mean(item))
motif_perc_means = []
for item in motif_perc:
motif_perc_means.append(np.mean(item))
bp1 = {'color': 'grey', 'facecolor': 'white'}
wp1 = {'color': 'grey', 'linestyle':'-', 'alpha': 0.5}
bp2 = {'color': 'grey', 'alpha': 0.8, 'facecolor': 'grey'}
wp2 = {'color': 'grey', 'linestyle':'-', 'alpha': 0.5}
medianprops = dict(linestyle='-', color='black')
meanpointprops1 = dict(marker='o',
markeredgecolor=top_color,
markerfacecolor=top_color,
markersize=5)
meanpointprops2 = dict(marker='o',
markeredgecolor=bot_color,
markerfacecolor=bot_color,
markersize=3)
ax3.plot(pos1, miss_in_means, color=top_color, alpha=0.5)
ax3.plot(pos2, motif_perc_means, color=bot_color, alpha=0.5)
bp = ax3.boxplot(miss_in,
vert=True,
positions=pos1,
whis=[5, 95],
widths=0.75,
showfliers=False,
showmeans=True,
patch_artist=True,
boxprops=bp1,
whiskerprops=wp1,
medianprops=medianprops,
meanprops=meanpointprops1)
bp2 = ax3.boxplot(motif_perc,
vert=True,
positions=pos2,
whis=[5, 95],
widths=1,
showfliers=False,
showmeans=True,
patch_artist=True,
boxprops=bp2,
whiskerprops=wp2,
medianprops=medianprops,
meanprops=meanpointprops2)
ax3.set_ylim([-0.1, 1.1])
ax3.set_xlim([0, 33])
ax3.set_ylabel('Missing in LC', color=top_color, size=12)
ax2 = ax3.twinx()
ax2.set_ylabel('LC Fraction', color=bot_color, size=12)
ax3.set_xlabel('LC Motifs')
ax3.set_xticks(x)
ax3.set_xticklabels(labels, rotation=45)
def inout_data(self):
df = pd.read_csv(self.miss_fp, sep='\t', index_col=0)
bins = range(0, 50, 5)
miss_in = []
motif_perc = []
all_box = []
for i in bins:
ndf = df[(df['LC Raw'] >= i) & (df['LC Raw'] < i + 5)]
all_box.append(list(ndf['Motif perc']))
all_box.append(list(ndf['Miss in motif']))
miss_in.append(list(ndf['Miss in motif']))
motif_perc.append(list(ndf['Motif perc']))
ndf = df[(df['LC Raw'] >= 50)]
miss_in.append(list(ndf['Miss in motif']))
motif_perc.append(list(ndf['Motif perc']))
return motif_perc, miss_in, all_box
def write_in_motif(self):
df = pd.read_csv(self.an_fpi, sep='\t', index_col=0)
miss_in_motifs, motif_percs, lc_raw = self.lc_blobs(df)
df_dict = {'Miss in motif': miss_in_motifs, 'Motif perc':
motif_percs, 'LC Raw': lc_raw}
df_out = pd.DataFrame(df_dict)
df_out.to_csv(self.miss_fp, sep='\t')
def lc_blobs(self, df):
miss_in_motifs = []
motif_percs = []
lc_raw = []
for i, row in df.iterrows():
print(i)
miss = row['Missing']
seq = row['Sequence']
ind_miss = set([i for i, c in enumerate(miss) if c == 'X'])
if len(ind_miss) > 0:
ind_in = self.get_inds(seq)
miss_in_motifs.append(len(ind_in & ind_miss) / len(ind_miss))
motif_percs.append(len(ind_in)/len(seq))
lc_raw.append(row['LC Raw'])
return miss_in_motifs, motif_percs, lc_raw
def get_inds(self, seq):
lcas = motif_seq.LcSeq(seq, self.k, self.lca, 'lca')
lces = motif_seq.LcSeq(seq, self.k, self.lce, 'lce')
lca_in, lca_out = lcas._get_motif_indexes()
lce_in, lce_out = lces._get_motif_indexes()
ind_in = lca_in.union(lce_in)
return ind_in
def mean_data(self):
mean_mm = [0.15119716529756219, 0.2758867067395091,
0.33919911651251144,
0.38925749618984801, 0.4596892469792353, 0.45675615911402828,
0.4864237185593116, 0.47843336509996348, 0.47722958598203197,
0.52296341132184865, 0.53371100558725326]
std_mm = [0.267896467804773, 0.31001593805679722,
0.29755128257322389,
0.29214897153214725, 0.29618672624311254, 0.28878338867998538,
0.27766447616029249, 0.26516401342522217, 0.24012679453077757,
0.23249365650538631, 0.23073066874878609]
mean_mp = [0.14288089382642194, 0.19447891989162036,
0.2171816720664799,
0.23594776589707467, 0.25346468713519443, 0.26288893104698952,
0.27484725570710161, 0.27239470296870616, 0.26238778404020702,
0.27150317759143594, 0.26612460664234783]
std_mp = [0.14335880427343892, 0.11564355104930381,
0.099416983023802502,
0.090527165333543019, 0.082859300918348588, 0.083315470100230646,
0.08419892402540298, 0.077321014349445147, 0.074297419859518155,
0.064961335129703535, 0.067440855726631221]
return mean_mm, std_mm, mean_mp, std_mp
def main():
ms = MissScore()
ms.plot_all()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,603 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_train/write_train.py | import os
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
class WriteTrain(object):
"""
Concatenate PDB and BC data into a single file
PID, y, seq, len
"""
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.pdb_fpi = os.path.join(data_dp, 'data_pdb', 'pdb_train_cd90.tsv')
self.bc_fpi = os.path.join(data_dp, 'data_bc', 'bc_train_cd90.fasta')
self.fpo = os.path.join(data_dp, 'train.tsv')
def concat_train(self):
bc_pids, bc_seqs = tools_fasta.fasta_to_id_seq(self.bc_fpi)
bc_lens = tools_fasta.get_lengths(bc_seqs)
pdb_df = pd.read_csv(self.pdb_fpi, sep='\t', index_col=0)
pdb_pids = list(pdb_df['Protein ID'])
pdb_seqs = list(pdb_df['Sequence'])
pdb_lens = list(pdb_df['Length'])
pids = bc_pids + pdb_pids
seqs = bc_seqs + pdb_seqs
lens = bc_lens + pdb_lens
y = [0]*len(bc_pids) + [1]*len(pdb_pids)
cols = ['Protein ID', 'y', 'Length', 'Sequence']
df_dict = {'Protein ID': pids, 'Sequence': seqs, 'Length': lens,
'y': y}
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(self.fpo, sep='\t')
def main():
wt = WriteTrain()
wt.concat_train()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,604 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/raw_scores.py | import os
import pandas as pd
from deconstruct_lc.params import lc_labels
from deconstruct_lc import tools_lc
class RawScores(object):
def __init__(self, config):
data_dp = config['fps']['data_dp']
self.train_fp = os.path.join(data_dp, 'train.tsv')
self.param_dp = os.path.join(data_dp, 'params')
self.k1 = config.getint('params', 'k1')
self.k2 = config.getint('params', 'k2')
self.alph = config['params']['alph']
self.all_ids, self.all_seqs, self.all_lens, self.y = self.get_seqs()
def get_seqs(self):
df = pd.read_csv(self.train_fp, sep='\t', index_col=0)
all_ids = list(df['Protein ID'])
all_seqs = list(df['Sequence'])
all_lens = list(df['Length'])
y = list(df['y'])
return all_ids, all_seqs, all_lens, y
def write_lca(self):
for k in range(self.k1, self.k2):
df_dict = {'Protein ID': self.all_ids, 'Length': self.all_lens,
'y': self.y}
print("Now processing LCA raw scores for k = {}".format(k))
fno = 'raw_{}_lca.tsv'.format(k)
fpo = os.path.join(self.param_dp, fno)
if not os.path.exists(fpo):
df = self.create_df_lca(k, df_dict)
df.to_csv(fpo, sep='\t')
def create_df_lca(self, k, df_dict):
lc_labs = lc_labels.GetLabels(k)
k_lcas = lc_labs.create_lcas(self.alph)
for k_lca in k_lcas:
lca = k_lca.split('_')[1]
scores = tools_lc.calc_lca_motifs(self.all_seqs, k, lca)
df_dict[k_lca] = scores
cols = ['Protein ID', 'Length', 'y']+k_lcas
df = pd.DataFrame(df_dict, columns=cols)
return df
def write_lce(self):
for k in range(self.k1, self.k2):
df_dict = {'Protein ID': self.all_ids, 'Length': self.all_lens,
'y': self.y}
print("Now processing LCE raw scores for k = {}".format(k))
fno = 'raw_{}_lce.tsv'.format(k)
fpo = os.path.join(self.param_dp, fno)
if not os.path.exists(fpo):
df = self.create_df_lce(k, df_dict)
df.to_csv(fpo, sep='\t')
def create_df_lce(self, k, df_dict):
lc_labs = lc_labels.GetLabels(k)
k_lces = lc_labs.create_lces(self.all_seqs)
for k_lce in k_lces:
lce = float(k_lce.split('_')[1])
scores = tools_lc.calc_lce_motifs(self.all_seqs, k, lce)
df_dict[k_lce] = scores
cols = ['Protein ID', 'Length', 'y']+k_lces
df = pd.DataFrame(df_dict, columns=cols)
return df | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,605 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/lca_lce/aa_comp.py | from Bio.SeqUtils.ProtParam import ProteinAnalysis
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc import tools_lc
class AaComp(object):
"""
Write a continuous string from each type of LC motif to a single fasta
Use overlapping motifs
"""
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.fdo = os.path.join(data_dp, 'lca_lce')
self.train_fpi = os.path.join(data_dp, 'train.tsv')
self.k = int(config['score']['k'])
self.lca = str(config['score']['lca'])
self.lce = float(config['score']['lce'])
def plot_charge(self):
"""
Result: This is nto working, too much variety
Plot, in the BC dataset, the KRE fraction in in motif vs. out motif.
No, wait. No matter how I fucking do this, the fraction will be higher
because of the reduced alphabet.
"""
bc_seqs = self.get_seqs(1)
lca_counts, seq_kmers = self.seq_lca(bc_seqs)
lca_fracs = self.charge_frac(seq_kmers)
seq_fracs = self.charge_frac(bc_seqs)
diff_fracs = []
for lca_frac, seq_frac in zip(lca_fracs, seq_fracs):
diff_fracs.append(lca_frac - seq_frac)
plt.scatter(seq_fracs, lca_fracs, alpha=0.5)
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.show()
def charge_frac(self, seqs):
cfracs = []
for seq in seqs:
if len(seq) == 0:
cfracs.append(0)
else:
ccount = seq.count('K') + seq.count('E') + seq.count('R')
cfrac = ccount/len(seq)
cfracs.append(cfrac)
return cfracs
def seq_lca(self, seqs):
seq_kmers = []
lca_counts = []
for seq in seqs:
lca_motifs = 0
kmer_str = ''
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lca_motif(kmer, self.lca):
kmer_str += kmer
lca_motifs += 1
lca_counts.append(lca_motifs)
seq_kmers.append(kmer_str)
return lca_counts, seq_kmers
def comp_lc(self):
"""What is the composition inside LCE motifs?
Put all LCE motifs into a single string, and do fractions"""
bc_seqs = self.get_seqs(0)
pdb_seqs = self.get_seqs(1)
bc_seqs = self.get_seqs(0)
pdb_seqs = self.get_seqs(1)
bc_lca = self.seq_lca(bc_seqs)
pdb_lca = self.seq_lca(pdb_seqs)
#aas = 'SGEQAPDTNKR'
#aas = 'ERKPSQTGAND'
aas = 'KRESQPANDGT'
aas_list = [aa for aa in aas]
ind = list(range(len(aas)))
bc_lca_bins = self.get_aa_bins(bc_lca)
print(bc_lca_bins)
pdb_lca_bins = self.get_aa_bins(pdb_lca)
print(pdb_lca_bins)
plt.bar(ind, pdb_lca_bins, color='darkblue', alpha=0.7, label='PDB')
plt.bar(ind, bc_lca_bins, color='darkorange', alpha=0.7, label='BC')
ind = [i + 0.4 for i in ind]
plt.xticks(ind, aas_list)
plt.legend()
plt.xlabel('Amino Acids')
plt.ylabel('Relative Fraction in LCA motifs')
plt.ylim([0, 0.16])
plt.xlim([-1, 12])
plt.show()
def get_aa_bins(self, seq):
#aas = 'SGEQAPDTNKRLHVYFIMCW'
#aas = 'ERKPSQTGAND'
aas = 'KRESQPANDGT'
pa = ProteinAnalysis(seq)
bc_dict = pa.get_amino_acids_percent()
aa_bins = []
for aa in aas:
aa_bins.append(bc_dict[aa])
return aa_bins
def run_seqs(self):
ind = ['LCA', 'LCA & ~LCE', 'LCE', '~LCA & LCE', 'LCA & LCE',
'LCA || LCE']
bc_seqs = self.get_seqs(0)
pdb_seqs = self.get_seqs(1)
fpo = os.path.join(self.fdo, 'lca_bc.fasta')
bc_lca = self.seq_lca(bc_seqs)
self.write_seqs(bc_lca, fpo)
pdb_lca = self.seq_lca(pdb_seqs)
fpo = os.path.join(self.fdo, 'lca_pdb.fasta')
self.write_seqs(pdb_lca, fpo)
def write_seqs(self, seq_str, fpo):
with open(fpo, 'w') as fo:
fo.write('>\n')
fo.write(seq_str)
def get_seqs(self, y):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
df = df[df['y'] == y]
seqs = list(df['Sequence'])
return seqs
def seq_lca_not_lce(self, seqs):
all_kmers = ''
for seq in seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lca_motif(kmer, self.lca):
if not tools_lc.lce_motif(kmer, self.lce):
all_kmers += kmer
return all_kmers
def seq_not_lca_lce(self, seqs):
all_kmers = ''
for seq in seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lce_motif(kmer, self.lce):
if not tools_lc.lca_motif(kmer, self.lca):
all_kmers += kmer
return all_kmers
def seq_lca_and_lce(self, seqs):
all_kmers = ''
for seq in seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lce_motif(kmer, self.lce):
if tools_lc.lca_motif(kmer, self.lca):
all_kmers += kmer
return all_kmers
def seq_lca_or_lce(self, seqs):
all_kmers = ''
for seq in seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lce_motif(kmer, self.lce):
all_kmers += kmer
elif tools_lc.lca_motif(kmer, self.lca):
all_kmers += kmer
return all_kmers
def seq_lca2(self, seqs):
all_kmers = ''
for seq in seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lca_motif(kmer, self.lca):
all_kmers += kmer
return all_kmers
def seq_lce(self, seqs):
all_kmers = ''
for seq in seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lce_motif(kmer, self.lce):
all_kmers += kmer
return all_kmers
def main():
ac = AaComp()
ac.plot_charge()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,606 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_pdb/write_pdb_analysis.py | import os
import pandas as pd
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
from deconstruct_lc.scores.norm_score import NormScore
class PdbAnalysis(object):
def __init__(self, config):
data_dp = config['fps']['data_dp']
pdb_dp = os.path.join(data_dp, 'data_pdb')
self.all_fpi = os.path.join(pdb_dp, 'pdb_all.tsv')
self.an_fpo = os.path.join(pdb_dp, 'pdb_analysis.tsv')
self.k = config['score'].getint('k')
self.alph_lca = config['score'].get('lca')
self.thresh_lce = config['score'].getfloat('lce')
def write_analysis(self):
df = pd.read_csv(self.all_fpi, sep='\t')
print("Size of dataframe before filtering is {}".format(len(df)))
df = df.drop_duplicates(subset=['Sequence', 'Missing'], keep=False)
print("Size of dataframe after filtering is {}".format(len(df)))
df = df.reset_index(drop=True)
df = self.add_scores(df)
df.to_csv(self.an_fpo, sep='\t')
def add_scores(self, df):
seqs = list(df['Sequence'])
miss_seqs = list(df['Missing'])
ns = NormScore()
lc_raw = tools_lc.calc_lc_motifs(seqs, self.k, self.alph_lca, self.thresh_lce)
lc_norms = ns.lc_norm_score(seqs)
lengths = tools_fasta.get_lengths(seqs)
miss_count = self.get_missing(miss_seqs)
df['Length'] = lengths
df['Miss Count'] = miss_count
df['LC Norm'] = lc_norms
df['LC Raw'] = lc_raw
return df
def get_missing(self, miss_seqs):
miss = []
for seq in miss_seqs:
miss.append(seq.count('X'))
return miss | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,607 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/kelil/display_motif.py | import os
from deconstruct_lc import read_config
from deconstruct_lc.scores import norm_score
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
from deconstruct_lc import tools
class Display(object):
def __init__(self, fn_out, color=True):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.k = config['score'].getint('k')
self.lca = config['score'].get('lca')
self.lce = config['score'].getfloat('lce')
self.fp_out = os.path.join(data_dp, 'display', fn_out)
self.color = color
def write_body(self, headers, seqs):
contents = '''
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>LC motifs</title>
</head>
<body>
'''
form_seqs = self.form_seq(seqs)
ns = norm_score.NormScore()
scores = ns.lc_norm_score(seqs)
zip_list = zip(scores, headers, form_seqs)
key_fun = lambda pair: pair[0]
sorted_tup = sorted(zip_list, reverse=True, key=key_fun)
for score, head, seq in sorted_tup:
contents += head
contents += '<br>'
contents += seq
contents += '<br>'
contents += str(score)
contents += '<br><br>'
contents += '''
</body>
</html>
'''
with open(self.fp_out, 'w') as fo:
fo.write(contents)
def form_seq(self, seqs):
form_seqs = []
for seq in seqs:
inds = tools_lc.lc_to_indexes(seq, self.k, self.lca, self.lce)
ranges = list(tools.ints_to_ranges(sorted(list(inds))))
es = self.format_string(seq, ranges)
if self.color:
ns = self.add_colors(es)
form_seqs.append(ns)
else:
form_seqs.append(es)
return form_seqs
def format_string(self, seq, c_ind):
"""
Given a sequence, return the excel formatted color string of the form:
'red, 'sequence region', 'sequence region2', red, sequence region3...
"""
es = '' # excel string
if len(c_ind) > 0:
if c_ind[0][0] != 0:
es += seq[0:c_ind[0][0]]
for i, index in enumerate(c_ind):
es += '<b>' + seq[index[0]:index[1] + 1] + '</b>'
if i != len(c_ind) - 1:
es += seq[index[1] + 1:c_ind[i + 1][0]]
es += seq[c_ind[-1][1] + 1:]
else:
es = seq
return es
def add_colors(self, form_seq):
"""
Given a string that has been formatted with bold, add color tags
ED: blue, RK: red, ST: green QN: orange, AG: just leave black, P: brown
"""
ns = ''
for i, aa in enumerate(form_seq):
if aa == 'S':
if i+10 > len(form_seq):
if 'S' in form_seq[i+2:]:
ns += '<font color=\'blue\'>'+ '<b>' + aa + '</b>' + '</font>'
elif 'S' in form_seq[i-10:i-2]:
ns += '<font color=\'blue\'>' + '<b>' + aa + '</b>' + '</font>'
else:
ns += '<font color=\'red\'>' + '<b>' + aa + '</b>' + '</font>'
elif i-10 < 0:
if 'S' in form_seq[i+2:i+10]:
ns += '<font color=\'blue\'>' + '<b>' + aa + '</b>' + '</font>'
elif 'S' in form_seq[0:i-2]:
ns += '<font color=\'blue\'>' + '<b>' + aa + '</b>' + '</font>'
else:
ns += '<font color=\'red\'>' + '<b>' + aa + '</b>' + '</font>'
else:
if 'S' in form_seq[i+2:i+10]:
ns += '<font color=\'blue\'>' + '<b>' + aa + '</b>' + '</font>'
elif 'S' in form_seq[i-10:i-2]:
ns += '<font color=\'blue\'>' + '<b>' + aa + '</b>' + '</font>'
else:
ns += '<font color=\'red\'>' + '<b>' + aa + '</b>' + '</font>'
else:
ns += aa
return ns
def main():
d = Display('temp')
seq = 'MDEPPLAQPLELNQHSRFIIGSVSEDNSEDEISNLVKLDLLEEKEGSLSPASVGSDTLSDLGISSLQDGLALHIRSSMS'
ns = d.add_colors(seq)
print(ns)
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,608 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/norm_svm.py | import os
import numpy as np
import pandas as pd
from deconstruct_lc.svm import svms
class NormSvm(object):
"""
1. Read each normalized set separately
2. Create a single vector and run both SVM and random forest
3. Use random forest to identify best featuers
"""
def __init__(self, config):
config = config
data_dp = config['fps']['data_dp']
self.solo_dp = os.path.join(data_dp, 'params', 'solo')
self.combo_dp = os.path.join(data_dp, 'params', 'combos', 'norm')
self.oned_fpo = os.path.join(data_dp, 'params', 'oned_svm.tsv')
def oned_svm(self):
solo_fns = os.listdir(self.solo_dp)
combo_fns = os.listdir(self.combo_dp)
df_dict = {'Label': [], 'Accuracy': []}
for combo_fn in combo_fns:
fpi = os.path.join(self.combo_dp, combo_fn)
combo_df = pd.read_csv(fpi, sep='\t', index_col=0)
labels = [label for label in list(combo_df)
if label != 'Protein ID' and label != 'y']
for label in labels:
full_label = '{} {}'.format(combo_fn[5:-4], label)
df_dict['Label'].append(full_label)
norm_scores = combo_df[label]
X = np.array([norm_scores]).T
y = np.array(combo_df['y']).T
clf = svms.linear_svc(X, y)
print(full_label)
df_dict['Accuracy'].append(clf.score(X, y))
for solo_fn in solo_fns:
full_label = solo_fn[5:-4]
print(full_label)
df_dict['Label'].append(full_label)
fpi = os.path.join(self.solo_dp, solo_fn)
solo_df = pd.read_csv(fpi, sep='\t', index_col=0)
norm_scores = solo_df['Norm Scores']
X = np.array([norm_scores]).T
y = np.array(solo_df['y']).T
clf = svms.linear_svc(X, y)
df_dict['Accuracy'].append(clf.score(X, y))
df_out = pd.DataFrame(df_dict, columns=['Label', 'Accuracy'])
df_out.to_csv(self.oned_fpo, sep='\t')
def main():
pass
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,609 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/lca_lce/lca_lce_amounts.py | import os
import numpy as np
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc.svm import svms
from deconstruct_lc import tools_lc
class AmountsTrain(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.train_fpi = os.path.join(data_dp, 'train.tsv')
self.k = int(config['score']['k'])
self.lca = str(config['score']['lca'])
self.lce = float(config['score']['lce'])
def venn_lc(self):
bc_seqs = self.get_seqs(0)
bc_kmers = self.get_counts(bc_seqs)
pdb_seqs = self.get_seqs(1)
pdb_kmers = self.get_counts(pdb_seqs)
bc_tot_kmers = self.count_kmers(bc_seqs)
pdb_tot_kmers = self.count_kmers(pdb_seqs)
ind = ['LCA', 'LCA & ~LCE', 'LCE', '~LCA & LCE', 'LCA & LCE', 'LCA || LCE']
bc_fracs = [item/bc_tot_kmers for item in bc_kmers]
pdb_fracs = [item/pdb_tot_kmers for item in pdb_kmers]
df_dict = {'LCA/LCE': ind, 'BC 6-mers': bc_kmers, 'BC fracs': bc_fracs,
'PDB 6-mers': pdb_kmers, 'PDB fracs': pdb_fracs}
cols = ['LCA/LCE', 'BC 6-mers', 'BC fracs', 'PDB 6-mers', 'PDB fracs']
df = pd.DataFrame(df_dict, columns=cols)
print(df)
def get_counts(self, seqs):
lca_count = sum(tools_lc.calc_lca_motifs(seqs, self.k, self.lca))
lca_not_lce_count = sum(self.count_lca_not_lce(seqs))
lce_count = sum(tools_lc.calc_lce_motifs(seqs, self.k, self.lce))
lce_not_lca_count = sum(self.count_not_lca_lce(seqs))
lca_lce_count = sum(self.count_lca_and_lce(seqs))
lc_count = sum(self.count_lca_or_lce(seqs))
return [lca_count, lca_not_lce_count, lce_count, lce_not_lca_count, lca_lce_count, lc_count]
def count_kmers(self, seqs):
total_kmers = 0
for seq in seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
total_kmers += len(kmers)
return total_kmers
def count_lca_not_lce(self, seqs):
all_counts = []
for seq in seqs:
count = 0
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lca_motif(kmer, self.lca):
if not tools_lc.lce_motif(kmer, self.lce):
count += 1
all_counts.append(count)
return all_counts
def count_not_lca_lce(self, seqs):
all_counts = []
for seq in seqs:
count = 0
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lce_motif(kmer, self.lce):
if not tools_lc.lca_motif(kmer, self.lca):
count += 1
all_counts.append(count)
return all_counts
def count_lca_and_lce(self, seqs):
all_counts = []
for seq in seqs:
count = 0
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
if tools_lc.lce_motif(kmer, self.lce):
if tools_lc.lca_motif(kmer, self.lca):
count += 1
all_counts.append(count)
return all_counts
def count_lca_or_lce(self, seqs):
lc_motifs = tools_lc.calc_lc_motifs(seqs, self.k, self.lca, self.lce)
return lc_motifs
def get_seqs(self, y):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
df = df[df['y'] == y]
seqs = list(df['Sequence'])
return seqs
def sum_to_svm(self):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
seqs = list(df['Sequence'])
y = np.array(df['y']).T
lca_count = tools_lc.calc_lca_motifs(seqs, self.k, self.lca)
lca_not_lce_count = self.count_lca_not_lce(seqs)
lce_count = tools_lc.calc_lce_motifs(seqs, self.k, self.lce)
lce_not_lca_count = self.count_not_lca_lce(seqs)
lca_lce_count = self.count_lca_and_lce(seqs)
lc_count = self.count_lca_or_lce(seqs)
ind = ['LCA', 'LCA & ~LCE', 'LCE', '~LCA & LCE', 'LCA & LCE',
'LCA || LCE']
accuracy = [self.run_svm(lca_count, y), self.run_svm(lca_not_lce_count, y),
self.run_svm(lce_count, y), self.run_svm(lce_not_lca_count, y),
self.run_svm(lca_lce_count, y), self.run_svm(lc_count, y)]
df_dict = {'LCA/LCE': ind, 'Accuracy': accuracy}
cols = ['LCA/LCE', 'Accuracy']
df = pd.DataFrame(df_dict, columns=cols)
print(df)
def run_svm(self, motif_sum, y):
X = np.array([motif_sum]).T
clf = svms.linear_svc(X, y)
return clf.score(X, y)
def main():
at = AmountsTrain()
at.venn_lc()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,610 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/experiment/proteins.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.scores.norm_score import NormScore
class Proteins(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.hex_fpi = os.path.join(data_dp, 'experiment', '180803_HD.xls')
self.tht_fpi = os.path.join(data_dp, 'experiment', '180803_ThT.xls')
self.puncta_fpi = os.path.join(data_dp, 'experiment', 'marcotte_puncta_scores.tsv')
self.sg_ann = os.path.join(data_dp, 'experiment',
'cytoplasmic_stress_granule_annotations.txt')
self.sg_drop_out = os.path.join(data_dp, 'experiment', 'sg_drop_descriptions.tsv')
self.sg_clus_out = os.path.join(data_dp, 'experiment', 'sg_clus_descriptions.tsv')
self.orf_trans = os.path.join(data_dp, 'proteomes', 'orf_trans.fasta')
def tht_stats(self):
tht_df = pd.read_excel(self.tht_fpi, sheetname='Hoja3')
print("There are {} proteins without data".format(
len(tht_df[(tht_df['180708 48h'] == '-')])))
print("There are {} proteins that did not form puncta".format(
len(tht_df[(tht_df['180708 48h'] == 'no')])))
print("There are {} proteins with no* (concentrated in nucleus)".format(
len(tht_df[(tht_df['180708 48h'] == 'no*')])))
def hex_stats(self):
hex_df = pd.read_excel(self.hex_fpi, sheetname='Hoja2')
print("There are {} proteins without data".format(
len(hex_df[(hex_df['180708 48h'] == '-')])))
print("There are {} proteins that did not form puncta".format(
len(hex_df[(hex_df['180708 48h'] == 'no')])))
def no_puncta(self):
print("Proteins that did not form puncta at 48 hours")
hex_df = pd.read_excel(self.hex_fpi, sheetname='Hoja2')
hex_df = hex_df[(hex_df['180708 48h'] == 'no')]
hex_ids = list(hex_df['ORF'])
scores = self.fetch_scores(hex_ids)
df = pd.DataFrame({'ORF': hex_ids, 'LC Score': scores})
df = df.sort_values(by='LC Score', ascending=False)
df = df.reset_index(drop=True)
return df
def yes_puncta_hex(self):
print("Proteins that did not dissolve with hexandiol")
tht_df = pd.read_excel(self.tht_fpi, sheetname='Hoja3')
tht_df = tht_df[(tht_df['180803 48h HD 1h'] == 'yes') | (
tht_df['180803 48h HD 1h'] == 'yes?') | (
tht_df['180803 48h HD 1h'] == 'no?')]
hex_ids = list(tht_df['ORF'])
scores = self.fetch_scores(hex_ids)
df = pd.DataFrame({'ORF': hex_ids, 'LC Score': scores})
df = df.sort_values(by='LC Score', ascending=False)
df = df.reset_index(drop=True)
print(len(df))
return df
def no_puncta_hex(self):
print("Proteins that dissolved with hexandiol")
tht_df = pd.read_excel(self.tht_fpi, sheetname='Hoja3')
tht_df = tht_df[(tht_df['180708 48h'] == 'yes') | (tht_df['180708 48h'] == 'yes?')]
tht_df = tht_df[(tht_df['180803 48h HD 1h'] == 'no') | (tht_df['180803 48h HD 1h'] == 'no*')]
hex_ids = list(set(tht_df['ORF']))
scores = self.fetch_scores(hex_ids)
df = pd.DataFrame({'ORF': hex_ids, 'LC Score': scores})
df = df.sort_values(by='LC Score', ascending=False)
df = df.reset_index(drop=True)
print(len(df))
return df
def yes_tht_stain(self):
print("Proteins that stained with Tht")
tht_df = pd.read_excel(self.tht_fpi, sheetname='Hoja3')
tht_df = tht_df[(tht_df['180809 ThT'] == 'yes')]
tht_ids = list(set(tht_df['ORF']))
scores = self.fetch_scores(tht_ids)
df = pd.DataFrame({'ORF': tht_ids, 'LC Score': scores})
df = df.sort_values(by='LC Score', ascending=False)
df = df.reset_index(drop=True)
print(len(df))
return df
def no_tht_stain(self):
print("Proteins that did not stain with Tht")
tht_df = pd.read_excel(self.tht_fpi, sheetname='Hoja3')
tht_df = tht_df[(tht_df['180809 ThT'] == 'no')]
tht_ids = list(set(tht_df['ORF']))
scores = self.fetch_scores(tht_ids)
df = pd.DataFrame({'ORF': tht_ids, 'LC Score': scores})
df = df.sort_values(by='LC Score', ascending=False)
df = df.reset_index(drop=True)
print(len(df))
return df
def clusters(self):
print("Clusters are yes hexanediol and no Tht")
tht_df = pd.read_excel(self.tht_fpi, sheetname='Hoja3')
tht_df = tht_df[(tht_df['180809 ThT'] == 'no')]
tht_df = tht_df[(tht_df['180803 48h HD 1h'] == 'yes') | (
tht_df['180803 48h HD 1h'] == 'yes?') | (
tht_df['180803 48h HD 1h'] == 'no?')]
tht_ids = list(set(tht_df['ORF']))
scores = self.fetch_scores(tht_ids)
df = pd.DataFrame({'ORF': tht_ids, 'LC Score': scores})
df = df.sort_values(by='LC Score', ascending=False)
df = df.reset_index(drop=True)
print(len(df))
return df
def stress_granules(self):
drop_df = self.no_puncta_hex()
agg_df = self.yes_tht_stain()
clus_df = self.clusters()
sg = pd.read_csv(self.sg_ann, sep='\t')
sg_orfs = list(sg['Gene Systematic Name'])
sg_drop = drop_df[drop_df['ORF'].isin(sg_orfs)]
sg_agg = agg_df[agg_df['ORF'].isin(sg_orfs)]
sg_clus = clus_df[clus_df['ORF'].isin(sg_orfs)]
sequences, genes, orfs, descriptions = tools_fasta.get_yeast_desc_from_ids(self.orf_trans, list(sg_clus['ORF']))
lengths = [len(seq) for seq in sequences]
ns = NormScore()
scores = ns.lc_norm_score(sequences)
ndf = pd.DataFrame({'Descriptions': descriptions, 'Gene': genes,
'Length': lengths, 'ORF': orfs, 'LC Score': scores})
ndf.to_csv(self.sg_clus_out, sep='\t')
sequences, genes, orfs, descriptions = tools_fasta.get_yeast_desc_from_ids(self.orf_trans, list(sg_drop['ORF']))
lengths = [len(seq) for seq in sequences]
ns = NormScore()
scores = ns.lc_norm_score(sequences)
ndf = pd.DataFrame({'Descriptions': descriptions, 'Gene': genes,
'Length': lengths, 'ORF': orfs, 'LC Score': scores})
ndf.to_csv(self.sg_drop_out, sep='\t')
return sg_orfs
def fetch_scores(self, pids):
df = pd.read_csv(self.puncta_fpi, sep='\t')
df = df[df['ORF'].isin(pids)]
df_orfs = set(list(df['ORF']))
print(set(pids) - df_orfs)
return list(df['LC Score'])
def plotting(self):
puncta_hex = self.yes_tht_stain()
npuncta_hex = self.clusters()
plt.hist(puncta_hex['LC Score'], bins=20, range=(-60, 200), alpha=0.5,
normed=True)
plt.hist(npuncta_hex['LC Score'], bins=20, range=(-60, 200), alpha=0.5, normed=True)
plt.show()
def main():
p = Proteins()
p.stress_granules()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,611 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/within_bc/within_bc.py | """
1. For proteins that are found in multiple BCs, is there anything special
about their scores?
Results. May be skewed towards higher scores, but they are spread out,
and there are still around 10 that sit in the PDB section. I would need to
look at this further to see what hypothesis I was trying to test. They do
NOT cluster though
2. Within a BC, is there anything that indicates complementarity?
Composition? Motifs? Composition within motifs?
Results: Scores are spread out - I didn't check by organism though,
there may be something present that a more detailed look could reveal
"""
import configparser
from collections import defaultdict
import os
import pandas as pd
import matplotlib.pyplot as plt
config = configparser.ConfigParser()
cfg_fp = os.path.join(os.path.join(os.path.dirname(__file__), '..',
'config.cfg'))
config.read_file(open(cfg_fp, 'r'))
class WithinBc(object):
def __init__(self):
self.minlen = 100
self.maxlen = 2000
self.fd = os.path.join(config['filepaths']['data_fp'])
self.bc_fp = os.path.join(self.fd, 'scores',
'quickgo_cb_cd90_6_SGEQAPDTNKR_6_1.6_norm.tsv')
self.pdb_fp = os.path.join(self.fd, 'scores',
'pdb_nomiss_cd90_6_SGEQAPDTNKR_6_1.6_norm')
self.bc_ss = os.path.join(self.fd, 'bc_prep', 'quickgo_bc.xlsx')
def get_within(self):
fns = self.get_sheets()
for sheet in fns:
print(sheet)
df_in = pd.read_excel(self.bc_ss, sheetname=sheet)
pids = list(df_in['Protein ID'])
lcas, lces = self.get_scores(pids)
plt.scatter(lcas, lces)
plt.xlim([-20, 100])
plt.ylim([-20, 100])
plt.show()
def get_scores(self, pids):
lcas = []
lces = []
df = pd.read_csv(self.bc_fp, sep='\t')
for pid in pids:
ndf = df[df['Protein ID'] == pid]
if len(ndf) > 0:
lcas.append(list(ndf['LCA Norm'])[0])
lces.append(list(ndf['LCE Norm'])[0])
return lcas, lces
def find_overlap(self):
"""Find proteins that show up in more than one BC. Record the BCs,
organism, protein"""
pids = self.get_overlaps()
df = pd.read_csv(self.bc_fp, sep='\t')
lcas = []
lces = []
for pid in pids:
ndf = df[df['Protein ID'] == pid]
if len(ndf) > 0:
lcas.append(list(ndf['LCA Norm'])[0])
lces.append(list(ndf['LCE Norm'])[0])
plt.scatter(lcas, lces)
plt.xlim([-20, 100])
plt.ylim([-20, 100])
plt.show()
def ss_to_dict(self):
fns = self.get_sheets()
pid_cb = defaultdict(set)
for sheet in fns:
df_in = pd.read_excel(self.bc_ss, sheetname=sheet)
for row in df_in.itertuples():
pid = row[1]
pid_cb[pid].add(sheet)
return pid_cb
def get_overlaps(self):
pid_cb = self.ss_to_dict()
pids = []
for pid in pid_cb:
if len(pid_cb[pid]) >= 2:
pids.append(pid)
return pids
def get_sheets(self):
ex = pd.ExcelFile(self.bc_ss)
sheet_names = ex.sheet_names
return sorted(sheet_names)
def main():
wb = WithinBc()
wb.get_within()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,612 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/scores/norm_score.py | from deconstruct_lc import tools_lc
class NormScore(object):
def __init__(self):
self.k = 6
self.lce = 1.6
self.lca = 'SGEQAPDTNKR'
self.lc_m = 0.06744064704548541
self.lc_b = 16.5
def lc_norm_score(self, seqs):
lens = [len(seq) for seq in seqs]
scores = tools_lc.calc_lc_motifs(seqs, self.k, self.lca, self.lce)
lc_norm = self.norm_function(self.lc_m, self.lc_b, scores, lens)
return lc_norm
def lc_miss_norm(self, seqs, miss_seqs):
"""For PDB chains, do not count the kmer if it has a missing residue"""
lens = [len(seq) for seq in seqs]
scores = tools_lc.calc_lc_motifs_nomiss(seqs, miss_seqs, self.k,
self.lca, self.lce)
lc_norm = self.norm_function(self.lc_m, self.lc_b, scores, lens)
return lc_norm
@staticmethod
def norm_function(m, b, raw_scores, lengths):
norm_scores = []
for raw_score, length in zip(raw_scores, lengths):
norm_score = raw_score - ((m * length) + b)
norm_scores.append(norm_score)
return norm_scores
def main():
pass
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,613 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_stats/pdb_uni_overlap.py | import os
from deconstruct_lc import tools_fasta
from deconstruct_lc import read_config
class Overlap(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.bc90 = os.path.join(data_dp, 'data_bc', 'bc_train_cd90.fasta')
self.pdb90 = os.path.join(data_dp, 'data_pdb', 'pdb_train_cd90.fasta')
self.pdb_chain = os.path.join(data_dp, 'data_pdb', 'outside_data', 'pdb_chain_uniprot.tsv')
def overlap(self):
pdb_uni = self.read_pdb_uni()
cb_ids, cb_seqs = tools_fasta.fasta_to_id_seq(self.bc90)
cb_pdb_unis = {}
cb_pdbs = []
for id in cb_ids:
if id in pdb_uni:
cb_pdb_unis[pdb_uni[id]] = id
cb_pdbs.append(pdb_uni[id])
pdb_ids, pdb_seqs = tools_fasta.fasta_to_id_seq(self.pdb90)
print("Proteins overlapping between the PDB and BC datasets")
for pdb_id in pdb_ids:
if pdb_id in cb_pdbs:
print(pdb_id)
print(cb_pdb_unis[pdb_id])
def read_pdb_uni(self):
pdb_uni = {}
with open(self.pdb_chain, 'r') as fi:
for i in range(0, 2):
next(fi)
for line in fi:
ls = line.split('\t')
pdb = ls[0].upper()
chain = ls[1].upper()
uni = ls[2]
pdb_chain = '{}_{}'.format(pdb, chain)
pdb_uni[uni] = pdb_chain
return pdb_uni
def main():
ol = Overlap()
ol.overlap()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,614 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_pdb/filter_pdb.py | from Bio import SeqIO
import os
from deconstruct_lc import tools_fasta
class PdbFasta(object):
def __init__(self, config):
data_dp = config['fps']['data_dp']
pdb_dp = os.path.join(data_dp, 'data_pdb')
self.minlen = config['dataprep'].getint('minlen')
self.maxlen = config['dataprep'].getint('maxlen')
self.entry_type_fp = os.path.join(pdb_dp, 'outside_data', 'pdb_entry_type.txt')
self.taxonomy_fp = os.path.join(pdb_dp, 'outside_data', 'pdb_chain_taxonomy.tsv')
self.speclist_fp = os.path.join(pdb_dp, 'outside_data', 'speclist.txt')
self.pdb_miss_fp = os.path.join(pdb_dp, 'pdb_all.fasta')
self.pdb_nomiss_fp = os.path.join(pdb_dp, 'pdb_train.fasta')
self.all_dis_fp = os.path.join(pdb_dp, 'all_dis.fasta')
self.all_seq_fp = os.path.join(pdb_dp, 'all_seqs.fasta')
def create_pdb_miss(self):
"""
Apply the following filtering:
Only x-ray
Only eukaryote
Only standard amino acid alphabet
do not apply any missing region or length filtering
"""
diffraction = self.read_diffraction()
eukaryote = self.read_euk_pdb()
new_records = []
with open(self.all_seq_fp, 'r') as seq_fi:
for seq_rec in SeqIO.parse(seq_fi, 'fasta'):
pdb_chain = tools_fasta.id_cleanup(str(seq_rec.id))
pdb = pdb_chain.split('_')[0]
sequence = str(seq_rec.seq)
if pdb_chain in eukaryote:
if pdb in diffraction:
if self.standard_aa(sequence):
new_records.append(seq_rec)
with open(self.pdb_miss_fp, 'w') as seq_fo:
SeqIO.write(new_records, seq_fo, 'fasta')
count = 0
with open(self.pdb_miss_fp, 'r') as handle:
for _ in SeqIO.parse(handle, 'fasta'):
count += 1
print('There are {} records with missing regions'.format(count))
def create_pdb_nomiss(self):
"""
load pdb_miss and apply no missing regions filter, and length filter
"""
pdb_miss = self.get_missing()
new_records = []
with open(self.pdb_miss_fp, 'r') as miss_fi:
for seq_rec in SeqIO.parse(miss_fi, 'fasta'):
pdb_chain = tools_fasta.id_cleanup(str(seq_rec.id))
sequence = str(seq_rec.seq)
prot_len = len(sequence)
if pdb_chain in pdb_miss:
if pdb_miss[pdb_chain] == 0:
if self.minlen <= prot_len <= self.maxlen:
new_records.append(seq_rec)
with open(self.pdb_nomiss_fp, 'w') as seq_fo:
SeqIO.write(new_records, seq_fo, 'fasta')
count = 0
with open(self.pdb_nomiss_fp, 'r') as handle:
for _ in SeqIO.parse(handle, 'fasta'):
count += 1
print('There are {} records without missing regions'.format(count))
def read_euk_pdb(self):
"""
Create a set of PDB IDs that are eukaryotes, ie.
{'3V6M_A', '3WGU_E', '4ITZ_B',...
"""
euks = self._euk_tax()
euk_pdbs = []
with open(self.taxonomy_fp, 'r') as fi:
next(fi)
next(fi)
for line in fi:
ls = line.split()
if ls[2] in euks:
pdb_chain = '{}_{}'.format(ls[0].upper(), ls[1].upper())
euk_pdbs.append(pdb_chain)
return set(euk_pdbs)
def _euk_tax(self):
"""
Create a set of all taxonomic identifiers that are 'E' for eukaryote
ie. {'348046', '160085', '143180',...
"""
tax_org = self._read_speclist()
euks = []
for item in tax_org:
if tax_org[item] == 'E':
euks.append(item)
return set(euks)
def _read_speclist(self):
"""
Read spec list and create a tax: org dictionary, ie. '3320': 'E'
"""
tax_org = {}
with open(self.speclist_fp, 'r') as fi:
for i in range(59):
next(fi)
for line in fi:
ls = line.split()
if len(ls) >= 3:
if ls[2][-1] == ':':
tax = ls[2][0:-1]
org = ls[1]
tax_org[tax] = org
return tax_org
def read_diffraction(self):
"""
Read diffraction file and return a set of PDB IDs that are
from crystal structures. Note this does not include chain info. ie.
{'3S5T', '1F8W', '1PCX',...
"""
xray_ids = []
with open(self.entry_type_fp, 'r') as fi:
for line in fi:
ls = line.split()
pdb_id = ls[0]
method = ls[2]
if method == 'diffraction':
xray_ids.append(pdb_id.upper())
return set(xray_ids)
def get_missing(self):
"""
Create a dictionary with pdb_chain: # missing regions
"""
pdb_miss = {}
with open(self.all_dis_fp, 'r') as dis_fo:
for dis_rec in SeqIO.parse(dis_fo, 'fasta'):
pdb_miss[tools_fasta.id_cleanup(str(dis_rec.id))] = \
self.missing_count(str(dis_rec.seq))
return pdb_miss
def missing_count(self, dis_seq):
return dis_seq.count('X')
def standard_aa(self, sequence):
aas = 'ADKERNTSQYFLIVMCWHGP'
for c in sequence:
if c not in aas:
return False
return True | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,615 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/ran_forest.py | import os
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
class BestFeatures(object):
def __init__(self, config):
data_dp = config['fps']['data_dp']
self.solo_dp = os.path.join(data_dp, 'params', 'solo')
self.combo_dp = os.path.join(data_dp, 'params', 'combos', 'norm')
def ran_forest(self):
X, y, all_labels = self.construct_matrix()
for i in range(18):
clf = RandomForestClassifier(n_estimators=100, random_state=15)
clf = clf.fit(X, y)
feat_imp = clf.feature_importances_
indexes = np.argsort(feat_imp)
X = self.remove_feature(indexes, X)
kf = KFold(n_splits=3, random_state=0, shuffle=True)
scores = cross_val_score(clf, X, y, cv=kf)
print(scores.mean())
for i in list(indexes):
print(all_labels[i])
print()
def remove_feature(self, indexes, X):
a = np.delete(X, [indexes[0]], 1)
return a
def construct_matrix(self):
solo_fns = os.listdir(self.solo_dp)
combo_fns = os.listdir(self.combo_dp)
norm_scores = []
all_labels = []
for combo_fn in combo_fns:
fpi = os.path.join(self.combo_dp, combo_fn)
combo_df = pd.read_csv(fpi, sep='\t', index_col=0)
labels = [label for label in list(combo_df)
if label != 'Protein ID' and label != 'y']
for label in labels:
full_label = '{} {}'.format(combo_fn[5:-4], label)
all_labels.append(full_label)
norm_score = list(combo_df[label])
norm_scores.append(norm_score)
for solo_fn in solo_fns:
full_label = solo_fn[5:-4]
all_labels.append(full_label)
fpi = os.path.join(self.solo_dp, solo_fn)
solo_df = pd.read_csv(fpi, sep='\t', index_col=0)
norm_score = list(solo_df['Norm Scores'])
norm_scores.append(norm_score)
y = np.array(solo_df['y']).T
X = np.array([norm_scores]).T.reshape(6793, 19)
return X, y, all_labels | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,616 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/scores/write_scores.py | import os
import pandas as pd
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc.analysis_bc.write_bc_score import BcScore
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
class WriteNorm(object):
def __init__(self):
config = read_config.read_config()
data = config['fps']['data_dp']
self.train_fpi = os.path.join(data, 'train.tsv')
prot_dp = os.path.join(data, 'proteomes')
self.bc_dp = os.path.join(data, 'bc_analysis')
self.yeast_fp = os.path.join(prot_dp, 'UP000002311_559292_Yeast.fasta')
self.human_fp = os.path.join(prot_dp, 'UP000005640_9606_Human.fasta')
self.fpo = os.path.join(data, 'scores', 'pdb_bc_scores.tsv')
def write_scores(self):
"""Write tsv that is pid, proteome, org, lc score"""
pdb_pids, pdb_proteome, pdb_org, pdb_scores = self.get_pdb()
bc_pids, bc_proteome, bc_org, bc_scores = self.get_bcs()
ypids, yproteome, yorg, yscores = self.get_yeast()
hpids, hproteome, horg, hscores = self.get_human()
pids = pdb_pids + bc_pids + ypids + hpids
proteome = pdb_proteome + bc_proteome + yproteome + hproteome
org = pdb_org + bc_org + yorg + horg
scores = pdb_scores + bc_scores + yscores + hscores
df_dict = {'Protein ID': pids,
'Proteome': proteome,
'Organism': org,
'LC Score': scores}
cols = ['Protein ID', 'Proteome', 'Organism', 'LC Score']
df_out = pd.DataFrame(df_dict, columns=cols)
df_out.to_csv(self.fpo, sep='\t')
def get_pdb(self):
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
pdb_df = df[df['y'] == 1]
pids = list(pdb_df['Protein ID'])
proteome = ['PDB']*len(pids)
org = ['PDB']*len(pids)
seqs = list(pdb_df['Sequence'])
ns = NormScore()
scores = ns.lc_norm_score(seqs)
return pids, proteome, org, scores
def get_bcs(self):
bcs = BcScore()
bc_names = bcs.get_sheets()
pids = []
proteome = []
org = []
scores = []
for bc_name in bc_names:
bc_fp = os.path.join(self.bc_dp, '{}_score.tsv'.format(bc_name))
df = pd.read_csv(bc_fp, sep='\t', index_col=0)
pids += list(df['Protein ID'])
proteome += [bc_name]*len(list(df['Protein ID']))
org += list(df['Organism'])
scores += list(df['LC Score'])
return pids, proteome, org, scores
def get_yeast(self):
pids, seqs = tools_fasta.fasta_to_id_seq(self.yeast_fp)
ns = NormScore()
scores = ns.lc_norm_score(seqs)
proteome = ['Yeast']*len(pids)
org = ['Yeast']*len(pids)
return pids, proteome, org, scores
def get_human(self):
pids, seqs = tools_fasta.fasta_to_id_seq(self.human_fp)
ns = NormScore()
scores = ns.lc_norm_score(seqs)
proteome = ['Human']*len(pids)
org = ['Human']*len(pids)
return pids, proteome, org, scores
class CreateTable(object):
def __init__(self):
config = read_config.read_config()
data = config['fps']['data_dp']
self.fpi = os.path.join(data, 'scores', 'pdb_bc_scores.tsv')
self.prot_fpi = os.path.join(data, 'scores', 'proteomes.tsv')
self.yeast_fpo = os.path.join(data, 'scores', 'yeast_bc.tsv')
self.human_fpo = os.path.join(data, 'scores', 'human_bc.tsv')
self.prot_fpo = os.path.join(data, 'scores', 'prot.tsv')
def write_table(self):
self.create_table('YEAST', self.yeast_fpo)
self.create_table('HUMAN', self.human_fpo)
def create_prot(self):
df = pd.read_csv(self.prot_fpi, sep='\t', index_col=0)
names = ['Human', 'Yeast', 'PDB']
lts = []
ms = []
gts = []
numseq = []
for name in names:
yndf = df[df['Proteome'] == name]
lt, m, gt = self.get_bins(yndf)
lts.append(lt)
ms.append(m)
gts.append(gt)
numseq.append(len(yndf))
df_dict = {'Proteome': names, '< 0': lts, '0-20': ms, '> 20': gts,
'Sequences': numseq}
cols = ['Proteome', '< 0', '0-20', '> 20', 'Sequences']
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(self.prot_fpo, sep='\t')
def create_table(self, org, fpo):
names = []
lts = []
ms = []
gts = []
numseq = []
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
bcs = BcScore()
bc_names = bcs.get_sheets()
for bc_name in bc_names:
ndf = df[df['Proteome'] == bc_name]
yndf = ndf[ndf['Organism'] == org]
if len(yndf) > 0:
lt, m, gt = self.get_bins(yndf)
lts.append(lt)
ms.append(m)
gts.append(gt)
names.append(bc_name)
numseq.append(len(yndf))
df_dict = {'BC Name': names, '< 0': lts, '0-20': ms, '> 20': gts, 'Sequences': numseq}
cols = ['BC Name', '< 0', '0-20', '> 20', 'Sequences']
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(fpo, sep='\t')
def get_bins(self, df):
ndf = df[df['LC Score'] < 0]
lt = len(ndf)/len(df)
ndf = df[(df['LC Score'] >= 0) & (df['LC Score'] <= 20)]
m = len(ndf)/len(df)
ndf = df[df['LC Score'] > 20]
gt = len(ndf)/len(df)
return lt, m, gt
def main():
ct = CreateTable()
ct.create_prot()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,617 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/lc_labels.py | from itertools import combinations
from deconstruct_lc import tools_lc
class GetLabels(object):
def __init__(self, k):
self.k = k
def format_labels(self, lcs):
labels = ['{}_{}'.format(self.k, lc) for lc in lcs]
return labels
def create_lcas(self, alph):
"""
alph should usually be 'SGEQAPDTNKRL'
Return all combinations of the base LCA from 2 to the full length as
a list of strings.
Example: create_lcas('SGE') returns ['k_SG', 'k_SE', 'k_GE', 'Sk_GE']
"""
lcas = []
for i in range(2, len(alph) + 1):
lca_combos = combinations(alph, i)
for lca in lca_combos:
lca_str = ''.join(lca)
lcas.append(lca_str)
lca_labels = self.format_labels(lcas)
return lca_labels
def create_lces(self, all_seqs):
"""
Return all the possible shannon entropies in my data set for the given
k-mer length, rounded up to the nearest 0.1.
"""
all_shannon = set()
for seq in all_seqs:
kmers = tools_lc.seq_to_kmers(seq, self.k)
for kmer in kmers:
s = tools_lc.shannon(kmer)
all_shannon.add(s)
new_scores = []
all_shannon = sorted(list(all_shannon), reverse=True)
for score in all_shannon[1:]:
new_score = self._round_up(score)
new_scores.append(new_score)
new_scores = sorted(list(set(new_scores)), reverse=True)
lce_labels = self.format_labels(new_scores)
return lce_labels
def _round_up(self, score):
"""
Given a float, round to the nearest 10th place, and then format into
string.
"""
new_score = round(score, 1)
if new_score < score:
new_score = new_score + 0.1
new_score = round(new_score, 1) # trailing 0.999..
return new_score
def main():
gl = GetLabels(4)
lcas = gl.create_lcas('SGE')
print(lcas)
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,618 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/experiment/labels.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
class Labels(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.label_dp = os.path.join(data_dp, 'annotations')
self.enz_labels = ['hydrolase', 'isomerase', 'ligase', 'lyase',
'oxidoreductase', 'transferase']
self.labels = ['Pbody', 'RNA_binding', 'cytoplasmic_stress_granule']
def get_enzyme_lists(self):
enz_dict = {}
apps = ['co', 'mc', 'ht']
for fn in self.enz_labels:
orfs = []
for app in apps:
ffn = "{}_activity_annotations_{}.txt".format(fn, app)
ffp = os.path.join(self.label_dp, ffn)
if os.path.exists(ffp):
df = pd.read_csv(ffp, sep='\t', comment='!')
orfs += list(df['Gene Systematic Name'])
enz_dict[fn] = set(orfs)
return enz_dict
def get_labels(self):
lab_dict = {}
apps = ['co', 'mc', 'ht']
for fn in self.labels:
orfs = []
for app in apps:
ffn = "{}_annotations_{}.txt".format(fn, app)
ffp = os.path.join(self.label_dp, ffn)
if os.path.exists(ffp):
df = pd.read_csv(ffp, sep='\t', comment='!')
orfs += list(df['Gene Systematic Name'])
lab_dict[fn] = set(orfs)
return lab_dict
def main():
en = Labels()
print(en.get_labels())
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,619 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_bc/pull_go.py | import os
import requests
import sys
from deconstruct_lc import read_config
class PullGo(object):
def __init__(self, goid, fn):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.goid = goid
self.fn = fn
self.fno = '{}.tsv'.format(self.fn)
self.fpo = os.path.join(data_dp, 'data', 'quickgo', self.fno)
def query_quickgo(self):
requestURL = "https://www.ebi.ac.uk/QuickGO/services/annotation/downloadSearch?" \
"goUsage=descendants&goUsageRelationships=is_a,part_of,occurs_in&" \
"goId={}&evidenceCode=ECO:0000269&evidenceCodeUsage=descendants&" \
"qualifier=part_of,colocalizes_with&geneProductType=protein".format(self.goid)
r = requests.get(requestURL, headers={"Accept": "text/gpad"})
if not r.ok:
r.raise_for_status()
sys.exit()
response_body = r.text
self.write_response(response_body)
return response_body
def write_response(self, response_body):
with open(self.fpo, 'w') as fo:
fo.write(response_body)
def main():
go_terms = {'Cajal_bodies': 'GO:0015030',
'Centrosome': 'GO:0005813',
'Nuclear_Speckles': 'GO:0016607',
'Nucleolus': 'GO:0005730',
'P_Body': 'GO:0000932',
'PML_Body': 'GO:0016605',
'Paraspeckle': 'GO:0042382',
'Nuclear_Stress_Granule': 'GO:0097165',
'Cytoplasmic_Stress_Granule': 'GO:0010494',
'P_granule': 'GO:0043186'}
for fn in go_terms:
goid = go_terms[fn]
pg = PullGo(goid, fn)
if not os.path.exists(pg.fpo):
pg.query_quickgo()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,620 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/write_mb.py | import os
import pandas as pd
from deconstruct_lc.len_norm import mb_len_norm
class WriteMb(object):
"""
Write the m, b normalization parameters for select lca/lce labels
"""
def __init__(self, config):
self.config = config
data_dp = self.config['fps']['data_dp']
self.param_dp = os.path.join(data_dp, 'params')
self.lca_fpi = os.path.join(self.param_dp, 'rep_lca.txt')
self.lce_fpi = os.path.join(self.param_dp, 'top_svm_lce.tsv')
self.mb_solo_fp = os.path.join(self.param_dp, 'mb_solo.tsv')
self.mb_combo_fp = os.path.join(self.param_dp, 'mb_combo.tsv')
self.k1 = self.config.getint('params', 'k1')
self.k2 = self.config.getint('params', 'k2')
def write_mb_solo(self):
lca_labs, lce_labs = self._read_labels()
ln = mb_len_norm.LenNorm(self.config)
df_dict = {'lc label': [], 'm': [], 'b': [], 'pearsons': [],
'pval': [], 'stderr': []}
for lca_lab in lca_labs:
ll = lca_lab.split('_')
k = int(ll[0])
lca = str(ll[1])
m, b, pearsons, pval, stderr = ln.mb_lca(k, lca)
df_dict['lc label'].append(lca_lab)
df_dict = self._fill_dict(m, b, pearsons, pval, stderr, df_dict)
for lce_lab in lce_labs:
ll = lce_lab.split('_')
k = int(ll[0])
lce = float(ll[1])
m, b, pearsons, pval, stderr = ln.mb_lce(k, lce)
df_dict['lc label'].append(lce_lab)
df_dict = self._fill_dict(m, b, pearsons, pval, stderr, df_dict)
cols = ['lc label', 'm', 'b', 'pearsons', 'pval', 'stderr']
df_out = pd.DataFrame(df_dict, columns=cols)
df_out.to_csv(self.mb_solo_fp, sep='\t')
def write_mb_combos(self):
lab_combos = self._lab_matchk()
ln = mb_len_norm.LenNorm(self.config)
for lab in lab_combos:
print(lab)
df_dict = {'LC Type': ['LCA || LCE', 'LCA & LCE', 'LCA & ~LCE',
'~LCA & LCE'],
'm': [], 'b': [], 'pearsons': [], 'pval': [], 'stderr': []}
fno = '{}_{}.tsv'.format(lab[0], lab[1])
fpo = os.path.join(self.param_dp, 'combos', fno)
k, lca, lce = self._get_lca_lce(lab)
m, b, pearsons, pval, stderr = ln.mb_lc(k, lca, lce)
self._fill_dict(m, b, pearsons, pval, stderr, df_dict)
m, b, pearsons, pval, stderr = ln.mb_lca_and_lce(k, lca, lce)
self._fill_dict(m, b, pearsons, pval, stderr, df_dict)
m, b, pearsons, pval, stderr = ln.mb_lca_not_lce(k, lca, lce)
self._fill_dict(m, b, pearsons, pval, stderr, df_dict)
m, b, pearsons, pval, stderr = ln.mb_not_lca_lce(k, lca, lce)
self._fill_dict(m, b, pearsons, pval, stderr, df_dict)
cols = ['LC Type', 'm', 'b', 'pearsons', 'pval', 'stderr']
df_out = pd.DataFrame(df_dict, columns=cols)
df_out.to_csv(fpo, sep='\t')
def _read_labels(self):
lce_df = pd.read_csv(self.lce_fpi, sep='\t')
lce_labs = list(lce_df['Label'])
lca_labs = []
with open(self.lca_fpi, 'r') as fpi:
for line in fpi:
lca_labs.append(line.strip())
return lca_labs, lce_labs
def _fill_dict(self, m, b, pearsons, pval, stderr, df_dict):
df_dict['m'].append(m)
df_dict['b'].append(b)
df_dict['pearsons'].append(pearsons)
df_dict['pval'].append(pval)
df_dict['stderr'].append(stderr)
return df_dict
def _get_lca_lce(self, combo_label):
lca_ls = combo_label[1].split('_')
k = int(lca_ls[0])
lca = str(lca_ls[1])
lce_ls = combo_label[0].split('_')
lce = float(lce_ls[1])
return k, lca, lce
def _lab_matchk(self):
lab_combos = self._label_combos()
lab_k_combos = []
for item in lab_combos:
k1 = item[0].split('_')[0]
k2 = item[1].split('_')[0]
if k1 == k2:
lab_k_combos.append(item)
return lab_k_combos
def _label_combos(self):
lca_labs, lce_labs = self._read_labels()
combos = []
for lce in lce_labs:
for lca in lca_labs:
combos.append((lce, lca))
return combos | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,621 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_params/top_aa.py | import os
import pandas as pd
from deconstruct_lc import read_config
class TopAa(object):
"""Find the most important amino acids in the LCA"""
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
params_dp = os.path.join(data_dp, 'params')
self.fpi = os.path.join(params_dp, 'top_svm_lca.tsv')
def top_aa(self):
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
labels = df['Label']
aas = {}
for label in labels:
lab = label.split('_')[1]
for aa in lab:
if aa in aas:
aas[aa] += 1
else:
aas[aa] = 1
naas = {}
for aa in aas:
naas[aa] = aas[aa]/300
self.dict_to_df(naas)
def dict_to_df(self, adict):
vals = []
aas = []
for item in adict:
vals.append(adict[item])
aas.append(item)
df = pd.DataFrame({'AA': aas, 'Fraction': vals})
result = df.sort(['Fraction'], ascending=False)
print(result)
def main():
taa = TopAa()
taa.top_aa()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,622 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/len_norm/mb_len_norm.py | import os
import pandas as pd
from scipy.stats import linregress
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
class LenNorm(object):
"""
Note that the linear regression algorithm returns the following:
m, b, pearsons correlation coefficient, p-value (assuming no slope),
standard error of the estimated gradient
"""
def __init__(self, config):
pdb_dp = os.path.join(config['fps']['data_dp'], 'pdb_prep')
self.pdb_fp = os.path.join(pdb_dp, 'pdb_norm_cd100.tsv')
self.seqs = self.read_seqs()
self.lens = tools_fasta.get_lengths(self.seqs)
def read_seqs(self):
df = pd.read_csv(self.pdb_fp, sep='\t', index_col=0)
seqs = list(df['Sequence'])
return seqs
def mb_lca(self, k, lca):
"""LCA"""
scores = tools_lc.calc_lca_motifs(self.seqs, k, lca)
lr = linregress(self.lens, scores)
return lr
def mb_lce(self, k, lce):
"""LCE"""
scores = tools_lc.calc_lce_motifs(self.seqs, k, lce)
lr = linregress(self.lens, scores)
return lr
def mb_lc(self, k, lca, lce):
"""LCA || LCE"""
scores = tools_lc.calc_lc_motifs(self.seqs, k, lca, lce)
lr = linregress(self.lens, scores)
return lr
def mb_lca_and_lce(self, k, lca, lce):
"""LCA & LCE"""
scores = []
for seq in self.seqs:
scores.append(tools_lc.count_lca_and_lce(seq, k, lca, lce))
lr = linregress(self.lens, scores)
return lr
def mb_lca_not_lce(self, k, lca, lce):
"""LCA & ~LCE"""
scores = []
for seq in self.seqs:
scores.append(tools_lc.count_lca_not_lce(seq, k, lca, lce))
lr = linregress(self.lens, scores)
return lr
def mb_not_lca_lce(self, k, lca, lce):
"""~LCA & LCE"""
scores = []
for seq in self.seqs:
scores.append(tools_lc.count_not_lca_lce(seq, k, lca, lce))
lr = linregress(self.lens, scores)
return lr
def main():
config = read_config.read_config()
k = int(config['score']['k'])
lca = str(config['score']['lca'])
lce = float(config['score']['lce'])
ln = LenNorm(config)
lr = ln.mb_lc(k, lca, lce)
print("The slope is {} and the intercept is {}".format(lr[0], lr[1]))
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,623 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/display/display.py | import os
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc.scores import norm_score
from deconstruct_lc import tools_lc
from deconstruct_lc import tools
class Display(object):
"""
input a sequence, a list of sequences, or a fasta file.
Create an html file that will put the LC motifs in bold
Create another html file that will highlight charge
Create another html file that will highlight Q/N
Create another html file that will highlight aromatics
Output score
1. Just write html page with sequences and score
"""
def __init__(self):
config = read_config.read_config()
self.data_dp = config['fps']['data_dp']
self.bc_dp = os.path.join(self.data_dp, 'bc_analysis', 'P_Body_score.tsv')
self.fp_out = os.path.join(self.data_dp, 'display', 'Pbody_human.html')
self.k = config['score'].getint('k')
self.lca = config['score'].get('lca')
self.lce = config['score'].getfloat('lce')
def write_body(self):
contents = '''
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Hello</title>
</head>
<body>
'''
form_seqs, scores = self.read_seq()
sort_scores, sort_form_seqs = tools.sort_list_by_second_list(scores, form_seqs)
for seq, score in zip(sort_form_seqs, sort_scores):
contents += seq
contents += '<br>'
contents += str(score)
contents += '<br>'
contents += '''
</body>
</html>
'''
with open(self.fp_out, 'w') as fo:
fo.write(contents)
def read_seq(self):
df = pd.read_csv(self.bc_dp, sep='\t', index_col=0)
df = df[df['Organism'] == 'HUMAN']
seqs = df['Sequence']
scores = list(df['LC Score'])
form_seqs = []
for seq in seqs:
inds = tools_lc.lc_to_indexes(seq, self.k, self.lca, self.lce)
ranges = list(tools.ints_to_ranges(sorted(list(inds))))
es = self.format_string(seq, ranges)
ns = self.add_colors(es)
#ns = self.color_aromatics(es)
form_seqs.append(ns)
return form_seqs, scores
def format_string(self, seq, c_ind):
"""
Given a sequence, return the excel formatted color string of the form:
'red, 'sequence region', 'sequence region2', red, sequence region3...
"""
es = '' # excel string
if len(c_ind) > 0:
if c_ind[0][0] != 0:
es += seq[0:c_ind[0][0]]
for i, index in enumerate(c_ind):
es += '<b>' + seq[index[0]:index[1] + 1] + '</b>'
if i != len(c_ind) - 1:
es += seq[index[1] + 1:c_ind[i + 1][0]]
es += seq[c_ind[-1][1] + 1:]
else:
es = seq
return es
def add_colors(self, form_seq):
"""
Given a string that has been formatted with bold, add color tags
ED: blue, RK: red, ST: green QN: orange, AG: just leave black, P: brown
"""
ns = ''
for aa in form_seq:
if aa == 'E' or aa == 'D':
ns += '<font color=\'blue\'>' + aa + '</font>'
elif aa == 'R' or aa == 'K':
ns += '<font color=\'red\'>' + aa + '</font>'
elif aa == 'Q' or aa == 'N':
ns += '<font color=\'orange\'>' + aa + '</font>'
elif aa == 'S' or aa == 'T':
ns += '<font color=\'green\'>' + aa + '</font>'
elif aa == 'P':
ns += '<font color=\'brown\'>' + aa + '</font>'
else:
ns += aa
return ns
def color_aromatics(self, form_seq):
ns = ''
for aa in form_seq:
if aa == 'Y' or aa == 'F' or aa == 'W':
ns += '<font color=\'blue\'>' + aa + '</font>'
elif aa == 'R' or aa == 'K':
ns += '<font color=\'red\'>' + aa + '</font>'
else:
ns += aa
return ns
def main():
seq = 'MHQQHSKSENKPQQQRKKFEGPKREAILDLAKYKDSKIRVKLMGGKLVIGVLKGYDQLMNLVLDDTVEYMSNPDDENNTELISKNARKLGLTVIRGTILVSLSSAEGSDVLYMQK'
d = Display()
d.write_body()
#inds = tools_lc.lc_to_indexes(seq, d.k, d.lca, d.lce)
#ranges = list(tools.ints_to_ranges(sorted(list(inds))))
#es = d.format_string(seq, ranges)
#ns = d.add_colors(es)
#print(ns)
if __name__ == '__main__':
main()
| {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,624 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/motif_seq.py | from deconstruct_lc import tools_lc
class LcSeq(object):
"""Tools for exploring the sequence inside and outside of motifs"""
def __init__(self, sequence, k, lc, lctype):
self.sequence = sequence
self.k = k
self.lc = lc
self.lctype = lctype
def overlapping_kmer_in_motif(self):
"""Counts overlapping composition"""
inside_seq = []
outside_seq = []
kmers = tools_lc.seq_to_kmers(self.sequence, self.k)
for kmer in kmers:
if self.lctype == 'lca':
if tools_lc.lca_motif(kmer, self.lc):
inside_seq.append(kmer)
else:
outside_seq.append(kmer)
elif self.lctype == 'lce':
if tools_lc.lce_motif(kmer, self.lc):
inside_seq.append(kmer)
else:
outside_seq.append(kmer)
else:
raise Exception("lctype must be lca or lce")
return inside_seq, outside_seq
def overlapping_seq_in_motif(self):
"""Counts overlapping composition"""
inside_seq = ''
outside_seq = ''
kmers = tools_lc.seq_to_kmers(self.sequence, self.k)
for kmer in kmers:
if self.lctype == 'lca':
if tools_lc.lca_motif(kmer, self.lc):
inside_seq += kmer
else:
outside_seq += kmer
elif self.lctype == 'lce':
if tools_lc.lce_motif(kmer, self.lc):
inside_seq += kmer
else:
outside_seq += kmer
else:
raise Exception("lctype must be lca or lce")
return inside_seq, outside_seq
def list_motifs(self):
motifs = []
kmers = tools_lc.seq_to_kmers(self.sequence, self.k)
for kmer in kmers:
if self.lctype == 'lca':
if tools_lc.lca_motif(kmer, self.lc):
motifs.append(kmer)
elif self.lctype == 'lce':
if tools_lc.lce_motif(kmer, self.lc):
motifs.append(kmer)
return motifs
def seq_in_motif(self):
ind_in, ind_out = self._get_motif_indexes()
seq_in = ''.join([self.sequence[i] for i in ind_in])
seq_out = ''.join([self.sequence[i] for i in ind_out])
return seq_in, seq_out
def _get_motif_indexes(self):
kmers = tools_lc.seq_to_kmers(self.sequence, self.k)
ind_in = set()
for i, kmer in enumerate(kmers):
if self.lctype == 'lca':
if tools_lc.lca_motif(kmer, self.lc):
for j in range(i, i + self.k):
ind_in.add(j)
elif self.lctype == 'lce':
if tools_lc.lce_motif(kmer, self.lc):
for j in range(i, i + self.k):
ind_in.add(j)
else:
raise Exception("lctype must be lca or lce")
ind_out = set(list(range(len(self.sequence)))) - ind_in
return ind_in, ind_out
def main():
k = 6
lc = 'SEQAPDTNKR'
lctype = 'lca'
#k = 6
#lc = 1.6
#lctype = 'lce'
seq = 'RSQLTSLEKDCSLRAIEKNDDNSCRNPEHTDVIDELEEEEDIDTK'
print(seq[2])
ls = LcSeq(seq, k, lc, lctype)
ind_in, ind_out = ls._get_motif_indexes()
print(ind_in)
print(ind_out)
seq_in, seq_out = ls.seq_in_motif()
print(seq_in)
print(seq_out)
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,625 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/svm/svms.py | """
Created by Shelly DeForte, Michnick Lab, University of Montreal 2017-2018
https://github.com/shellydeforte/deconstruct_lc/
"""
from sklearn.svm import SVC
def smooth_rbf(X, y):
clf = SVC(kernel='rbf',
C=0.1,
cache_size=500,
class_weight=None,
random_state=0,
decision_function_shape='ovr',
gamma='auto',
max_iter=-1,
probability=False,
shrinking=True,
tol=0.001,
verbose=False)
clf.fit(X, y)
return clf
def linear_svc(X, y):
clf = SVC(kernel='linear',
C=1,
cache_size=500,
class_weight=None,
random_state=None,
decision_function_shape='ovr',
gamma='auto',
max_iter=-1,
probability=False,
shrinking=True,
tol=.001,
verbose=False)
clf.fit(X, y)
return clf | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,626 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/len_norm/plot_len_norm.py | import matplotlib.pyplot as plt
import numpy as np
import os
import pandas as pd
from deconstruct_lc import read_config
class PlotLenNorm(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
pdb_an_dp = os.path.join(data_dp, 'pdb_analysis')
self.fpi = os.path.join(pdb_an_dp, 'pdb_len_norm.tsv')
self.lc_m = 0.066213297264721263
self.lc_b = 1.7520712972708843
self.lc_b_up = 16.5
self.grey_b = 36.5
def plot_all(self):
fig = plt.figure(figsize=(10, 3))
ax1 = fig.add_subplot(121)
self.plot_scatter(ax1)
ax2 = fig.add_subplot(122)
self.plot_nomiss(ax2)
ax2.yaxis.set_label_position("right")
fig.subplots_adjust(hspace=0, wspace=0)
fig.tight_layout()
plt.show()
def plot_scatter(self, ax):
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
lens = list(df['Length'])
raw_scores = list(df['score'])
ax.scatter(lens, raw_scores, alpha=0.1, color='darkblue')
self.plot_lines()
ax.set_xlim([0, 1500])
ax.set_ylim([0, 150])
ax.set_xlabel('Protein sequence length', size=12)
ax.set_ylabel('LC Motifs', size=12)
def plot_nomiss(self, ax):
"""Show that the PDB norm dataset moves below the trendline when you
don't count missing residues"""
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
lens = list(df['Length'])
raw_scores = list(df['nomiss_score'])
ax.scatter(lens, raw_scores, alpha=0.1, color='darkblue')
self.plot_lines()
ax.set_xlim([0, 1500])
ax.set_ylim([0, 150])
ax.set_xlabel('Protein sequence length', size=12)
ax.set_ylabel('LC Motifs - No Missing Residues', size=12)
plt.tick_params(axis='both', left='on', top='on', right='on',
bottom='on', labelleft='off', labeltop='off',
labelright='on', labelbottom='on')
def plot_lines(self):
x = np.arange(0, 1500, 0.01)
y1 = self.plot_line(self.lc_m, self.lc_b, x)
y2 = self.plot_line(self.lc_m, self.lc_b_up, x)
y3 = self.plot_line(self.lc_m, self.grey_b, x)
plt.plot(x, y1, color='black', lw=2)
plt.plot(x, y2, color='black', lw=2, linestyle='--')
plt.plot(x, y3, color='grey', lw=2)
plt.xlim([0, 1500])
plt.ylim([0, 150])
def plot_line(self, m, b, x):
y = m*x + b
return y
def main():
pln = PlotLenNorm()
pln.plot_all()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,627 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/chi2/create_contingency.py | import os
import pandas as pd
from deconstruct_lc import read_config
class BcProteome(object):
"""Create contingency tables for BC data vs. proteome, with BC prtoteins
removed from the proteome"""
def __init__(self, bc, organism):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
scores_dp = os.path.join(data_dp, 'scores')
self.bc = bc
self.organism = organism
self.fpi = os.path.join(scores_dp, 'pdb_bc_scores.tsv')
def get_cont_table(self):
"""Organism can be 'Human', 'Yeast'"""
bc_df = self.get_bc()
prot_df = self.get_proteome()
bc_counts = get_bins(bc_df)
prot_counts = get_bins(prot_df)
print('Returning low, med, high of bc, followed by proteome background')
return bc_counts, prot_counts
def get_bc_ids(self):
"""
Given the proteome label and the BC label, return the BC Uniprot IDs
"""
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
bc_ids = list(set(df[(df['Proteome'] == self.bc) & (df['Organism'] == self.organism)]['Protein ID']))
return bc_ids
def get_proteome(self):
"""
Given the proteome label and the BC label, return the proteome
scores minus the values that were in the BC.
"""
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
bc_ids = self.get_bc_ids()
df = df[(df['Organism'] == self.organism) & (df['Proteome'] == self.organism)]
df = df[~df['Protein ID'].isin(bc_ids)]
return df
def get_bc(self):
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
df = df[(df['Organism'] == self.organism.upper()) & (df['Proteome'] == self.bc)]
return df
def get_bc_cats(self):
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
bcs = list(set(df['Proteome']))
print(bcs)
class Marcotte(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.puncta = os.path.join(data_dp, 'experiment', 'marcotte_puncta_scores.tsv')
self.nopuncta = os.path.join(data_dp, 'experiment', 'marcotte_nopuncta_scores.tsv')
def get_cont_table(self):
puncta_df = pd.read_csv(self.puncta, sep='\t', index_col=0)
nopuncta_df = pd.read_csv(self.nopuncta, sep='\t', index_col=0)
puncta_counts = get_bins(puncta_df)
nopuncta_counts = get_bins(nopuncta_df)
print('Returning low, med, high of puncta, followed by nopuncta')
return puncta_counts, nopuncta_counts
def get_bins(df):
ndf = df[df['LC Score'] < 0]
lt = len(ndf)
ndf = df[(df['LC Score'] >= 0) & (df['LC Score'] <= 20)]
m = len(ndf)
ndf = df[df['LC Score'] > 20]
gt = len(ndf)
counts = (lt, m, gt)
return counts
def main():
m = Marcotte()
puncta, nopuncta = m.get_cont_table()
print(puncta)
print(nopuncta)
bc = BcProteome('Nucleolus', 'Yeast')
bc_counts, prot_counts = bc.get_cont_table()
print(bc_counts)
print(prot_counts)
bc.get_bc_cats()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,628 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/experiment/write_details.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc.experiment.labels import Labels
class WriteDetails(object):
"""
ORF, Gene, LC Score, Length, Description, Stress Granule, P body,
'hydrolase', 'isomerase', 'ligase', 'lyase', 'oxidoreductase', 'transferase',
RNA binding
"""
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.tht_fpi = os.path.join(data_dp, 'experiment', '180803_ThT.xls')
self.orf_trans = os.path.join(data_dp, 'proteomes', 'orf_trans.fasta')
self.desc_fpo = os.path.join(data_dp, 'experiment', 'full_descriptions.tsv')
def read_files(self):
df_dict = {'ORF': [], 'Gene': [], 'LC Score': [], 'Length': [],
'Description': [], 'cytoplasmic_stress_granule': [], 'Pbody': [],
'hydrolase': [], 'isomerase': [], 'ligase': [],
'lyase': [], 'oxidoreductase': [], 'transferase': [], 'RNA_binding': []}
cols = ['Gene', 'ORF', 'LC Score', 'Length', 'Description', 'cytoplasmic_stress_granule',
'Pbody', 'hydrolase', 'isomerase', 'ligase', 'lyase', 'oxidoreductase',
'transferase', 'RNA_binding']
l = Labels()
enz_dict = l.get_enzyme_lists()
lab_dict = l.get_labels()
tht_df = pd.read_excel(self.tht_fpi, sheetname='Hoja3')
for i, row in tht_df.iterrows():
df_dict['ORF'].append(row['ORF'])
df_dict['Gene'].append(row['plate 1'])
length, desc, score = self.fetch_seq(row['ORF'])
df_dict['Length'].append(length)
df_dict['Description'].append(desc)
df_dict['LC Score'].append(score)
df_dict = self.fetch_labels(row['ORF'], enz_dict, lab_dict, df_dict)
df_out = pd.DataFrame(df_dict, columns=cols)
df_out.to_csv(self.desc_fpo, sep='\t')
def fetch_seq(self, orf):
result = tools_fasta.get_one_yeast_desc(self.orf_trans, orf)
if result:
ns = NormScore()
seq = result[0]
score = ns.lc_norm_score([seq])[0]
length = len(seq)
desc = result[1]
return length, desc, score
else:
raise Exception("pid not present in fasta file")
def fetch_labels(self, orf, enz_dict, lab_dict, df_dict):
enzymes = ['hydrolase', 'isomerase', 'ligase', 'lyase',
'oxidoreductase', 'transferase']
labels = ['RNA_binding', 'cytoplasmic_stress_granule', 'Pbody']
for enz in enzymes:
if orf in enz_dict[enz]:
df_dict[enz].append('yes')
else:
df_dict[enz].append('no')
for lab in labels:
if orf in lab_dict[lab]:
df_dict[lab].append('yes')
else:
df_dict[lab].append('no')
return df_dict
def main():
wd = WriteDetails()
wd.read_files()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,629 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/params/raw_top.py | import os
import pandas as pd
class RawTop(object):
def __init__(self, config):
self.config = config
data_dp = self.config['fps']['data_dp']
self.param_dp = os.path.join(data_dp, 'params')
self.k1 = self.config.getint('params', 'k1')
self.k2 = self.config.getint('params', 'k2')
def write_top(self):
lca_fps, lce_fps = self.get_fps()
lca_fpo = os.path.join(self.param_dp, 'top_svm_lca.tsv')
lce_fpo = os.path.join(self.param_dp, 'top_svm_lce.tsv')
lca_dict = self.get_top(lca_fps)
lce_dict = self.get_top(lce_fps)
cols = ['Label', 'SVM score']
lca_df = pd.DataFrame(lca_dict, columns=cols)
lca_df.to_csv(lca_fpo, sep='\t')
lce_df = pd.DataFrame(lce_dict, columns=cols)
lce_df.to_csv(lce_fpo, sep='\t')
def get_top(self, all_fps):
df_dict = {'Label': [], 'SVM score': []}
for fp in all_fps:
df = pd.read_csv(fp, sep='\t', index_col=0)
ndf = df[df['SVM score'] > 0.82]
df_dict['Label'] += list(ndf['Label'])
df_dict['SVM score'] += list(ndf['SVM score'])
return df_dict
def get_fps(self):
lca_fps = []
lce_fps = []
for k in range(self.k1, self.k2):
lca_fpo = os.path.join(self.param_dp, 'svm_{}_lca.tsv'.format(k))
lce_fpo = os.path.join(self.param_dp, 'svm_{}_lce.tsv'.format(k))
lca_fps.append(lca_fpo)
lce_fps.append(lce_fpo)
return lca_fps, lce_fps
| {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,630 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/data_stats/len_comp.py | import os
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from Bio.SeqUtils.ProtParam import ProteinAnalysis
from deconstruct_lc import read_config
from deconstruct_lc.svm import svms
class LenComp(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.aas = 'SGEQAPDTNKRLHVYFIMCW'
self.lca = config['score'].get('lca')
self.train_fp = os.path.join(data_dp, 'train.tsv')
self.comp_fp = os.path.join(data_dp, 'len_comp', 'train_comp.tsv')
def plot_lencomp(self):
plt.subplot(2, 1, 1)
self.plot_len()
plt.subplot(2, 1, 2)
self.plot_comp()
plt.subplots_adjust(hspace=0.5)
plt.show()
def plot_len(self):
df_train = pd.read_csv(self.train_fp, sep='\t', index_col=0)
bc_lens = list(df_train[df_train['y'] == 0]['Length'])
pdb_lens = list(df_train[df_train['y'] == 1]['Length'])
cb_heights, cb_bins = np.histogram(bc_lens, bins=20, range=(0,2000))
cbn_heights = cb_heights / sum(cb_heights)
pdb_heights, pdb_bins = np.histogram(pdb_lens, bins=20, range=(0,
2000))
pdbn_heights = pdb_heights / sum(pdb_heights)
plt.bar(pdb_bins[:-1], pdbn_heights, width=(max(pdb_bins) - min(
pdb_bins)) / len(pdb_bins), color="darkblue", alpha=0.7,
label='PDB')
plt.bar(cb_bins[:-1], cbn_heights, width=(max(cb_bins) - min(
cb_bins)) / len(cb_bins), color="orangered", alpha=0.7,
label='BC')
plt.xlabel('Protein Length', size=12)
plt.ylabel('Relative Fraction', size=12)
plt.legend()
def plot_comp(self):
df_train = pd.read_csv(self.train_fp, sep='\t', index_col=0)
bc_seqs = list(df_train[df_train['y'] == 0]['Sequence'])
pdb_seqs = list(df_train[df_train['y'] == 1]['Sequence'])
aas_list = [aa for aa in self.aas]
ind = range(len(self.aas))
pdb_seq = ''
for seq in pdb_seqs:
pdb_seq += seq
cb_seq = ''
for seq in bc_seqs:
cb_seq += seq
an_pdb_seq = ProteinAnalysis(pdb_seq)
pdb_dict = an_pdb_seq.get_amino_acids_percent()
an_cb_seq = ProteinAnalysis(cb_seq)
cb_dict = an_cb_seq.get_amino_acids_percent()
pdb_bins = []
cb_bins = []
for aa in aas_list:
pdb_bins.append(pdb_dict[aa])
cb_bins.append(cb_dict[aa])
plt.bar(ind, pdb_bins, color='darkblue', alpha=0.7, label='PDB',
align='center')
plt.bar(ind, cb_bins, color='orangered', alpha=0.7,
label='BC', align='center')
plt.xticks(ind, aas_list)
plt.xlim([-1, len(self.aas)])
plt.legend()
plt.xlabel('Amino Acids', size=12)
plt.ylabel('Relative Fraction', size=12)
def svm_comp(self):
df_train = pd.read_csv(self.comp_fp, sep='\t', index_col=0)
y = np.array(df_train['y']).T
scores = []
for aa in self.aas:
cols = [aa]
X = np.array(df_train[cols])
lin_clf = svms.linear_svc(X, y)
score = lin_clf.score(X, y)
scores.append(score)
print("The mean accuracy is {} and standard deviation is {} for the "
"fraction of each amino acid used separately to "
"classify.".format(np.mean(scores), np.std(scores)))
all_cols = [aa for aa in self.aas]
X = np.array(df_train[all_cols])
rbf_clf = svms.smooth_rbf(X, y)
score = rbf_clf.score(X, y)
print("The accuracy score for the fraction of all amino acids used "
"to classify is {}".format(score))
def svm_len(self):
df_train = pd.read_csv(self.train_fp, sep='\t', index_col=0)
y = np.array(df_train['y']).T
X = np.array(df_train[['Length']])
lin_clf = svms.linear_svc(X, y)
print("The accuracy score for the length is {}".format(lin_clf.score(X, y)))
def write_aa_comp(self):
cols = ['Protein ID', 'y'] + [aa for aa in self.aas]
df_train = pd.read_csv(self.train_fp, sep='\t', index_col=0)
bc_seqs = list(df_train[df_train['y'] == 0]['Sequence'])
pdb_seqs = list(df_train[df_train['y'] == 1]['Sequence'])
df_dict = dict()
for aa in self.aas:
df_dict[aa] = []
df_dict['y'] = list(df_train['y'])
df_dict['Protein ID'] = list(df_train['Protein ID'])
for bc_seq in bc_seqs:
a_bc_seq = ProteinAnalysis(bc_seq)
bc_aas = a_bc_seq.get_amino_acids_percent()
for aa in self.aas:
df_dict[aa].append(bc_aas[aa])
for pdb_seq in pdb_seqs:
a_pdb_seq = ProteinAnalysis(pdb_seq)
pdb_aas = a_pdb_seq.get_amino_acids_percent()
for aa in self.aas:
df_dict[aa].append(pdb_aas[aa])
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(self.comp_fp, sep='\t')
def main():
lc = LenComp()
lc.plot_lencomp()
#lc.write_aa_comp()
lc.svm_comp()
lc.svm_len()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,631 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/lp/lp_proteins.py | from deconstruct_lc.scores.norm_score import NormScore
from deconstruct_lc import tools_fasta
from deconstruct_lc import tools_lc
class CheckPrDs(object):
def __init__(self):
self.fasta_fpi = 'C:\LP\lps_proteins.fasta'
self.k = 6
self.lce = 1.6
self.lca = 'SGEQAPDTNKR'
def read_fasta(self):
pids, seqs = tools_fasta.fasta_to_id_seq(self.fasta_fpi)
norm = NormScore()
# ent1[211:457]
ent1 = seqs[0]
#print(ent1[211:457])
ent1wo = ent1[:211] + ent1[457:]
#print(norm.lc_norm_score([ent1wo]))
#print(norm.lc_norm_score([ent1]))
# ent2[224:616]
ent2 = seqs[1]
#print(ent2[224:616])
ent2wo = ent2[:224] + ent2[616:]
#print(norm.lc_norm_score([ent2wo]))
# yap1801[351:638]
yap1801 = seqs[2]
#print(yap1801[351:638])
yap1801wo = yap1801[:351] + yap1801[638:]
#print()
#print(norm.lc_norm_score([yap1801]))
#print(norm.lc_norm_score([yap1801wo]))
# yap1802[319:569]
yap1802 = seqs[3]
#print(yap1802[319:569])
yap1802wo = yap1802[:319] + yap1802[569:]
#print(norm.lc_norm_score([yap1802wo]))
# sla1[954:1244]
sla1 = seqs[4]
print(len(sla1))
print(sla1[954:1244])
print()
ns = tools_lc.display_lc(sla1, self.k, self.lca, self.lce)
print(sla1)
print(ns)
sla1wo = sla1[:954] + sla1[1244:]
print(norm.lc_norm_score([sla1wo]))
print(norm.lc_norm_score([sla1]))
#sla2[348:442]
sla2 = seqs[5]
#print(sla2[348:442])
sla2wo = sla2[:348] + sla2[442:]
#print(norm.lc_norm_score([sla2wo]))
#print(norm.lc_norm_score([sla2]))
# sup35[0:123]
sup35 = seqs[6]
#print(sup35[0:123])
#print(norm.lc_norm_score([seq]))
def main():
cp = CheckPrDs()
cp.read_fasta()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,632 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/experiment/expression.py | import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import chi2_contingency
from deconstruct_lc import read_config
class Expression(object):
"""
Chi square analysis for marcotte data against Huh
"""
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
self.exp_dp = os.path.join(data_dp, 'expression_files_for_S3', 'Gasch_2000_PMID_11102521')
self.exp_fp = os.path.join(self.exp_dp, '2010.Gasch00_stationaryPhase(y14).flt.knn.avg.pcl')
self.puncta_fpi = os.path.join(data_dp, 'experiment', 'marcotte_puncta_scores.tsv')
def read_file(self):
print(self.exp_fp)
hex = self.hex_low()
df = pd.read_csv(self.exp_fp, sep='\t')
df = df[['YORF', 'YPD_2_d_30C; src: t=0<->2_d']]
puncta_df = pd.read_csv(self.puncta_fpi, sep='\t')
puncta_low = puncta_df[puncta_df['LC Score'] < -10]
puncta_hi = puncta_df[puncta_df['LC Score'] >= 20]
low_orf = list(puncta_low['ORF'])
hi_orf = list(puncta_hi['ORF'])
low_df = df[df['YORF'].isin(hex)]
#hi_df = df[df['YORF'].isin(hi_orf)]
print(low_df['YPD_2_d_30C; src: t=0<->2_d'].mean())
#print(hi_df['YPD_2_d_30C; src: t=0<->2_d'].mean())
print(low_df)
def hex_low(self):
hex = ['YDR539W', 'YGR117C', 'YKL035W', 'YER081W', 'YLR028C', 'YDR127W', 'YBL055C',
'YMR120C', 'YBL039C', 'YDR450W', 'YER175C', 'YJR103W', 'YCL030C', 'YJR057W',
'YGR210C', 'YER052C', 'YMR303C', 'YLR343W', 'YNL220W', 'YKL001C', 'YGR185C',
'YMR169C', 'YKL127W', 'YLR344W']
return hex
def main():
ex = Expression()
ex.read_file()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,633 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/tools.py | import itertools
def ints_to_ranges(int_list):
"""
Given a list of integers (usually corresponding to index locations in a
list), return a generator that provides a list of ranges for the indexes.
example: [1,2,3,4,6,7,8] yeilds (1, 4), (6, 8)
"""
for a, b in itertools.groupby(enumerate(int_list), lambda x: x[0] - x[1]):
b = list(b)
yield b[0][1], b[-1][1]
def sort_lists(zip_list, flag=True):
"""
Accepts a list of tuples created by zip(list1, list2, list3...)
Will sort by the first item in the tuple
lambda defines a function.
Given the variable pair, return the 0 indexed value
unpack either by for var1, var2, var3 in sorted_tups:
or list1, list2, list3 = zip(*sorted_tups)
"""
key_fun = lambda pair: pair[0]
sorted_tups = sorted(zip_list, reverse=flag, key=key_fun)
return sorted_tups
def demonstrate_sort():
a = [2, 1, 3]
b = ['cat', 'the', 'meowed']
c = [6, 5, 7]
list_tups = zip(a, b, c)
key_fun = lambda pair: pair[0]
sorted_tups = sorted(list_tups, reverse=True, key=key_fun)
return sorted_tups
def main():
demonstrate_sort()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,634 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/atg_proteins/atg.py | import os
import pandas as pd
from Bio import SeqIO
from deconstruct_lc import read_config
from deconstruct_lc import tools_fasta
from deconstruct_lc.display.display_lc import Display
class Atg(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.atg_fp = os.path.join(data_dp, 'atg', 'atg.xlsx')
self.atg_out = os.path.join(data_dp, 'atg', 'atg_gene_orf_seq.tsv')
self.atg_fasta = os.path.join(data_dp, 'atg', 'atg.fasta')
self.atg_display = os.path.join(data_dp, 'atg', 'atg_display.html')
self.orf_trans = os.path.join(data_dp, 'proteomes', 'orf_trans.fasta')
def readxl(self):
sns = ['Cvt', 'Starvation-Induced', 'Core', 'Pexophagy', 'Subgroups']
all_genes = []
for sn in sns:
df = pd.read_excel(self.atg_fp, sheetname=sn)
all_genes += list(df['Gene'])
all_genes = list(set(all_genes))
all_genes = [gene.upper() for gene in all_genes]
seqs, genes, orfs = self.get_yeast_seq_gene_from_ids(self.orf_trans, all_genes)
print(set(all_genes) - set(genes))
tools_fasta.yeast_write_fasta_from_ids(self.orf_trans, orfs, self.atg_fasta)
self.display()
def get_yeast_seq_gene_from_ids(self, orf_trans_fp, gene_ids):
sequences = []
genes = []
orfs = []
with open(orf_trans_fp, 'r') as fasta_in:
for record in SeqIO.parse(fasta_in, 'fasta'):
pid = str(record.id)
full_description = str(record.description)
fd_sp = full_description.split(',')
gene = fd_sp[0].split(' ')[1]
if gene in gene_ids:
sequences.append(str(record.seq))
genes.append(gene)
orfs.append(pid)
return sequences, genes, orfs
def display(self):
ds = Display(self.atg_fasta, self.atg_display, color=False)
ds.write_body()
def main():
a = Atg()
a.readxl()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,635 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/len_norm/data_len_norm.py | import os
import pandas as pd
from deconstruct_lc import read_config
from deconstruct_lc import tools_lc
class DataLenNorm(object):
def __init__(self):
config = read_config.read_config()
data_dp = os.path.join(config['fps']['data_dp'])
pdb_dp = os.path.join(data_dp, 'pdb_prep')
pdb_an_dp = os.path.join(data_dp, 'pdb_analysis')
self.norm_fpi = os.path.join(pdb_dp, 'pdb_norm_cd100.tsv')
self.fpo = os.path.join(pdb_an_dp, 'pdb_len_norm.tsv')
self.k = int(config['score']['k'])
self.lca = str(config['score']['lca'])
self.lce = float(config['score']['lce'])
def write_tsv(self):
"""Write a tsv file that is score, nomiss_score, length"""
df = pd.read_csv(self.norm_fpi, sep='\t', index_col=0)
seqs = df['Sequence']
miss_seqs = df['Missing']
lens = [len(seq) for seq in seqs]
raw_scores = tools_lc.calc_lc_motifs(seqs, self.k, self.lca, self.lce)
nomiss_scores = tools_lc.calc_lc_motifs_nomiss(seqs, miss_seqs, self.k,
self.lca, self.lce)
df_dict = {'score': raw_scores, 'nomiss_score': nomiss_scores, 'Length': lens}
cols = ['score', 'nomiss_score', 'Length']
df = pd.DataFrame(df_dict, columns=cols)
df.to_csv(self.fpo, sep='\t')
def main():
dl = DataLenNorm()
dl.write_tsv()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,636 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/len_norm/adjust_b.py | import os
import pandas as pd
import numpy as np
from deconstruct_lc import read_config
from deconstruct_lc.svm import svms
from deconstruct_lc.scores.norm_score import NormScore
class AdjustB(object):
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.train_fpi = os.path.join(data_dp, 'train.tsv')
def find_hyperplane(self):
"""Show that the hyperplane for the set intercept is close to 0"""
df = pd.read_csv(self.train_fpi, sep='\t', index_col=0)
seqs = list(df['Sequence'])
cs = NormScore()
lc_norm = cs.lc_norm_score(seqs)
X = np.array([lc_norm]).T
y = np.array(df['y']).T
clf = svms.linear_svc(X, y)
xs = np.arange(-2, 2, 0.01).reshape(1, -1).T
dists = list(clf.decision_function(xs))
for x, dist in zip(xs, dists):
if dist < 0:
print(x)
break
def main():
ab = AdjustB()
ab.find_hyperplane()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,637 | shellydeforte/deconstruct_lc | refs/heads/master | /deconstruct_lc/analysis_proteomes/plot_proteome_composition.py | import os
import matplotlib.pyplot as plt
import pandas as pd
from deconstruct_lc import read_config
class PlotLcProteome():
"""
Create boxplots for the fraction of each amino acid between proteomes.
Data generated from lca/data_proteome_composition.py
"""
def __init__(self):
config = read_config.read_config()
data_dp = config['fps']['data_dp']
self.fpi = os.path.join(data_dp, 'analysis_proteomes', 'lc_composition.tsv')
self.fig_fpo = os.path.join(data_dp, 'figures', 'lca_comp.png')
def plot_lc_comp(self):
df = pd.read_csv(self.fpi, sep='\t', index_col=0)
medprops, meanprops, whiskerprops, boxprops = self.params()
df.plot.box(vert=True,
whis=[5, 95],
widths=0.75,
showfliers=True,
color='grey',
patch_artist=False,
showmeans=True,
boxprops=boxprops,
whiskerprops=whiskerprops,
medianprops=medprops,
meanprops=meanprops)
plt.xlabel('Amino Acids', size=12)
plt.ylabel('Total Fraction in Long LCRs', size=12)
plt.show()
def params(self):
medprops = dict(linestyle='-',
color='grey')
meanprops = dict(marker='o',
markeredgecolor='black',
markerfacecolor='darkred',
markersize=5)
whiskerprops = dict(color='grey',
linestyle='-')
boxprops = dict(color='grey')
return medprops, meanprops, whiskerprops, boxprops
def main():
lcp = PlotLcProteome()
lcp.plot_lc_comp()
if __name__ == '__main__':
main() | {"/deconstruct_lc/drosophila/run_drosophila.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/write_marcotte_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/hexandiol.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/run.py": ["/deconstruct_lc/data_pdb/ssdis_to_fasta.py", "/deconstruct_lc/data_pdb/filter_pdb.py", "/deconstruct_lc/data_pdb/norm_all_to_tsv.py", "/deconstruct_lc/data_pdb/write_pdb_analysis.py"], "/deconstruct_lc/rohit/plot_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/kelil/run_display.py": ["/deconstruct_lc/kelil/display_motif.py"], "/deconstruct_lc/analysis_bc/score_profile.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/old/experiment/marcotte.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/puncta/puncta_scores.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/old/experiment/write_yeast.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sup35.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/analysis_bc/write_bc_score.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/remove_structure/remove_pfam.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/biogrid/format.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/format_gfp.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/examples/sandbox.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/data_pdb/write_pdb_analysis.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/experiment/proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/scores/write_scores.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/analysis_bc/write_bc_score.py"], "/deconstruct_lc/experiment/write_details.py": ["/deconstruct_lc/scores/norm_score.py", "/deconstruct_lc/experiment/labels.py"], "/deconstruct_lc/lp/lp_proteins.py": ["/deconstruct_lc/scores/norm_score.py"], "/deconstruct_lc/len_norm/adjust_b.py": ["/deconstruct_lc/scores/norm_score.py"]} |
44,641 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0001_initial.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-18 18:09
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Host',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('loginid', models.CharField(db_index=True, max_length=16)),
('last_login_date', models.DateTimeField()),
('display_name', models.CharField(max_length=200)),
('email_address', models.CharField(db_index=True, max_length=200)),
],
),
migrations.AddField(
model_name='host',
name='loginid',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='puppet.User'),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,642 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0020_auto_20160324_1550.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-24 22:50
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0019_auto_20160323_1106'),
]
operations = [
migrations.RenameField(
model_name='user',
old_name='email_address',
new_name='mail',
),
migrations.AddField(
model_name='user',
name='ou',
field=models.CharField(default='abcd', max_length=200),
preserve_default=False,
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,643 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0026_auto_20160408_1033.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-04-08 17:33
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0025_auto_20160405_1110'),
]
operations = [
migrations.AddField(
model_name='user',
name='departmental_account',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='user',
name='mail',
field=models.EmailField(db_index=True, max_length=254, validators=[django.core.validators.EmailValidator]),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,644 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/utils.py | import subprocess
def run_command(command, cwd='/tmp'):
p = subprocess.Popen(command, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
return p.communicate()
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,645 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0002_auto_20160318_2029.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-18 20:29
from __future__ import unicode_literals
import datetime
from django.db import migrations, models
from django.utils.timezone import utc
class Migration(migrations.Migration):
dependencies = [
('puppet', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='PuppetClass',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128)),
('description', models.CharField(max_length=500)),
('argument_allowed', models.BooleanField(default=False)),
('argument', models.CharField(max_length=200)),
],
),
migrations.AddField(
model_name='host',
name='hash',
field=models.CharField(default=' ', max_length=128),
preserve_default=False,
),
migrations.AddField(
model_name='host',
name='last_update_date',
field=models.DateTimeField(default=datetime.datetime(2016, 3, 18, 20, 29, 21, 846947, tzinfo=utc)),
preserve_default=False,
),
migrations.AddField(
model_name='host',
name='puppet_classes',
field=models.ManyToManyField(to='puppet.PuppetClass'),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,646 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0007_auto_20160321_1438.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-21 21:38
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0006_auto_20160318_2038'),
]
operations = [
migrations.AlterModelOptions(
name='host',
options={'ordering': ['fqdn']},
),
migrations.AlterField(
model_name='user',
name='email_address',
field=models.EmailField(db_index=True, max_length=254),
),
migrations.AlterField(
model_name='user',
name='last_login_date',
field=models.DateTimeField(auto_created=True),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,647 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0025_auto_20160405_1110.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-04-05 18:10
from __future__ import unicode_literals
from django.db import migrations, models
import puppet.models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0024_auto_20160324_1623'),
]
operations = [
migrations.AlterField(
model_name='host',
name='fqdn',
field=models.CharField(max_length=255, unique=True, validators=[puppet.models.full_domain_validator], verbose_name=' FQDN'),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,648 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/urls.py | from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^class/([^/]+)/?$', views.puppet_class, name='puppet-class'),
url(r'^edit-host/(?P<fqdn>[^/]+)?/?$', views.edit_host, name='edit-host'),
url(r'^add-host/(?P<fqdn>[^/]+)?/?$', views.add_host, name='add-host'),
url(r'^delete/([^/]+)/?$', views.delete_host, name='delete-host'),
url(r'^user/(?P<loginid>[^/]+)/?$', views.edit_user, name='edit-user'),
# url(r'^add-host', views.add_host, name='add-host'),
url(r'^', views.index, name='index'),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,649 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/views.py | import traceback
from django.template.response import TemplateResponse
from django.shortcuts import render, get_object_or_404, redirect, HttpResponse
import django.forms
from django.contrib import messages
import django.core.exceptions
import django.http
from django.db import transaction
import datetime
import ipware.ip
from .models import *
from .utils import *
def get_current_git_commit():
out, err = run_command(['/usr/bin/git', 'rev-parse', 'HEAD'], cwd=ucdpuppet_dir)
return out
def messages_traceback(request, comment=None):
base = 'Sorry, a serious error occurred, please copy this box and send it to <tt>ucd-puppet-admins@ucdavis.edu</tt>'
if comment:
base = base + '<br/>' + comment
messages.error(request, base + '<br/><pre>' + traceback.format_exc() + '</pre>', extra_tags='safe')
def msg_admins(request, str):
contact_admins = '<p>If you do not know how to resolve this error please email ucd dash puppet dash admins at ucdavis dot edu.</p>'
messages.error(request, str + contact_admins, extra_tags='safe')
def get_loginid(request):
if request.user.is_superuser:
return request.user.username
else:
return request.META['REMOTE_USER']
def get_user_info(request):
previous_login = None
previous_ip = None
user = None
try:
loginid = get_loginid(request)
user = User.objects.get(loginid=loginid)
previous_login = user.last_login
previous_ip = user.ip_address
except User.DoesNotExist:
try:
user = User.create(request.META['REMOTE_USER'])
except User.UCDLDAPError:
return (None, None, None,
redirect('edit-user', loginid=loginid))
except KeyError as e:
if e.args[0] == 'REMOTE_USER':
return (None, None, None,
TemplateResponse(request, 'puppet/403.html',
{'error': 'You must login via CAS to access this site.'}, status=403))
else:
return (None, None, None,
TemplateResponse(request, 'puppet/401.html', {'error': '%s: %s' % (type(e), e)}, status=401))
except Exception as e:
messages_traceback(request)
return (None, None, None,
TemplateResponse(request, 'puppet/401.html', {'error': 'Generic Error, the very best kind'},
status=401))
user.last_login = datetime.datetime.now()
user.ip_address = ipware.ip.get_ip(request)
user.save()
return (user, previous_login, previous_ip, None)
def validate_host(request, formset, user):
# Downcase it early as Puppet deals exclusively with lower case FQDNs
fqdn = formset.cleaned_data['fqdn'] = formset.instance.fqdn = formset.cleaned_data['fqdn'].lower()
# Before the host gets saved to the database, make sure it has been signed by Puppet
out, err = run_command(['/usr/bin/sudo', '/opt/puppetlabs/bin/puppetserver', 'ca', 'list', '--certname', fqdn])
if out and out.startswith('Missing Certificates:'):
messages.warning(request,
'The Puppet Server was unable to find a certificate signing request from <tt>%s</tt>.<br/>Did you run <tt>%s</tt>?' % (
fqdn, puppet['command_initial']),
extra_tags='safe')
return False
elif err:
msg_admins(request, 'Received error trying to list the certificate:<pre>%s</pre><pre>%s</pre>' % (out, err))
return False
"""
Missing Certificates:
fc-ajfinger-lt1.ucdavis.eduMISSING
Requested Certificates:
fc-ajfinger-lt1.ucdavis.edu (SHA256) BD:42:95:A3:CF:2F:AE:0A:BC:CC:B9:6C:0B:58:8F:D5:D6:68:17:20:89:69:81:70:11:DF:4A:9A:3D:C2:B1:4F
"""
lines = out.strip().splitlines()
header = lines[0].strip()
data = lines[1].strip().split()
if header.startswith('Signed Certificates:'):
msg_admins(request, 'A certificate for this FQDN is already signed:<pre>%s</pre>' % out)
return False
# TODO: find equivelant for new ca commands
if header.startswith('Revoked Certificates:'):
msg_admins(request, "The certificate for this host has been revoked on the server. You may need to clear out Puppet's SSL directory <tt>%s</tt> and re-run the Puppet command <tt>%s</tt>." % (puppet['clear_certs'], puppet['command_initial']))
return False
if data[2] != formset.cleaned_data['hash']:
out, err = run_command(['/usr/bin/sudo', '/opt/puppetlabs/bin/puppetserver', 'ca', 'clean', '--certname', fqdn])
msg_admins(request, "Your specified hash does not match the hash Puppet had for your host. The old request has been removed from the server. Clear out Puppet's SSL directory <tt>%s</tt> and re-run the Puppet command <tt>%s</tt>." % (puppet['clear_certs'], puppet['command_initial']))
return False
if data[0] != fqdn:
msg_admins(request, 'Invalid output returned from Puppet:<br/><pre>%s</pre>' % out)
return False
out, err = run_command(['/usr/bin/sudo', '/opt/puppetlabs/bin/puppetserver', 'ca', 'sign', '--certname', fqdn])
if out and not out.startswith('Successfully signed certificate request for'):
msg_admins(request, 'Received unexpected output trying to sign the certificate: <br/>%s<br/>%s' % (out, err))
return False
if err:
msg_admins(request, 'Received error trying to sign the certificate: <br/>%s<br/>%s' % (out, err))
return False
# Notice: Signed certificate request for puppet-test.metro.ucdavis.edu
# Notice: Removing file Puppet::SSL::CertificateRequest puppet-test.metro.ucdavis.edu at '/etc/puppetlabs/puppet/ssl/ca/requests/puppet-test.metro.ucdavis.edu.pem'
try:
with transaction.atomic():
new_host = formset.save(commit=True)
new_host.loginid = user
new_host.save()
except:
messages_traceback(request)
# If there is a write error in the YAML in formset.save(commit=True) then we need to delete the object that gets saved to the database.
Host.objects.get(fqdn=fqdn).delete()
messages.success(request,
"Host %s added to your profile. Please run <tt>%s</tt> to finish you Puppet client configuration." % (new_host.fqdn, puppet['command']),
extra_tags='safe')
# Redirect back to the index so the user gets a blank form, as well as make page reload not attempt to re-add the host.
return redirect('index')
def edit_user(request, loginid):
if loginid != get_loginid(request):
return TemplateResponse(request, 'puppet/401.html', {'error': 'Looks like you are trying to mess with the LoginID. Bad dog, no cookie.'},
status=401)
try:
u = User.objects.get(loginid=loginid)
return TemplateResponse(request, 'puppet/401.html',
{'error': 'You cannot edit LoginIDs once added.'},
status=401)
except User.DoesNotExist:
pass
formset = django.forms.models.modelform_factory(User, form=UserEditForm)
if request.method == 'POST' and 'edit-user' in request.POST:
formset = formset(request.POST)
if formset.is_valid():
with transaction.atomic():
user = formset.save(commit=False)
user.loginid = loginid
user.last_login = datetime.datetime.now()
user.ip_address = ipware.ip.get_ip(request)
user.departmental_account = True
user.save()
return redirect('index')
else:
messages.error(request, 'Unable to add user, please fix the errors below.')
return render(request,
'puppet/edit-user.html',
{'formset': formset,
'loginid': loginid}
)
def index(request):
user, previous_login, previous_ip, err = get_user_info(request)
if err:
return err
return render(request,
'puppet/user.html',
{'hosts': Host.objects.filter(loginid=user),
'user': user,
'formset': django.forms.models.modelform_factory(Host, form=HostAddForm),
'previous_login': previous_login,
'previous_ip': previous_ip,
'puppet_classes': PuppetClass.objects.all(),
'puppet': puppet,
'git_commit': get_current_git_commit(),
}
)
def edit_host(request, fqdn=None):
user, previous_login, previous_ip, err = get_user_info(request)
if err:
return err
host = get_object_or_404(Host, fqdn=fqdn, loginid=user)
if request.method == 'POST' and 'edit-host' in request.POST:
p_c = PuppetClass.objects.filter(pk__in=request.POST.getlist('puppet_classes'))
host.puppet_classes = p_c
try:
host.save()
except:
messages_traceback(request)
else:
messages.success(request,
"Updated host %s. Run <tt>%s</tt> to immediately update your host." % (
host.fqdn, puppet['command']),
extra_tags='safe')
return redirect('index')
host_form = django.forms.models.modelform_factory(Host, form=HostAddForm, fields=('fqdn', 'puppet_classes',),
widgets={'fqdn': django.forms.HiddenInput()})
formset = host_form(None, instance=host)
return render(request,
'puppet/user.html',
{'hosts': Host.objects.filter(loginid=user),
'user': user,
'formset': formset,
'previous_login': previous_login,
'previous_ip': previous_ip,
'edit': host,
'puppet_classes': PuppetClass.objects.all(),
'puppet': puppet,
'git_commit': get_current_git_commit(),
}
)
def add_host(request, fqdn=None):
user, previous_login, previous_ip, err = get_user_info(request)
if err:
return err
if request.method != 'POST' or 'add-host' not in request.POST:
raise django.http.Http404()
host_form = django.forms.models.modelform_factory(Host, form=HostAddForm)
formset = host_form(request.POST)
if formset.is_valid():
status = validate_host(request, formset, user)
if status:
return status
else:
# formset not valid
messages.error(request, 'Unable to add host, please fix the errors below.')
return render(request,
'puppet/user.html',
{'hosts': Host.objects.filter(loginid=user),
'user': user,
'previous_login': previous_login,
'previous_ip': previous_ip,
'formset': formset,
'edit': edit_host,
'puppet_classes': PuppetClass.objects.all(),
'puppet': puppet,
'git_commit': get_current_git_commit(),
}
)
def delete_host(request, fqdn):
user, previous_login, previous_ip, err = get_user_info(request)
if err:
return err
host = get_object_or_404(Host, fqdn=fqdn, loginid=user)
out, err = host.delete()
if err:
msg_admins(request, 'Received unexpected output running cert clean for %s: <br/>%s<br/>%s' % (fqdn, out, err))
else:
messages.success(request, 'Host %s deleted successfully and removed from UCD Puppet.<br/>' % host.fqdn, extra_tags='safe')
return redirect('index')
def puppet_class(request, name):
pc = get_object_or_404(PuppetClass, display_name=name)
return render(request,
'puppet/class.html',
{'pc': pc},
)
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,650 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0010_auto_20160321_1449.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-21 21:49
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('puppet', '0009_user_ip_address'),
]
operations = [
migrations.RenameField(
model_name='user',
old_name='last_login_date',
new_name='last_login',
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,651 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/apps.py | from __future__ import unicode_literals
from django.apps import AppConfig
class PuppetConfig(AppConfig):
name = 'puppet'
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,652 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0009_user_ip_address.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-21 21:46
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0008_auto_20160321_1440'),
]
operations = [
migrations.AddField(
model_name='user',
name='ip_address',
field=models.GenericIPAddressField(default=''),
preserve_default=False,
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,653 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0021_auto_20160324_1553.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-24 22:53
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0020_auto_20160324_1550'),
]
operations = [
migrations.AlterField(
model_name='user',
name='ou',
field=models.CharField(max_length=200, verbose_name=' OU'),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,654 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0014_auto_20160321_1737.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-22 00:37
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import puppet.models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0013_auto_20160321_1724'),
]
operations = [
migrations.AlterField(
model_name='host',
name='hash',
field=models.CharField(max_length=128, validators=[puppet.models.validate_hash, django.core.validators.MinLengthValidator(40)]),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,655 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/admin.py | from django.contrib import admin
# Register your models here.
from .models import User
from .models import Host
from .models import PuppetClass
class HostAdmin(admin.ModelAdmin):
list_filter = ['puppet_classes', 'loginid__ou', 'loginid']
class UserAdmin(admin.ModelAdmin):
list_filter = ['ou', 'departmental_account']
admin.site.register(User, UserAdmin)
admin.site.register(Host, HostAdmin)
admin.site.register(PuppetClass)
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,656 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/models.py | from __future__ import unicode_literals
from django.db import models
from django.core.exceptions import ValidationError
import django
import django.forms
import django.core.validators
import re
import os
from .utils import *
puppet = {}
puppet['command_base'] = 'sudo /opt/puppetlabs/bin/puppet'
puppet['command'] = puppet['command_base'] + ' agent --test --server=puppet.ucdavis.edu'
puppet['command_initial'] = puppet['command'] + ' --waitforcert 0'
puppet['fingerprint'] = puppet['command_base'] + ' agent --fingerprint'
puppet['clear_certs'] = 'sudo rm -rf /etc/puppetlabs/puppet/ssl/ && sudo mkdir /etc/puppetlabs/puppet/ssl/'
ucdpuppet_dir = '/etc/puppetlabs/code/environments/production/modules/ucdpuppet'
sha256_re = re.compile(r'^[0-9A-Fa-f]{2}(:[0-9A-Fa-f]{2}){31}$')
def validate_hash(value):
if not re.match(sha256_re, value):
raise ValidationError('%(value)s does not look like a valid SHA256 hash',
params={'value': value},
)
HOSTNAME_LABEL_PATTERN = re.compile("(?!-)[A-Z\d-]+(?<!-)$", re.IGNORECASE)
def full_domain_validator(hostname):
"""
OW: originally from: http://stackoverflow.com/questions/17821400/regex-match-for-domain-name-in-django-model
Fully validates a domain name as compilant with the standard rules:
- Composed of series of labels concatenated with dots, as are all domain names.
- Each label must be between 1 and 63 characters long.
- The entire hostname (including the delimiting dots) has a maximum of 255 characters.
- Only characters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9'.
- Labels can't start or end with a hyphen.
"""
if not hostname:
return
if len(hostname) > 255:
raise ValidationError('The domain name cannot be composed of more than 255 characters.')
if hostname[-1:] == ".":
hostname = hostname[:-1] # strip exactly one dot from the right, if present
if re.match(r"[\d.]+$", hostname):
raise ValidationError('You must provide a FQDN, not an IP address.')
split = hostname.split(".")
if len(split) < 3:
raise ValidationError('FQDN must consist of 3 or more pieces.')
for label in split:
if len(label) > 63:
raise ValidationError('The label \'%(label)s\' is too long (maximum is 63 characters).' % {'label': label})
if not HOSTNAME_LABEL_PATTERN.match(label):
raise ValidationError('Unallowed characters in label: %(label)s' % {'label': label})
class User(models.Model):
loginid = models.CharField(max_length=16, db_index=True, unique=True)
display_name = models.CharField(max_length=200)
ou = models.CharField(max_length=200, verbose_name=" OU")
mail = models.EmailField(db_index=True, validators=[django.core.validators.EmailValidator])
last_login = models.DateTimeField()
ip_address = models.GenericIPAddressField()
departmental_account = models.BooleanField(default=False)
class Meta:
ordering = ['display_name']
class UCDLDAPError(Exception):
pass
@classmethod
def create(cls, loginid):
import ldap
l = ldap.initialize("ldaps://ldap.ucdavis.edu")
baseDN = "ou=People,dc=ucdavis,dc=edu"
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
searchFilter = "uid=%s" % loginid
ldap_result_id = l.search(baseDN, searchScope, searchFilter, retrieveAttributes)
result_set = []
while 1:
result_type, result_data = l.result(ldap_result_id, 0)
if (result_data == []):
break
else:
## here you don't have to append to a list
## you could do whatever you want with the individual entry
## The appending to list is just for illustration.
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
# except ldap.LDAPError as e:
# raise User.UCDLDAPError(e.args)
# result_set ::
# a = [[('ucdPersonUUID=00457597,ou=People,dc=ucdavis,dc=edu',
# {'telephoneNumber': ['+1 530 752 1130'], 'departmentNumber': ['030250'], 'displayName': ['Omen Wild'],
# 'cn': ['Omen Wild'], 'title': ['Systems Administrator'], 'eduPersonAffiliation': ['staff'],
# 'ucdPersonUUID': ['00457597'], 'l': ['Davis'], 'st': ['CA'], 'street': ['148 Hoagland Hall'],
# 'sn': ['Wild'], 'postalCode': ['95616'], 'mail': ['omen@ucdavis.edu'],
# 'postalAddress': ['148 Hoagland Hall$Davis, CA 95616'], 'givenName': ['Omen'], 'ou': ['Metro Cluster'],
# 'uid': ['omen']})]]
try:
displayName = result_set[0][0][1]['displayName'][0]
mail = result_set[0][0][1]['mail'][0]
ou = result_set[0][0][1]['ou'][0]
except:
raise User.UCDLDAPError('Error looking up LDAP Attributes for %s' % loginid)
return cls(loginid=loginid, display_name=displayName, mail=mail, ou=ou)
def __str__(self):
return "%s <%s>" % (self.display_name, self.mail)
class UserEditForm(django.forms.ModelForm):
class Meta:
model = User
fields = ['display_name', 'ou', 'mail']
help_texts = {
'display_name': 'The name of your IT group, or the main IT person associated with this departmental account.',
'ou': 'Your official UCD Organizational Unit name.',
'mail': 'An email address to contact your IT team.'
}
widgets = { # 'loginid': django.forms.HiddenInput(),
'display_name': django.forms.TextInput(attrs={'size': 55}),
'ou': django.forms.TextInput(attrs={'size': 55}),
'mail': django.forms.TextInput(attrs={'size': 55}),
}
class PuppetClass(models.Model):
display_name = models.CharField(max_length=128, unique=True)
class_name = models.CharField(max_length=128, unique=True)
description = models.TextField(max_length=500)
argument_allowed = models.BooleanField(default=False)
argument = models.CharField(max_length=200, blank=True, default='')
def __str__(self):
return self.display_name
class Meta:
ordering = ['display_name']
def full_puppet_class_name(self):
return 'ucdpuppet::%s' % self.class_name
class Host(models.Model):
loginid = models.ForeignKey(User, null=True)
hash = models.CharField(max_length=128, validators=[validate_hash])
fqdn = models.CharField(max_length=255, unique=True, verbose_name=" FQDN", validators=[full_domain_validator])
puppet_classes = models.ManyToManyField(PuppetClass)
last_update_date = models.DateTimeField(auto_now=True)
### The directory the Puppet YAML files get written into.
yaml_base = '/etc/puppetlabs/code/hieradata/nodes/'
class Meta:
ordering = ['fqdn']
def __str__(self):
if self.loginid and self.loginid.mail:
email = self.loginid.mail
else:
email = "ORPHANED"
return "%s (%s) by %s" % (self.fqdn, ", ".join(p.display_name for p in self.puppet_classes.all()), email)
def yaml_file(self):
return os.path.join(self.yaml_base, self.fqdn + '.yaml')
def save(self, *args, **kwargs):
super(Host, self).save(*args, **kwargs)
self.write_yaml()
def write_yaml(self):
with open(self.yaml_file(), 'w') as f:
f.write("classes:\n")
for puppet_class in self.puppet_classes.all():
f.write(" - %s\n" % puppet_class.full_puppet_class_name())
def delete(self, *args, **kwargs):
if os.path.isfile(self.yaml_file()):
os.unlink(self.yaml_file())
fqdn = self.fqdn
super(Host, self).delete()
return run_command(['/usr/bin/sudo', '/opt/puppetlabs/bin/puppetserver', 'ca', 'clean', '--certname', fqdn])
class HostAddForm(django.forms.ModelForm):
class Meta:
model = Host
fields = ['fqdn', 'hash', 'puppet_classes']
help_texts = {
'fqdn': 'The FQDN of the host, as shown by: <tt>/opt/puppetlabs/bin/facter fqdn</tt>',
'hash': 'The SHA256 hash shown during the first run of: <tt>%s</tt> or <tt>%s</tt>' % (puppet['command_initial'], puppet['fingerprint']),
}
widgets = {'hash': django.forms.TextInput(attrs={'size': 98}),
'fqdn': django.forms.TextInput(attrs={'size': 55})}
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,657 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0015_auto_20160321_1743.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-22 00:43
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
import puppet.models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0014_auto_20160321_1737'),
]
operations = [
migrations.AlterField(
model_name='host',
name='hash',
field=models.CharField(max_length=128, validators=[puppet.models.validate_hash, django.core.validators.MinLengthValidator(94)]),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,658 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0004_auto_20160318_2035.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-18 20:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0003_auto_20160318_2031'),
]
operations = [
migrations.AlterField(
model_name='puppetclass',
name='description',
field=models.TextField(max_length=500),
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
44,659 | ucdavis/ucdpuppet | refs/heads/master | /django/puppet/migrations/0022_auto_20160324_1621.py | # -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-03-24 23:21
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('puppet', '0021_auto_20160324_1553'),
]
operations = [
migrations.AlterModelOptions(
name='puppetclass',
options={'ordering': ['display_name']},
),
migrations.RenameField(
model_name='puppetclass',
old_name='name',
new_name='class_name',
),
migrations.AddField(
model_name='puppetclass',
name='display_name',
field=models.CharField(default='abc', max_length=128, unique=True),
preserve_default=False,
),
]
| {"/django/puppet/views.py": ["/django/puppet/models.py", "/django/puppet/utils.py"], "/django/puppet/admin.py": ["/django/puppet/models.py"], "/django/puppet/models.py": ["/django/puppet/utils.py"]} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.