Exemplo n.º 1
0
    def _test_parsing_context(self):
        """
            Create a small csv file, use populate_metadata.py to parse and
            attach to Plate. Then query to check table has expected content.
        """

        ctx = ParsingContext(self.client, self.plate, file=self.csvName)
        ctx.parse()
        ctx.write_to_omero()

        # Get file annotations
        anns = self.get_plate_annotations()
        # Only expect a single annotation which is a 'bulk annotation'
        assert len(anns) == 1
        tableFileAnn = anns[0]
        assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS
        fileid = tableFileAnn.file.id.val

        # Open table to check contents
        r = self.client.sf.sharedResources()
        t = r.openTable(OriginalFileI(fileid), None)
        cols = t.getHeaders()
        rows = t.getNumberOfRows()
        assert rows == self.rowCount * self.colCount
        for hit in range(rows):
            rowValues = [col.values[0] for col in t.read(range(len(cols)),
                                                         hit, hit+1).columns]
            assert len(rowValues) == 4
            if "a1" in rowValues:
                assert "Control" in rowValues
            elif "a2" in rowValues:
                assert "Treatment" in rowValues
            else:
                assert False, "Row does not contain 'a1' or 'a2'"
def populate_metadata(client, conn, script_params):
    object_id = long(script_params["IDs"])
    file_id = long(script_params["File_ID"])
    original_file = get_original_file(
        conn, script_params["Data_Type"], object_id, file_id)
    provider = DownloadingOriginalFileProvider(conn)
    file_handle = provider.get_original_file_data(original_file)
    if script_params["Data_Type"] == "Plate":
        omero_object = PlateI(long(object_id), False)
    else:
        omero_object = ScreenI(long(object_id), False)
    ctx = ParsingContext(client, omero_object, "")
    ctx.parse_from_handle(file_handle)
    ctx.write_to_omero()
    def testPopulateMetadataPlate(self):
        """
            Create a small csv file, use populate_metadata.py to parse and
            attach to Plate. Then query to check table has expected content.
        """

        csvName = "testCreate.csv"
        self.createCsv(csvName)
        rowCount = 1
        colCount = 2
        plate = self.createPlate(rowCount, colCount)
        ctx = ParsingContext(self.client, plate, csvName)
        ctx.parse()
        ctx.write_to_omero()
        # Delete local temp file
        os.remove(csvName)

        # Get file annotations
        query = """select p from Plate p
            left outer join fetch p.annotationLinks links
            left outer join fetch links.child
            where p.id=%s""" % plate.id.val
        qs = self.client.sf.getQueryService()
        plate = qs.findByQuery(query, None)
        anns = plate.linkedAnnotationList()
        # Only expect a single annotation which is a 'bulk annotation'
        assert len(anns) == 1
        tableFileAnn = anns[0]
        assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS
        fileid = tableFileAnn.file.id.val

        # Open table to check contents
        r = self.client.sf.sharedResources()
        t = r.openTable(OriginalFileI(fileid), None)
        cols = t.getHeaders()
        rows = t.getNumberOfRows()
        assert rows == rowCount * colCount
        for hit in range(rows):
            rowValues = [col.values[0] for col in t.read(range(len(cols)),
                                                         hit, hit+1).columns]
            assert len(rowValues) == 4
            if "a1" in rowValues:
                assert "Control" in rowValues
            elif "a2" in rowValues:
                assert "Treatment" in rowValues
            else:
                assert False, "Row does not contain 'a1' or 'a2'"
    def populate_data(self, csv, cfg):
        row_count = 1
        col_count = 6
        self.screen, self.plate = self.create_screen(row_count, col_count)

        ctx = ParsingContext(self.client, self.screen.proxy(), file=csv)
        ctx.parse()
        ctx.write_to_omero()

        # Get file annotations
        anns = self.get_screen_annotations()
        # Only expect a single annotation which is a 'bulk annotation'
        assert len(anns) == 1
        table_file_ann = anns[0]
        assert unwrap(table_file_ann.getNs()) == NSBULKANNOTATIONS
        fileid = table_file_ann.file.id.val

        ctx = BulkToMapAnnotationContext(
            self.client, self.screen.proxy(), fileid=fileid, cfg=cfg)
        ctx.parse()
        ctx.write_to_omero()
def populate_metadata(client, conn, script_params):
    object_id = int(script_params["IDs"])
    file_id = int(script_params["File_ID"])
    original_file = get_original_file(conn, script_params["Data_Type"],
                                      object_id, file_id)
    provider = DownloadingOriginalFileProvider(conn)
    file_handle = provider.get_original_file_data(original_file)
    if script_params["Data_Type"] == "Plate":
        omero_object = PlateI(int(object_id), False)
    else:
        omero_object = ScreenI(int(object_id), False)
    ctx = ParsingContext(client, omero_object, "")
    ctx.parse_from_handle(file_handle)
    ctx.write_to_omero()
Exemplo n.º 6
0
    def testPopulateMetadataPlate(self):
        """
            Create a small csv file, use populate_metadata.py to parse and
            attach to Plate. Then query to check table has expected content.
        """

        csvName = "testCreate.csv"
        self.createCsv(csvName)
        rowCount = 1
        colCount = 2
        plate = self.createPlate(rowCount, colCount)
        ctx = ParsingContext(self.client, plate, csvName)
        ctx.parse()
        ctx.write_to_omero()
        # Delete local temp file
        os.remove(csvName)

        # Get file annotations
        query = """select p from Plate p
            left outer join fetch p.annotationLinks links
            left outer join fetch links.child
            where p.id=%s""" % plate.id.val
        qs = self.client.sf.getQueryService()
        plate = qs.findByQuery(query, None)
        anns = plate.linkedAnnotationList()
        # Only expect a single annotation which is a 'bulk annotation'
        assert len(anns) == 1
        tableFileAnn = anns[0]
        assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS
        fileid = tableFileAnn.file.id.val

        # Open table to check contents
        r = self.client.sf.sharedResources()
        t = r.openTable(OriginalFileI(fileid), None)
        cols = t.getHeaders()
        rows = t.getNumberOfRows()
        assert rows == rowCount * colCount
        for hit in range(rows):
            rowValues = [
                col.values[0]
                for col in t.read(range(len(cols)), hit, hit + 1).columns
            ]
            assert len(rowValues) == 4
            if "a1" in rowValues:
                assert "Control" in rowValues
            elif "a2" in rowValues:
                assert "Treatment" in rowValues
            else:
                assert False, "Row does not contain 'a1' or 'a2'"
