Example #1
0
    for mandatory_key in MANDATORY_KEYS:
        if mandatory_key not in field_names:
            raise GenestackException(
                "The key '%s' must be supplied in the CSV file" %
                mandatory_key)

    for file_data in reader:

        # for each entry, prepare a BioMetainfo object
        metainfo = BioMetainfo()
        for key in field_names:
            # 'link' and 'organism' are treated separately, as they are added to the metainfo using specific methods
            if key == "link":
                url = file_data[key]
                metainfo.add_external_link(key=BioMetainfo.READS_LINK,
                                           text="link",
                                           url=url,
                                           fmt=file_format)
            elif key == "organism":
                metainfo.add_organism(BioMetainfo.ORGANISM, file_data[key])
            # all the other keys are added as strings
            else:
                metainfo_key = SPECIAL_KEYS.get(key.lower(), key)
                metainfo.add_string(metainfo_key, file_data[key])

        # create the sequencing assay on Genestack
        created_file = importer.create_sequencing_assay(experiment,
                                                        metainfo=metainfo)

        print "Created file '%s' (%s)" % (file_data['name'], created_file)

print "All done! Bye now..."
    reader = csv.DictReader(the_file, delimiter=",")
    field_names = reader.fieldnames

    # check if mandatory keys are in the CSV file
    for mandatory_key in MANDATORY_KEYS:
        if mandatory_key not in field_names:
            raise GenestackException("The key '%s' must be supplied in the CSV file" % mandatory_key)

    for file_data in reader:

        # for each entry, prepare a BioMetainfo object
        metainfo = BioMetainfo()
        for key in field_names:
            # 'link' and 'organism' are treated separately, as they are added to the metainfo using specific methods
            if key == "link":
                url = file_data[key]
                metainfo.add_external_link(key=BioMetainfo.READS_LINK, text="link", url=url, fmt=file_format)
            elif key == "organism":
                metainfo.add_organism(BioMetainfo.ORGANISM, file_data[key])
            # all the other keys are added as strings
            else:
                metainfo_key = SPECIAL_KEYS.get(key.lower(), key)
                metainfo.add_string(metainfo_key, file_data[key])

        # create the sequencing assay on Genestack
        created_file = importer.create_sequencing_assay(experiment, metainfo=metainfo)

        print "Created file '%s' (%s)" % (file_data['name'], created_file)

print "All done! Bye now..."