PyProphet / pyprophet

PyProphet: Semi-supervised learning and scoring of OpenSWATH results.
http://www.openswath.org
BSD 3-Clause "New" or "Revised" License
29 stars 21 forks source link

Back propagate fails if 'SCORE_PROTEIN' isn't in apply_scores #39

Closed bretttully closed 5 years ago

bretttully commented 5 years ago

Suggested edit -- but haven't got full enough understanding of the code to know if this is worth a PR and there doesn't appear to be any tests that cover this function

def backpropagate_oswr(infile, outfile, apply_scores):
    # store data in table
    if infile != outfile:
        copyfile(infile, outfile)

    # find out what tables exist in the scores
    score_con = sqlite3.connect(apply_scores)
    transition_present = check_sqlite_table(score_con, "SCORE_TRANSITION")
    peptide_present = check_sqlite_table(score_con, "SCORE_PEPTIDE")
    protein_present = check_sqlite_table(score_con, "SCORE_PROTEIN")
    score_con.close()
    if not (transition_present or peptide_present or protein_present):
        raise RuntimeError('You must have at least one score table present')

    # build up the list
    script = list()
    script.append('PRAGMA synchronous = OFF;')
    script.append('DROP TABLE IF EXISTS SCORE_TRANSITION;')
    script.append('DROP TABLE IF EXISTS SCORE_PEPTIDE;')
    script.append('DROP TABLE IF EXISTS SCORE_PROTEIN;')

    # create the tables
    create_table_fmt = 'CREATE TABLE {} (CONTEXT TEXT, RUN_ID INTEGER, PEPTIDE_ID INTEGER, SCORE REAL, PVALUE REAL, QVALUE REAL, PEP REAL);'
    if transition_present:
        script.append(create_table_fmt.format('SCORE_TRANSITION'))
    if peptide_present:
        script.append(create_table_fmt.format('SCORE_PEPTIDE'))
    if protein_present:
        script.append(create_table_fmt.format('SCORE_PROTEIN'))

    # copy across the tables
    script.append(f'ATTACH DATABASE "{apply_scores}" AS sdb;')
    insert_table_fmt = 'INSERT INTO {0}\nSELECT *\nFROM sdb.{0};'
    if transition_present:
        script.append(insert_table_fmt.format('SCORE_TRANSITION'))
    if peptide_present:
        script.append(insert_table_fmt.format('SCORE_PEPTIDE'))
    if protein_present:
        script.append(insert_table_fmt.format('SCORE_PROTEIN'))

    # execute the scriptl
    conn = sqlite3.connect(outfile)
    c = conn.cursor()
    c.executescript('\n'.join(script))
    conn.commit()
    conn.close()

    click.echo("Info: All multi-run data was backpropagated.")
bretttully commented 5 years ago

Worth saying, that this works on my machine when pyprohpet protein hasn't been called on a file

grosenberger commented 5 years ago

Thanks for the error report. I will implement the proposed changes and make a new release today or tomorrow.

grosenberger commented 5 years ago

Ok, the patch is integrated in master. Could you please check whether the issue is resolved?

bretttully commented 5 years ago

Once I've got the hotfix 2.4.1 merged in to OpenMS, I'll put both into our Docker image and run some tests. Thanks for such a quick turn around!

bretttully commented 5 years ago

Hi @grosenberger -- just noticed this on the PR above: https://github.com/PyProphet/pyprophet/pull/40#commitcomment-31610738