Skip to content

Commit

Permalink
[RELEASE] 1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
grosenberger committed Jul 31, 2020
1 parent 12e05cb commit e70c4dd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion secat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def export(infile, maximum_interaction_qvalue):
@click.option('--id', required=False, type=str, help='Plot specific UniProt bait_id (Q10000) or interaction_id (Q10000_P10000)')
@click.option('--max_qvalue', default=0.01, show_default=True, type=float, help='Maximum q-value to plot baits or interactions.')
@click.option('--min_abs_log2fx', default=1.0, show_default=True, type=float, help='Minimum absolute log2 fold-change for integrated nodes.')
@click.option('--mode', default='quantitative', show_default=True, type=click.Choice(['quantitative', 'detection_integrated', 'detection_separate']), help='Select mode to order interaction plots by. Note: detection_separate will also report decoys')
@click.option('--mode', default='quantitative', show_default=True, type=click.Choice(['quantitative', 'detection']), help='Select mode to order interaction plots by.')
@click.option('--combined/--no-combined', default=False, show_default=True, help='Select interactions and baits according to combined q-values.')
@click.option('--peptide_rank', default=6, show_default=True, type=int, help='Number of most intense peptides to plot.')
def plot(infile, level, id, max_qvalue, min_abs_log2fx, mode, combined, peptide_rank):
Expand Down
13 changes: 7 additions & 6 deletions secat/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,10 @@ def read_interactions(self):

if check_sqlite_table(con, 'EDGE') and self.mode == 'quantitative':
df = pd.read_sql('SELECT DISTINCT bait_id || "_" || prey_id AS interaction_id, 0 as decoy FROM %s WHERE pvalue_adjusted < %s AND abs_log2fx > %s ORDER BY pvalue ASC;' % (table, self.max_qvalue, self.min_abs_log2fx), con)
elif self.mode == 'detection_integrated':
elif self.mode == 'detection':
df = pd.read_sql('SELECT DISTINCT bait_id || "_" || prey_id AS interaction_id, decoy FROM FEATURE_SCORED_COMBINED WHERE qvalue < %s GROUP BY bait_id, prey_id ORDER BY qvalue ASC;' % (self.max_qvalue), con)
elif self.mode == 'detection_separate':
df = pd.read_sql('SELECT DISTINCT bait_id || "_" || prey_id AS interaction_id, decoy FROM FEATURE_SCORED WHERE qvalue < %s ORDER BY qvalue ASC;' % (self.max_qvalue), con)
else:
sys.exit("Mode for interaction plotting not supported.")
sys.exit("Error: Mode for interaction plotting not supported.")

con.close()

Expand All @@ -183,9 +181,9 @@ def read_interactions_dmeta(self):

if check_sqlite_table(con, 'COMPLEX_QM') and (self.mode == 'quantitative'):
df = pd.read_sql('SELECT FEATURE_SCORED_COMBINED.bait_id AS bait_id, FEATURE_SCORED_COMBINED.prey_id AS prey_id, FEATURE_SCORED_COMBINED.bait_id || "_" || FEATURE_SCORED_COMBINED.prey_id AS interaction_id, BAIT_META.protein_name AS bait_name, PREY_META.protein_name AS prey_name, min(FEATURE_SCORED_COMBINED.pvalue) AS pvalue, min(FEATURE_SCORED_COMBINED.qvalue) AS qvalue FROM FEATURE_SCORED_COMBINED INNER JOIN (SELECT * FROM PROTEIN) AS BAIT_META ON FEATURE_SCORED_COMBINED.bait_id = BAIT_META.protein_id INNER JOIN (SELECT * FROM PROTEIN) AS PREY_META ON FEATURE_SCORED_COMBINED.prey_id = PREY_META.protein_id INNER JOIN (SELECT DISTINCT bait_id, prey_id FROM COMPLEX_QM) AS COMPLEX_QM ON FEATURE_SCORED_COMBINED.bait_id = COMPLEX_QM.bait_id AND FEATURE_SCORED_COMBINED.prey_id = COMPLEX_QM.prey_id GROUP BY FEATURE_SCORED_COMBINED.bait_id, FEATURE_SCORED_COMBINED.prey_id;', con)
elif self.mode == 'detection_integrated':
elif self.mode == 'detection':
df = pd.read_sql('SELECT FEATURE_SCORED_COMBINED.bait_id AS bait_id, FEATURE_SCORED_COMBINED.prey_id AS prey_id, FEATURE_SCORED_COMBINED.bait_id || "_" || FEATURE_SCORED_COMBINED.prey_id AS interaction_id, BAIT_META.protein_name AS bait_name, PREY_META.protein_name AS prey_name, min(FEATURE_SCORED_COMBINED.pvalue) AS pvalue, min(FEATURE_SCORED_COMBINED.qvalue) AS qvalue FROM FEATURE_SCORED_COMBINED INNER JOIN (SELECT * FROM PROTEIN) AS BAIT_META ON FEATURE_SCORED_COMBINED.bait_id = BAIT_META.protein_id INNER JOIN (SELECT * FROM PROTEIN) AS PREY_META ON FEATURE_SCORED_COMBINED.prey_id = PREY_META.protein_id GROUP BY FEATURE_SCORED_COMBINED.bait_id, FEATURE_SCORED_COMBINED.prey_id;', con)
elif self.mode == 'detection_separate':
else:
df = None

