Exemple #1
0
def create(labbook_id, ids):
    # verify
    if not plbCore.validID(args.labbook):
        print("'" + labbook_id + "' contains invalid characters")
        sys.exit()
    # does module exist already?
    modfile = labbook_id + ".py"
    modffn = os.path.join(plbLabbookRoot, modfile)

    if os.path.isfile(modffn):
        printwarn("A module already exists for " + labbook_id + ".")
        print("You can delete this labbook by using the delete command.")
        sys.exit()

    if args.dbfile != "":
        if not os.path.isfile(args.dbfile):
            print("Can't find database file " + args.dbfile + "...")
            sys.exit()

    try:
        labbook = pyLabbook(
            id=labbook_id,
            root=plbRoot,
            repositoryPath=os.path.join(plbRepositoryRoot_REL, labbook_id),
            sheetFormat=args.sheetformat,
            databasePath=plbDatabaseRoot_REL,
            databaseFile=labbook_id + ".sqlite3",
            databaseFormat=args.dbformat,
        )
    except Exception as e:
        print("Error initializing: " + str(e))
        sys.exit()

    serialized = labbook.exportSerialized()
    with open(modffn, 'w') as fh:
        fh.write(labbook.exportSerialized())
    # now try to import and create structure
    try:
        labbook = plbCore.import_initialize_labbook(labbook_id, plbRoot)
    except Exception as e:
        print("error importing: " + str(e))
        sys.exit()
    try:
        labbook.createFileStructure()
    except Exception as e:
        print("error creating repository: " + str(e))
        sys.exit()
    if args.dbfile != "":
        try:
            dstfile = os.path.join(plbRoot, labbook.databasePath,
                                   labbook.databaseFile)
            plbCore.copyfile(args.dbfile, dstfile)
        except Exception as e:
            print("error copying " + args.dbfile + ": " + str(e))
            print("Labbook will be created with empty database.")
            print("You can copy " + args.dbfile + " manually to: \n" + dstfile)
    print("Created " + ansi.magenta + modffn + ansi.clear)
    print("Done.")
Exemple #2
0
def remove(labbook_id, ids):
    if len(ids) < 1:
        print("No protocol ids specified...  Nothing to do.")
        sys.exit()
    # validate ids
    if not plbCore.validID(args.labbook):
        print("'" + labbook_id + "' contains invalid characters")
        sys.exit()
    for pid in ids:
        if not plbCore.validID(pid):
            print("'" + pid + "' contains invalid characters")
            sys.exit()
    # warn user
    printwarn("About to remove repository paths for:")
    print("\n".join([
        ansi.magenta + labbook_id + ansi.cyan + '@' + ansi.magenta + pid +
        ansi.clear for pid in ids
    ]))
    print("This will delete ALL associated files and subfolders including +"
          "raw data files.")
    try:
        if prompt("is this what you want", ['y', 'n'], default='n') == 'n':
            print("Okay, exiting.")
            sys.exit()
    except Exception as e:
        print("Sorry, I didn't understand that.")
        sys.exit()
    # confirm
    try:
        if prompt("Are your really really sure", ['y', 'n'],
                  default='n') == 'n':
            print("Okay, exiting.")
            sys.exit()
    except Exception as e:
        print("Sorry, I didn't understand that.")
        sys.exit()

    # initialize labbook and import protocols
    try:
        labbook = plbCore.import_initialize_labbook(labbook_id, plbRoot)
    except Exception as e:
        print("Error importing " + labbook_id + ": " + str(e))
        sys.exit()
    print("Removing protocol paths:")
    for pid in ids:
        try:
            protocol = plbCore.import_initialize_protocol(pid, labbook)
        except Exception as e:
            print(ansi.red + "ERROR" + ansi.clear)
            print("couldn't initialize: " + str(e))
            continue

        print("Deleting path " + ansi.green + protocol.protocolroot() +
              ansi.clear + ": ",
              end='',
              flush=True)
        try:
            plbCore.rmpath(protocol.protocolroot(), require_empty=False)
        except Exception as e:
            print(ansi.red + "ERROR" + ansi.clear)
            print("Couldn't delete: " + str(e))
            continue
        print(ansi.green + "OK" + ansi.clear)

    print("Done.")
