def new_entry(conn, mid, units, notes):
    """
    Adds a new entry to the ArtifactInfo table
    If molecule already exists, returns null
    :param conn: Sqlite3 database connection
    :param mid: Molecule id of the associated molecule
    :param type:  type of experiment
    :param units: frequency units (i.e [MHz, cm-1]
    :param composition: composition of the molecule (i.e C2H2)
    :param notes: additional information
    :return:
    """

    if mid_exists(conn, mid) is False:
        return "[ERROR: Molecule entry does not exist!"
    elif info_exists(conn, mid) is True:
        # If entry already exists, return that mid.
        return "[ ERROR: ArtifactInfo entry associated already exists. Cancelling action. ]"

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

    print "[ Added info entry: " + mid + " to molecules ]"

    # Get the new entry's id (iid)
    cursor = conn.execute('SELECT max(kid) FROM ArtifactInfo')
    kid = cursor.fetchone()[0]

    # Commit Changes
    conn.commit()

    return kid
def new_artifact_entry(conn, mid, notes):
    """
    Adds a new entry to the KnownInfo table
    If molecule already exists, returns null
    :param conn: Sqlite3 database connection
    :param mid: Molecule id of the associated molecule
    :param type:  type of experiment
    :param units: frequency units (i.e [MHz, cm-1]
    :param composition: composition of the molecule (i.e C2H2)
    :param notes: additional information
    :return:
    """

    if mid_exists(conn, mid) is False:
        return "[ERROR: Molecule entry does not exist!"
    elif info_exists(conn, mid) is True:
        # If entry already exists, return that mid.
        return "[ ERROR: KnownInfo entry associated already exists. Cancelling action. ]"

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

    print "[ Added info entry: " + str(mid) + " to molecules ]"

    # Get the new entry's id (iid)
    cursor = conn.execute('SELECT max(kid) FROM KnownInfo')
    kid = cursor.fetchone()[0]

    # Commit Changes
    conn.commit()

    return kid
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
Beispiel #4
0
def import_file(conn, filepath, mid, peaks=False):
    """
    Imports file to peak table in spectrum database to it's associative molecule
    Molecule must exist for import
    Supports '.cat' , '.sp', '.lines', '.list', .txt', 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]
    print(extention)

    # 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)
    elif extention == 'dpt':
        __import_dptfile(conn, filepath, mid)
    elif extention == 'txt':
        __import_txtfile(conn, filepath, mid, peaks)
    elif extention == 'list':
        __import_listfile(conn, filepath, mid)
    elif extention == 'ftb':
        __import_ftbfile(conn, filepath, mid, peaks)
    else:
        print "Invalid import file. EXTENTION must be: '.cat' , '.sp', '.lines'"
        return False

    return True
def import_file(conn, filepath, mid, peaks=False):
    """
    Imports file to peak table in spectrum database to it's associative molecule
    Molecule must exist for import
    Supports '.cat' , '.sp', '.lines', '.list', .txt', 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)
    elif extention == 'dpt':
        __import_dptfile(conn, filepath, mid)
    elif extention == 'txt':
        __import_txtfile(conn, filepath, mid, peaks)
    elif extention == 'list':
        __import_listfile(conn, filepath, mid)
    elif extention == 'ftb':
        __import_ftbfile(conn, filepath, mid, peaks)
    else:
        print "Invalid import file. EXTENTION must be: '.cat' , '.sp', '.lines'"
        return False

    return True
Beispiel #6
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
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