Ejemplo n.º 1
0
def remove_all(conn, mid):
    """
    Removes all entries for a specified molecule
    :param conn: Connection to sqlite3 database
    :param mid: Molecule entry ID (mid) to remove associated peaks
    :return: True, if peaks are removed successfuly, otherwise False
    """
    if (mid_exists(conn, mid) is False):
        print "[ ERROR: Molecule entry does not exist. Cancelling action! ]"
        return False

    conn.execute("DELETE FROM peaks WHERE mid={m}".format(m=mid))
    conn.commit()

    return True
Ejemplo n.º 2
0
def update_category(conn, mid, category):
    """
    Changes the category row of a molecule
    :param conn: Connection to sqlite database
    :param mid: Molecule ID (mid) to make changes
    :param category: New category to replace
    :return: True, if updated successfully
    :return: False, if
    """
    if (mid_exists(conn, mid) is False):
        print "[ ERROR: Molecule entry does not exist. Cancelling action! ]"
        return False

    conn.execute("UPDATE molecules SET category={c} WHERE mid={m}".format(
        c=category, m=mid))
    conn.commit()
    return True
Ejemplo n.º 3
0
def update_name(conn, mid, name):
    """
    Changes the name row of a molecule
    :param conn: Connection to sqlite database
    :param mid: Molecule ID (mid) to make changes
    :param name: New name to replace
    :return: True, if updated successfully
    :return: False, if
    """
    if (mid_exists(conn, mid) is False):
        print "[ ERROR: Molecule entry does not exist. Cancelling action! ]"
        return False

    conn.execute("UPDATE molecules SET name={n} WHERE mid={m}".format(n=name,
                                                                      m=mid))
    conn.commit()
    return True
Ejemplo n.º 4
0
def remove_all(conn, mid):
    """
    Removes all entries for a specified molecule
    :param conn: Connection to sqlite3 database
    :param mid: Molecule entry ID (mid) to remove associated peaks
    :return: True, if assignments are removed successfuly, otherwise False
    """
    if (mid_exists(conn, mid) is False):
        print "[ ERROR: Molecule entry does not exist. Cancelling action! ]"
        return False

    sql="DELETE FROM assignments WHERE aid IN (" \
        " SELECT aid" \
        " FROM peaks INNER JOIN assignments ON (assignments.pid=peaks.pid)"\
        " WHERE peaks.mid={m}" \
        ");".format(m=mid)

    conn.execute(sql)
    conn.commit()

    return True
Ejemplo n.º 5
0
def new_info_entry(conn, mid, vibration, notes):
    """
    Adds a new info entry to info table
    Associative molecule entry must exist, and it's info entry must not.
    :param conn: Connection to sqlite3 database
    :param mid: Molecule ID (mid) for the associate info entry
    :param vibration: Vibration of molecule
    :param notes: Notes regarding the molecule
    :return: Info entry id (iid) of new entry
    :return None if info entry already exists or molecule entry does not exist
    """

    # Check if molecule entry exists
    if mid_exists(conn, mid) is False:
        # Molecule does not exist, ERR return
        print "[ ERROR: Molecule entry does not exist.]"
        return #none

    iid = get_iid(conn, mid)    # Get iid
    # If entry already exists, return that mid.
    if iid is not None:
        # Entry exists
        print "[ ERROR: Info entry already exists.]"
        return #none


    # If entry does not exist.
    # Add new entry to info table
    conn.execute('INSERT INTO info (mid, vibration, notes) VALUES (?,?,?)', (mid, vibration, notes))

    # Get the new entry's info id (iid)
    cursor = conn.execute('SELECT max(mid) FROM info')
    iid = cursor.fetchone()[0]
    print "[ Added entry: iid:" + str(iid) + " to info ]"

    # Commit Changes
    conn.commit()

    return iid
Ejemplo n.º 6
0
def remove_molecule(conn, mid):
    """
    Removes all info, peak and molecule entries of given mid
    :param conn: Sqlite database connection
    :param mid: Molecule ID (mid) of molecule to be removed
    :return: True if successfully removed
    :return: False, if not removed
    """
    if (mid_exists(conn, mid) is False):
        print "[ ERROR: Molecule entry does not exist. Cancelling action! ]"
        return False

    # Delete Info Entry
    conn.execute("DELETE FROM info WHERE mid={m}".format(m=mid))
    # Delete peak entry
    conn.execute("DELETE FROM peaks WHERE mid={m}".format(m=mid))
    # Delete Molecule entry
    conn.execute("DELETE FROM molecules WHERE mid={m}".format(m=mid))

    conn.commit()

    print "[ Successfully removed " + str(mid) + "from database ]"
    return True
Ejemplo n.º 7
0
def import_file(conn, filepath, mid):
    """
    Imports file to peak table in spectrum database to it's associative molecule
    Molecule must exist for import
    Supports '.cat' , '.sp', '.lines' files.
    :param filepath: Path to import file
    :param mid: Molecule ID
    :return:
    """

    # Check if molecule entry exists
    if mid_exists(conn, mid) is False:
        # Molecule does not exist, ERR return
        print "[ ERROR: Molecule entry does not exist. Cancelling action! ]"
        return False

    # Check if file can be opened
    if __checkfile(filepath) is False:
        # File cannot be opened. ERR return
        return False

    # Get File extention
    extention = str.split(filepath, ".")[1]

    # Match extention to its appropriate import function
    if extention == 'cat':
        __import_catfile(conn, filepath, mid)
    elif extention == 'sp':
        __import_spfile(conn, filepath, mid)
    elif extention == 'lines':
        __import_linesfile(conn, filepath, mid)
    else:
        print "Invalid import file. EXTENTION must be: '.cat' , '.sp', '.lines'"
        return False

    return True