Exemple #3
0
def drop(labbook_id, ids):
    if len(ids) < 1:
        print("No protocol ids specified...  Nothing to do.")
        sys.exit()
    # validate ids
    if not plbCore.validID(args.labbook):
        print("'" + labbook_id + "' contains invalid characters")
        sys.exit()
    for pid in ids:
        if not plbCore.validID(pid):
            print("'" + pid + "' contains invalid characters")
            sys.exit()
    # warn user
    printwarn("About to drop the following protocol set/sample tables:")
    print("\n".join([
        ansi.magenta + labbook_id + ansi.cyan + '@' + ansi.magenta + pid +
        ansi.clear for pid in ids
    ]))
    print("This will delete all associated database records.")
    try:
        if prompt("is this what you want", ['y', 'n'], default='n') == 'n':
            print("Okay, exiting.")
            sys.exit()
    except Exception as e:
        print("Sorry, I didn't understand that.")
        sys.exit()
    # confirm
    try:
        if prompt("Are your really really sure", ['y', 'n'],
                  default='n') == 'n':
            print("Okay, exiting.")
            sys.exit()
    except Exception as e:
        print("Sorry, I didn't understand that.")
        sys.exit()

    # initialize labbook and import protocols
    try:
        labbook = plbCore.import_initialize_labbook(labbook_id, plbRoot)
    except Exception as e:
        print("Error importing " + labbook_id + ": " + str(e))
        sys.exit()
    print("Dropping protocol tables:")
    for pid in ids:
        print(ansi.magenta + labbook.id + ansi.cyan + '@' + ansi.magenta +
              pid + ansi.clear + ": ",
              end='',
              flush=True)
        try:
            protocol = plbCore.import_initialize_protocol(pid, labbook)
        except Exception as e:
            print(ansi.red + "ERROR" + ansi.clear)
            print("couldn't initialize: " + str(e))
            continue

        protocol.connect()
        try:
            protocol.dropSetSampleTables()
        except Exception as e:
            print(ansi.red + "ERROR" + ansi.clear)
            print("Couldn't drop tables: " + str(e))
            continue
        protocol.disconnect()
        print(ansi.green + "OK" + ansi.clear)

    print("Done.")
Exemple #4
0
def delete(labbook_id, ids):
    # verify
    if not plbCore.validID(args.labbook):
        print("'" + labbook_id + "' contains invalid characters")
        sys.exit()
    # does module exist?
    modfile = labbook_id + ".py"
    modffn = os.path.join(plbLabbookRoot, modfile)
    if not os.path.isfile(modffn):
        print("No module found for " + labbook_id + "...  Nothing to do.")
        sys.exit()
    # warn user
    printwarn(ansi.red + "This action will delete all repository files and " +
              "databases belonging to " + labbook_id + "." + ansi.clear)
    try:
        if prompt("Are you really really sure", ['y', 'n'],
                  default='n') == 'n':
            print("Phew!  That would have been awful...")
            sys.exit()
    except Exception as e:
        print("Sorry, I don't understand that...  Exiting.")
        sys.exit()

    # confirm
    try:
        if prompt("Are you sure you're sure", ['y', 'n'], default='n') == 'n':
            print("Phew!  That would have been awful...")
            sys.exit()
    except Exception as e:
        print("Sorry, I don't understand that...  Exiting.")
        sys.exit()

    # import and initialize and delete...
    try:
        labbook = plbCore.import_initialize_labbook(labbook_id, plbRoot)
    except Exception as e:
        print("can't import " + labbook_id + ": " + str(e))
        sys.exit()

    print("Deleting " + ansi.magenta + labbook.id + ansi.clear +
          " repository: ",
          end='',
          flush=True)
    try:
        labbook.deleteFileStructure(require_empty=False)
    except Exception as e:
        print(ansi.red + "ERROR" + ansi.clear)
        print(str(e))
        sys.exit()
    print(ansi.green + "OK" + ansi.clear)

    print("Deleting " + ansi.magenta + modffn + ansi.clear + ": ",
          end='',
          flush=True)
    try:
        os.remove(modffn)
    except Exception as e:
        print(ansi.red + "ERROR" + ansi.clear)
        print(str(e))
        sys.exit()
    print(ansi.green + "OK" + ansi.clear)

    print("Done.")