Exemplo n.º 7
0
def populate_metadata(client, conn, script_params):
    object_ids = script_params["IDs"]
    object_id = object_ids[0]
    file_ann_id = None
    if "File_Annotation" in script_params:
        file_ann_id = long(script_params["File_Annotation"])
    data_type = script_params["Data_Type"]
    original_file = get_original_file(conn, data_type, object_id, file_ann_id)
    provider = DownloadingOriginalFileProvider(conn)
    file_handle = provider.get_original_file_data(original_file)
    if data_type == "Plate":
        omero_object = PlateI(long(object_id), False)
    else:
        omero_object = ScreenI(long(object_id), False)
    ctx = ParsingContext(client, omero_object, "")
    ctx.parse_from_handle(file_handle)
    ctx.write_to_omero()
    return "Table data populated for %s: %s" % (data_type, object_id)
Exemplo n.º 8
0
    def _test_parsing_context(self):
        """
            Create a small csv file, use populate_metadata.py to parse and
            attach to Plate. Then query to check table has expected content.
        """

        ctx = ParsingContext(self.client, self.plate, file=self.csvName)
        ctx.parse()
        ctx.write_to_omero()

        # Get file annotations
        anns = self.get_plate_annotations()
        # Only expect a single annotation which is a 'bulk annotation'
        assert len(anns) == 1
        tableFileAnn = anns[0]
        assert unwrap(tableFileAnn.getNs()) == NSBULKANNOTATIONS
        fileid = tableFileAnn.file.id.val

        # Open table to check contents
        r = self.client.sf.sharedResources()
        t = r.openTable(OriginalFileI(fileid), None)
        cols = t.getHeaders()
        rows = t.getNumberOfRows()
        assert rows == self.rowCount * self.colCount
        for hit in range(rows):
            rowValues = [
                col.values[0]
                for col in t.read(range(len(cols)), hit, hit + 1).columns
            ]
            assert len(rowValues) == 4
            if "a1" in rowValues:
                assert "Control" in rowValues
            elif "a2" in rowValues:
                assert "Treatment" in rowValues
            else:
                assert False, "Row does not contain 'a1' or 'a2'"
Exemplo n.º 9
0
# ===================================================
orig_table_file = conn.getObject(
    "OriginalFile", attributes={'name': tablename})    # if name is unique
savedTable = conn.c.sf.sharedResources().openTable(orig_table_file._obj)
print "Opened table with row-count:", savedTable.getNumberOfRows()


# Populate a table on a Plate from a csv file
# ===========================================
colNames = "Well, Well Type, Concentration\n"
csvLines = [
    colNames,
    "A1, Control, 0\n",
    "A2, Treatment, 5\n",
    "A3, Treatment, 10\n"]
with open('data.csv', 'w') as csvData:
    csvData.writelines(csvLines)
plate = conn.getObject("Plate", plateId)
target_object = plate._obj
client = conn.c
ctx = ParsingContext(client, target_object, 'data.csv')
ctx.parse()
ctx.write_to_omero()
os.remove('data.csv')


# Close connection
# ================
# When you are done, close the session to free up server resources.
conn._closeSession()
Exemplo n.º 10
0
    def populate_data(self, csv, cfg):
        row_count = 1
        col_count = 6
        self.screen, self.plate = self.create_screen(row_count, col_count)

        ctx = ParsingContext(self.client, self.screen.proxy(), file=csv)
        ctx.parse()
        ctx.write_to_omero()

        # Get file annotations
        anns = self.get_screen_annotations()
        # Only expect a single annotation which is a 'bulk annotation'
        assert len(anns) == 1
        table_file_ann = anns[0]
        assert unwrap(table_file_ann.getNs()) == NSBULKANNOTATIONS
        fileid = table_file_ann.file.id.val

        ctx = BulkToMapAnnotationContext(
         self.client, self.screen.proxy(), fileid=fileid, cfg=cfg)
        ctx.parse()
        ctx.write_to_omero()
Exemplo n.º 11
0
# ===================================================
orig_table_file = conn.getObject(
    "OriginalFile", attributes={'name': table_name})    # if name is unique
saved_table = resources.openTable(orig_table_file._obj)
print("Opened table with row-count:", saved_table.getNumberOfRows())
saved_table.close()

# Populate a table on a Plate from a csv file
# ===========================================
col_names = "Well, Well Type, Concentration\n"
csv_lines = [
    col_names,
    "A1, Control, 0\n",
    "A2, Treatment, 5\n",
    "A3, Treatment, 10\n"]
with open('data.csv', 'w') as csv_data:
    csv_data.writelines(csv_lines)
plate = conn.getObject("Plate", plateId)
target_object = plate._obj
client = conn.c
ctx = ParsingContext(client, target_object, 'data.csv')
ctx.parse()
ctx.write_to_omero()
os.remove('data.csv')


# Close connection
# ================
# When you are done, close the session to free up server resources.
conn.close()