Skip to content

Commit feef486

Browse files
authored
Merge pull request #134 from singjc/master
update: merge osw post scoring method to merge feature alignment tables if present
2 parents 7cec084 + 167ce2d commit feef486

File tree

1 file changed

+96
-3
lines changed

1 file changed

+96
-3
lines changed

pyprophet/levels_contexts.py

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,15 @@ def merge_oswps(infiles, outfile, templatefile, same_run):
847847
create_scores_query = '\n'.join( ['CREATE TABLE ' + score_tbl + ' AS SELECT * FROM sdb.' + score_tbl + ' LIMIT 0;' for score_tbl in score_tables] )
848848
else:
849849
create_scores_query = ""
850+
851+
## Get Feature Alignment tables table_present
852+
feature_alignment_tables = [name for name in original_tables if "ALIGNMENT" in name]
853+
feature_alignment_tables_present = False
854+
if len(feature_alignment_tables) > 0:
855+
create_feature_alignment_query = '\n'.join( ['CREATE TABLE ' + feature_alignment_tbl + ' AS SELECT * FROM sdb.' + feature_alignment_tbl + ' LIMIT 0;' for feature_alignment_tbl in feature_alignment_tables] )
856+
feature_alignment_tables_present = True
857+
else:
858+
create_feature_alignment_query = ""
850859

851860
click.echo( '''First File input: %s''' %( infiles[0] ) )
852861

@@ -857,6 +866,9 @@ def merge_oswps(infiles, outfile, templatefile, same_run):
857866
DROP TABLE IF EXISTS FEATURE_MS1;
858867
DROP TABLE IF EXISTS FEATURE_MS2;
859868
DROP TABLE IF EXISTS FEATURE_TRANSITION;
869+
DROP TABLE IF EXISTS FEATURE_ALIGNMENT;
870+
DROP TABLE IF EXISTS FEATURE_MS2_ALIGNMENT;
871+
DROP TABLE IF EXISTS FEATURE_TRANSITION_ALIGNMENT;
860872
DROP TABLE IF EXISTS SCORE_MS1;
861873
DROP TABLE IF EXISTS SCORE_MS2;
862874
DROP TABLE IF EXISTS SCORE_TRANSITION;
@@ -868,10 +880,12 @@ def merge_oswps(infiles, outfile, templatefile, same_run):
868880
CREATE TABLE FEATURE AS SELECT * FROM sdb.FEATURE LIMIT 0;
869881
CREATE TABLE FEATURE_MS1 AS SELECT * FROM sdb.FEATURE_MS1 LIMIT 0;
870882
CREATE TABLE FEATURE_MS2 AS SELECT * FROM sdb.FEATURE_MS2 LIMIT 0;
871-
CREATE TABLE FEATURE_TRANSITION AS SELECT * FROM sdb.FEATURE_TRANSITION LIMIT 0;
883+
CREATE TABLE FEATURE_TRANSITION AS SELECT * FROM sdb.FEATURE_TRANSITION
884+
LIMIT 0;
885+
%s
872886
%s
873887
DETACH DATABASE sdb;
874-
''' % (infiles[0], create_scores_query) )
888+
''' % (infiles[0], create_feature_alignment_query, create_scores_query) )
875889

876890
conn.commit()
877891
conn.close()
@@ -973,7 +987,86 @@ def merge_oswps(infiles, outfile, templatefile, same_run):
973987
conn.close()
974988

975989
click.echo("Info: Merged transition features of file %s to %s." % (infile, outfile))
976-
990+
991+
if feature_alignment_tables_present:
992+
for infile in infiles:
993+
994+
# Check if the infile contains the feature_alignment table
995+
conn = sqlite3.connect(infile)
996+
feature_alignment_present = check_sqlite_table(conn, "FEATURE_ALIGNMENT")
997+
conn.close()
998+
999+
if feature_alignment_present:
1000+
conn = sqlite3.connect(outfile)
1001+
c = conn.cursor()
1002+
1003+
c.executescript('''
1004+
ATTACH DATABASE "%s" AS sdb;
1005+
INSERT INTO FEATURE_ALIGNMENT
1006+
SELECT *
1007+
FROM sdb.FEATURE_ALIGNMENT;
1008+
DETACH DATABASE sdb;
1009+
''' % infile)
1010+
1011+
conn.commit()
1012+
conn.close()
1013+
1014+
click.echo("Info: Merged feature alignment tables of file %s to %s." % (infile, outfile))
1015+
else:
1016+
click.echo("Warn: No feature alignment table found in file %s." % (infile))
1017+
1018+
# Merge FEATURE_MS2_ALIGNMENT
1019+
for infile in infiles:
1020+
1021+
conn = sqlite3.connect(infile)
1022+
feature_ms2_alignment_present = check_sqlite_table(conn, "FEATURE_MS2_ALIGNMENT")
1023+
conn.close()
1024+
1025+
if feature_ms2_alignment_present:
1026+
conn = sqlite3.connect(outfile)
1027+
c = conn.cursor()
1028+
1029+
c.executescript('''
1030+
ATTACH DATABASE "%s" AS sdb;
1031+
INSERT INTO FEATURE_MS2_ALIGNMENT
1032+
SELECT *
1033+
FROM sdb.FEATURE_MS2_ALIGNMENT;
1034+
DETACH DATABASE sdb;
1035+
''' % infile)
1036+
1037+
conn.commit()
1038+
conn.close()
1039+
1040+
click.echo("Info: Merged feature MS2 alignment tables of file %s to %s." % (infile, outfile))
1041+
else:
1042+
click.echo("Warn: No feature MS2 alignment table found in file %s." % (infile))
1043+
1044+
# Merge FEATURE_TRANSITION_ALIGNMENT
1045+
for infile in infiles:
1046+
1047+
conn = sqlite3.connect(infile)
1048+
feature_transition_alignment_present = check_sqlite_table(conn, "FEATURE_TRANSITION_ALIGNMENT")
1049+
conn.close()
1050+
1051+
if feature_transition_alignment_present:
1052+
conn = sqlite3.connect(outfile)
1053+
c = conn.cursor()
1054+
1055+
c.executescript('''
1056+
ATTACH DATABASE "%s" AS sdb;
1057+
INSERT INTO FEATURE_TRANSITION_ALIGNMENT
1058+
SELECT *
1059+
FROM sdb.FEATURE_TRANSITION_ALIGNMENT;
1060+
DETACH DATABASE sdb;
1061+
''' % infile)
1062+
1063+
conn.commit()
1064+
conn.close()
1065+
1066+
click.echo("Info: Merged feature transition alignment tables of file %s to %s." % (infile, outfile))
1067+
else:
1068+
click.echo("Warn: No feature transition alignment table found in file %s." % (infile))
1069+
9771070

9781071
for infile in infiles:
9791072
for score_tbl in score_tables:

0 commit comments

Comments
 (0)