Exemple #5
0
        "Note that each sample should represent a plasmid component with a "+
        "concentration and molar mass.\n"+
        "If the recipe calculation for a set generates an error, the sample "+
        "file records for that set will remain UNALTERED, so you can preserve "+
        "manual calculations if you like."
    ),
);
parser.add_argument(    'labbook',
                        help=("id of the labbook containing Transfection experiments"),
                        type=str,
);
parser.add_argument(    'experiment_ids',
                        nargs='+',
                        default=[],
                        help=("space separated list of experiment id's to calculate recipes for"),
);
args = parser.parse_args();
################################################################################
labbook = plbCore.import_initialize_labbook("testbook", plbRoot);
protocol = plbCore.import_initialize_protocol("Transfection", labbook);
################################################################################
try:
    sets = protocol.loadSetFile(args.experiment_ids);
    sams = protocol.loadSamFile(args.experiment_ids)
except Exception as e:
    print("Error loading set/sample files: "+str(e));
    sys.exit();
################################################################################
sets, sams = protocol.calculate_recipes(sets, sams);
protocol.writeSams(sams);
Exemple #6
0
    printok()
except Exception as e:
    printerr(str(e))

try:
    lb_modfile = os.path.join(plbLabbookRoot, 'testLabbook.py')
    printtest("Serializing")
    with open(lb_modfile, 'w') as fh:
        fh.write(lb.exportSerialized())
    printok()
except Exception as e:
    printerr(str(e))

try:
    printtest("Importing")
    lb = core.import_initialize_labbook('testLabbook', plbRoot)
    print(ansi.green + lb.id + ansi.clear)
except Exception as e:
    printerr(str(e))

try:
    printtest("Repository")
    lb.createFileStructure()
    if not os.path.isdir(os.path.join(lb.root, lb.repositoryPath)):
        raise Exception("Not found")
    printok()
except Exception as e:
    printerr(str(e))

try:
    printtest("Creating sample protocol")
Exemple #7
0
if not plbCore.validID(labbook_id):
    print("labbook '" + labbook_id + "' has invalid characters.")
    sys.exit()
if not plbCore.validID(protocol_id):
    print("labbook '" + protocol_id + "' has invalid characters.")
    sys.exit()
# check for source labbook and protocol modules
protocol_module = protocol_id + '.py'
labbook_module = labbook_id + '.py'
if not os.path.isfile(os.path.join(plbLabbookRoot, labbook_module)):
    print("Can't find labbook module file " + labbook_module + ".")
    sys.exit()
if not os.path.isfile(os.path.join(plbProtocolRoot, protocol_module)):
    print("Can't find protocol module file " + protocol_module + ".")
    sys.exit()
# import and initialize source
try:
    labbook = plbCore.import_initialize_labbook(labbook_id, plbRoot)
except Exception as e:
    print("Error initializing " + labbook_id + ": " + str(e))
    sys.exit()
try:
    protocol = plbCore.import_initialize_protocol(protocol_id, labbook)
except Exception as e:
    print("Error initializing " + protocol_id + ": " + str(e))
    sys.exit()
# call command
command_map[args.command](labbook, protocol, args.arguments)

#
Exemple #8
0
        sys.exit()
    try:
        plbCore.import_protocol(pid)
    except Exception as e:
        print(str(e))
        sys.exit()

# verify labbooks and initialize labbook@protocol combos
lp_objects = []
for lid in items['labbook_id'].unique():
    file = os.path.join(plbLabbookRoot, lid + ".py")
    if not os.path.isfile(file):
        print("Can't find " + file + ".")
        sys.exit()
    try:
        labbooks[id] = plbCore.import_initialize_labbook(lid, plbRoot)
    except Exception as e:
        print("Can't import module " + file + ".")
        sys.exit()
    # subset and do protocols
    ss_lb = items[items['labbook_id'] == lid]
    for pid in ss_lb['protocol_id'].unique():
        # initialize and store into row
        try:
            protocol = plbCore.initialize_protocol(pid, labbooks[id])
        except Exception as e:
            print(str(e))
            sys.exit()
        row = pd.Series({
            'labbook_id': lid,
            'protocol_id': pid,