con.close()
Expand Down Expand Up @@ -223,6 +221,9 @@ def read_monomer_qmeta(self):
def read_baits(self):
con = sqlite3.connect(self.infile)

if not check_sqlite_table(con, 'NODE'):
sys.exit("Error: Your experimental design is not supported. At least two conditions are necessary for differential analysis. Switch 'level' to 'interaction' for visualization.")

if self.combined:
table = 'NODE'
else:
Expand Down
21 changes: 15 additions & 6 deletions secat/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,25 @@ def __init__(self, mitabfile):

def read(self, mitabfile):
def _extract_uniprotkb(string):
return [u for u in string.split("|") if "uniprotkb" in u][0].split("uniprotkb:")[1]
return [u for u in string.split("|") if "uniprotkb" in u][0].split("uniprotkb:")[1].split("-")[0]

def _extract_score(string):
if 'score:' in string:
if 'intact-miscore:' in string:
return float([u for u in string.split("|") if "intact-miscore" in u][0].split("intact-miscore:")[1])
elif 'score:' in string:
return float([u for u in string.split("|") if "score" in u][0].split("score:")[1])
else:
return 0

df = pd.read_csv(mitabfile, sep="\t", header = None, usecols=[0,1,14])
df.columns = ["bait_id","prey_id","interaction_confidence"]
df = pd.read_csv(mitabfile, sep="\t", header = None, usecols=[0,1,2,3,14])
df.columns = ["bait_id","prey_id","bait_id_alt","prey_id_alt","interaction_confidence"]

df['bait_id_alt'] = df['bait_id_alt'].replace(np.nan,'',regex=True)
df['prey_id_alt'] = df['prey_id_alt'].replace(np.nan,'',regex=True)

df['bait_id'] = df['bait_id'] + "|" + df['bait_id_alt']
df['prey_id'] = df['prey_id'] + "|" + df['prey_id_alt']
df = df.drop(columns=['bait_id_alt','prey_id_alt'])

# Reduce DB to UniProtKB entries with scores
df = df[df['bait_id'].str.contains('uniprotkb:') & df['prey_id'].str.contains('uniprotkb:') & (df['interaction_confidence'].str.contains('score:') | df['interaction_confidence'].str.contains('shortestPath:'))]
Expand Down Expand Up @@ -208,12 +217,12 @@ def identify(self, netfile):

def unique_interactions(self, network):
def get_interaction_id(x):
return '_'.join(sorted([x['bait_id'], x['prey_id']]))
return '__'.join(sorted([x['bait_id'], x['prey_id']]))

network['interaction_id'] = network.apply(get_interaction_id, axis=1)

network = network.groupby('interaction_id')['interaction_confidence'].max().reset_index()
network[['bait_id','prey_id']] = network.interaction_id.str.split('_', expand=True)
network[['bait_id','prey_id']] = network.interaction_id.str.split('__', expand=True)
return network[['bait_id','prey_id','interaction_confidence']]

def to_df(self):
Expand Down
2 changes: 1 addition & 1 deletion secat/quantify.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def contrast(self):
con.close()

if len(conditions) < 2:
sys.exit("Error: Your experimental design is not appropriate. At least two conditions are necessary for quantification.")
sys.exit("Error: Your experimental design is not supported. At least two conditions are necessary for differential analysis.")

comparisons = []
# prepare single-sample comparisons
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='secat',
version='1.0.6',
version='1.0.7',
description='Size-Exclusion Chromatography Algorithmic Toolkit',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit e70c4dd

Please sign in to comment.