Exemplo n.º 1
0
def form_gate(gate):
    """Deconvolutes string flow gate object"""
    vertices = ast.literal_eval(
        textwrap.dedent(str(gate).split("Vertices: ")[1].split("Channel")[0]))
    channels = ast.literal_eval(
        textwrap.dedent(str(gate).split("Channel(s): ")[1].split("Name")[0]))
    return PolyGate(vertices, channels)
Exemplo n.º 2
0
def makeGate(lowerCorner, upperCorner, channels, name):
    """Returns square gate using upper and lower corners"""
    return PolyGate([(lowerCorner[0], lowerCorner[1]),
                     (upperCorner[0], lowerCorner[1]),
                     (upperCorner[0], upperCorner[1]),
                     (lowerCorner[0], upperCorner[1])],
                    channels,
                    region='in',
                    name=name)
Exemplo n.º 3
0
import matplotlib.pyplot as plt
#%%
datadir = '/Users/oyleryaniva/Documents/Python/Comps'
pattern = 'Compensation'
Comps = LFS.FlowData(datadir, pattern)
#Comps = Comps.asinhtform(Comps.fluorescent_channel_names,150)

#%%
Comps.samples[0].view_interactively()
#%% general gates
from FlowCytometryTools import PolyGate

gate1 = PolyGate([(3.030e+04, 6.309e+04), (3.266e+04, 2.436e+04),
                  (4.636e+04, 1.281e+04), (1.531e+05, 1.893e+04),
                  (2.609e+05, 1.147e+05), (2.481e+05, 2.248e+05),
                  (1.834e+05, 2.445e+05), (9.597e+04, 2.105e+05)],
                 ('FSC-A', 'SSC-A'),
                 region='in',
                 name='gate1')
gate2 = PolyGate([(2.102e+04, 7.858e+04), (1.157e+05, 8.865e+04),
                  (1.477e+05, 7.507e+04), (1.414e+05, 6.456e+04),
                  (1.884e+04, 6.368e+04), (1.884e+04, 6.368e+04)],
                 ('SSC-H', 'SSC-W'),
                 region='in',
                 name='gate2')
Comps = Comps.gate(gate1).gate(gate2)
#Comps1 = Comps1.gate(gate1)

#%% Gating individual samples
from FlowCytometryTools import ThresholdGate
Exemplo n.º 4
0
    def rePlot(self,UIIndex,fileIndex):
        #Clear plot and replot
        plot = self.UIDic["Plots"][UIIndex]
        plot.clear()
        xSelect = self.UIDic["XAxisSelectors"][UIIndex]
        ySelect = self.UIDic["YAxisSelectors"][UIIndex]

        #Check if we are gating and if yes gate
        gating = False
        for checkBox in self.UIDic["GateCheckBoxes"]:
            if checkBox.isChecked():
                gating=True
                gateIndex = self.UIDic["GateCheckBoxes"].index(checkBox)
                break
        if gating:
            #Get coords of
            data = self.dataDic["Data"][fileIndex]
            roi = self.UIDic["ROIs"][gateIndex]
            gateBounds = roi.parentBounds()
            x1 = gateBounds.bottomLeft().x()
            x2 = gateBounds.bottomRight().x()
            y1 = gateBounds.topLeft().y()
            y2 = gateBounds.bottomRight().y()
            xChannel = str(self.UIDic["XAxisSelectors"][gateIndex].currentText())
            yChannel = str(self.UIDic["YAxisSelectors"][gateIndex].currentText())
            gate = PolyGate([(x1,y1),(x2,y1),(x2,y2),(x1,y2)],channels = [xChannel,yChannel])
            data = data.gate(gate)
        else:
            data = self.dataDic["Data"][fileIndex]


        if str(ySelect.currentText()) == "Events":
            z = data[str(xSelect.currentText())]
            if len(z) > 0:
                y,x = np.histogram(z, bins=np.linspace(min(z), max(z), max(z)/500))
                curve = pg.PlotCurveItem(x, y, stepMode=True, fillLevel=0, brush=(0, 0, 255, 80))
                for reigon in self.UIDic["AverageReigons"][UIIndex]:
                    x1,x3
            else:
                curve = pg.PlotCurveItem([], [])

        else:
            curve = pg.ScatterPlotItem(pen=None,brush=(1,2),pxMode=True,size=2)
            x = data[str(xSelect.currentText())]
            y = data[str(ySelect.currentText())]
            if self.UIDic["LogXAxis"][UIIndex].isChecked():
                #x = np.sign(x)* np.log10(abs(x) + 1)
                x = np.log(x + abs(min(x)) + 1)
            if self.UIDic["LogYAxis"][UIIndex].isChecked():
                #y = np.sign(y)* np.log10(abs(y) + 1)
                y = np.log(y + abs(min(y)) + 1)
            curve.setData(x,y)
        self.UIDic["PlotData"][UIIndex] = data
        self.UIDic["Plots"][UIIndex].addItem(curve)
        #Add axis labels
        self.UIDic["Plots"][UIIndex].setLabel('left', str(self.UIDic["YAxisSelectors"][UIIndex].currentText()))
        self.UIDic["Plots"][UIIndex].setLabel('bottom', str(self.UIDic["XAxisSelectors"][UIIndex].currentText()))

        #Add reigons we cleared
        if str(ySelect.currentText()) == "Events":
            for reigon in self.UIDic["AverageReigons"][UIIndex]:
                self.UIDic["Plots"][UIIndex].addItem(reigon)
Exemplo n.º 5
0
def makeFigure():
    """Get a list of the axis objects and create a figure"""

    ax, f = getSetup((10, 8), (3, 4), multz={8: 1, 10: 1})
    subplotLabel(ax)

    Tcell_pathname = path_here + "/data/flow/2019-11-08 monomer IL-2 Fc signaling/CD4 T cells - IL2-060 mono, IL2-060 dimeric"
    NK_CD8_pathname = path_here + "/data/flow/2019-11-08 monomer IL-2 Fc signaling/NK CD8 T cells - IL2-060 mono, IL2-060 dimeric"

    Tcell_sample, _ = importF2(Tcell_pathname, "A")
    NK_CD8_sample, _ = importF2(NK_CD8_pathname, "A")

    Tcell_sample = combineWells(Tcell_sample).subsample(0.2)
    NK_CD8_sample = combineWells(NK_CD8_sample).subsample(0.2)

    Tcell_sample = applyMatrix(Tcell_sample,
                               compMatrix('2019-11-08', '1', 'A'))
    NK_CD8_sample = applyMatrix(NK_CD8_sample,
                                compMatrix('2019-11-08', '1', 'B'))

    Tcell_sample = Tcell_sample.transform(
        "tlog", channels=['VL1-H', 'VL4-H', 'BL1-H',
                          'BL3-H'])  # Tlog transformations
    NK_CD8_sample = NK_CD8_sample.transform(
        "tlog", channels=['RL1-H', 'VL4-H', 'BL1-H',
                          'BL2-H'])  # Tlog transformations

    cd4_gate = ThresholdGate(6500.0, ['VL4-H'],
                             region='above') & ThresholdGate(8000.0, ['VL4-H'],
                                                             region='below')
    ax[0] = Tcell_sample.plot(['VL4-H'], gates=cd4_gate, ax=ax[0])  # CD4
    plt.title("Singlet Lymphocytes")
    #ax.set(xlabel= "CD4", ylabel="Events")
    plt.grid()

    sampleCD4 = Tcell_sample.gate(cd4_gate)
    Treg_gate = PolyGate([(4.2e3, 7.2e3), (6.5e03, 7.2e03), (6.5e03, 5.3e03),
                          (4.9e03, 5.3e03), (4.2e03, 5.7e03)],
                         ('VL1-H', 'BL1-H'),
                         region='in',
                         name='treg')
    Thelp_gate = PolyGate([(1.8e03, 3.1e03), (1.8e03, 4.9e03),
                           (6.0e03, 4.9e03), (6.0e03, 3.1e03)],
                          ('VL1-H', 'BL1-H'),
                          region='in',
                          name='thelper')

    _ = sampleCD4.plot(['VL1-H', 'BL1-H'],
                       gates=[Treg_gate, Thelp_gate],
                       gate_colors=['red', 'red'],
                       cmap=cm.jet,
                       ax=ax[1])  # CD4
    plt.title("CD4+ Cells")
    plt.xlabel("CD25")
    plt.ylabel("FOXP3")
    plt.grid()

    #CD8+ Cells
    CD3CD8gate = PolyGate([(7.5e3, 8.4e3), (4.7e3, 8.4e3), (4.7e03, 6.5e03),
                           (7.5e03, 6.5e03)], ('VL4-H', 'RL1-H'),
                          region='in',
                          name='treg')
    _ = NK_CD8_sample.plot(['VL4-H', 'RL1-H'],
                           gates=CD3CD8gate,
                           gate_colors='red',
                           cmap=cm.jet,
                           ax=ax[2])  # CD3, CD8
    plt.title("Singlet Lymphocytes")
    plt.xlabel("CD3")
    plt.ylabel("CD8")
    plt.grid()

    # NK Cells
    NKgate = PolyGate([(4.8e3, 5.1e3), (5.9e3, 5.1e3), (5.9e03, 6.1e03),
                       (4.8e03, 6.1e03)], ('VL4-H', 'BL1-H'),
                      region='in',
                      name='treg')
    CD56brightgate = PolyGate([(4.8e3, 6.3e3),
                               (5.9e3, 6.3e3), (5.9e03, 7.3e03),
                               (4.8e03, 7.3e03)], ('VL4-H', 'BL1-H'),
                              region='in',
                              name='treg')
    _ = NK_CD8_sample.plot(['VL4-H', 'BL1-H'],
                           gates=[NKgate, CD56brightgate],
                           gate_colors=['red', 'red'],
                           cmap=cm.jet,
                           ax=ax[3])  # CD3, CD56
    plt.title("Singlet Lymphocytes")
    plt.xlabel("CD3")
    plt.ylabel("CD56")
    plt.grid()

    # Gating for live cells
    sample1A, _, _ = importF("4-23", "1", "A", 1, "IL2R", None)
    sample2B, _, _ = importF("4-23", "1", "B", 2, "IL2R", None)
    sample3C, _, _ = importF("4-23", "1", "C", 3, "IL2R", None)
    panel1 = sample1A.transform(
        "tlog", channels=['VL6-H', 'VL4-H', 'BL1-H', 'VL1-H',
                          'BL3-H']).subsample(0.2)
    panel2 = sample2B.transform("tlog", channels=['VL4-H',
                                                  'BL3-H']).subsample(0.2)
    panel3 = sample3C.transform("tlog", channels=['VL6-H', 'VL4-H',
                                                  'BL3-H']).subsample(0.2)

    cd3cd4_gate = PolyGate([(5.0e03, 7.3e03), (5.3e03, 5.6e03),
                            (8.0e03, 5.6e03), (8.0e03, 7.3e03)],
                           ('VL4-H', 'VL6-H'),
                           region='in',
                           name='cd3cd4')
    _ = panel1.plot(['VL4-H', 'VL6-H'],
                    gates=cd3cd4_gate,
                    gate_colors=['red'],
                    cmap=cm.jet,
                    ax=ax[4])  # CD3, CD4
    plt.title("Singlet Lymphocytes")
    plt.xlabel("CD3")
    plt.ylabel("CD4")
    plt.grid()

    samplecd3cd4 = panel1.gate(cd3cd4_gate)
    thelp_gate = PolyGate([(0.2e03, 6.8e03), (0.2e03, 4.4e03),
                           (3.7e03, 4.4e03), (5.7e03, 5.9e03),
                           (5.7e03, 6.8e03)], ('VL1-H', 'BL1-H'),
                          region='in',
                          name='thelp')
    treg_gate = PolyGate([(3.8e03, 4.4e03), (3.8e03, 3.0e03), (6.5e03, 2.9e03),
                          (6.5e03, 5.0e03), (5.7e03, 5.8e03)],
                         ('VL1-H', 'BL1-H'),
                         region='in',
                         name='treg')
    _ = samplecd3cd4.plot(['VL1-H', 'BL1-H'],
                          gates=[thelp_gate, treg_gate],
                          gate_colors=['red', 'red'],
                          cmap=cm.jet,
                          ax=ax[5])  # CD3, CD4
    plt.title("CD3+CD4+ cells")
    plt.xlabel("CD25")
    plt.ylabel("CD127")
    plt.grid()

    nk_gate = PolyGate([(3.3e3, 5.4e3), (5.3e3, 5.4e3), (5.3e3, 7.3e3),
                        (3.3e3, 7.3e3)], ('VL4-H', 'BL3-H'),
                       region='in',
                       name='nk')
    nkt_gate = PolyGate([(5.6e3, 5.1e3), (7.6e3, 5.1e3), (7.6e3, 7.1e3),
                         (5.6e3, 7.1e3)], ('VL4-H', 'BL3-H'),
                        region='in',
                        name='nkt')
    _ = panel2.plot(['VL4-H', 'BL3-H'],
                    gates=[nk_gate, nkt_gate],
                    gate_colors=['red', 'red'],
                    cmap=cm.jet,
                    ax=ax[6])  # CD56 vs. CD3
    samplenk = panel2.gate(nk_gate)
    samplenkt = panel2.gate(nkt_gate)
    plt.title("Singlet Lymphocytes")
    plt.xlabel("CD3")
    plt.ylabel("CD56")
    plt.grid()

    cd8_gate = PolyGate([(4.2e3, 5.7e3), (8.1e3, 5.7e3), (8.1e3, 8.0e3),
                         (4.2e3, 8.0e3)], ('VL4-H', 'VL6-H'),
                        region='in',
                        name='cd8')
    _ = panel3.plot(['VL4-H', 'VL6-H'],
                    gates=cd8_gate,
                    gate_colors=['red'],
                    cmap=cm.jet,
                    ax=ax[7])  # CD8 vs. CD3
    plt.title("Singlet Lymphocytes")
    plt.xlabel("CD3")
    plt.ylabel("CD8")

    for i, axs in enumerate(ax):
        if i == 0:
            print(" ")
            # weird error replace later, axs is not correct object type
            # axs.set(xlabel='CD4',ylabel='Events')
        elif i == 1:
            axs.set_title('T Cell Gating')
            axs.set(xlabel='CD25', ylabel='FOXP3')
        elif i == 2:
            axs.set_title('CD8+ Cells Gating')
            axs.set(xlabel='CD3', ylabel='CD8')
        elif i == 3:
            axs.set_title('NK Cells Gating')
            axs.set(xlabel='CD3', ylabel='CD56')
        elif i == 4:
            axs.set_title('CD3+CD4+ Gating')
            axs.set(xlabel='CD3', ylabel='CD4')
        elif i == 5:
            axs.set_title('T reg and T Helper Gating')
            axs.set(xlabel='CD25', ylabel='CD127')
        elif i == 6:
            axs.set_title('NK and NKT Gating')
            axs.set(xlabel='CD3', ylabel='CD56')
        elif i == 7:
            axs.set_title('CD3+CD8+ Gating')
            axs.set(xlabel='CD3', ylabel='CD8')
        if i != 0:
            axs.grid()

    receptorPlot(ax[8])
    IL2RahiLoPlot(ax[9])

    return f
Exemplo n.º 6
0
# Input_file points to specific FCS file
input_file = raw_input("Enter FCS file location: ")

# Load the flow data
flow_data = FCMeasurement(ID='Flow data', datafile=input_file)

# Print channel information
print flow_data.channels

# Print the number of events in the data
print 'Events in file: ', flow_data.shape[0]

# Primary gates
non_debris_polygate = PolyGate([(45000, 50000), (150000, 55000),
                                (200000, 75000), (230000, 150000),
                                (180000, 225000), (60000, 200000),
                                (30000, 100000)], ['FSC-A', 'SSC-A'],
                               region='in',
                               name='live')
non_debris_gated_flow_data = flow_data.gate(non_debris_polygate)
singles_polygate = PolyGate([(45000, 25000), (190000, 99000), (170000, 135000),
                             (55000, 43000)], ['FSC-A', 'FSC-H'],
                            region='in',
                            name='singles')
singles_flow_data = non_debris_gated_flow_data.gate(singles_polygate)

# Transform data
tsingles_flow_data = singles_flow_data.transform(
    'hlog',
    channels=[
        'Alexa Fluor 405-A', 'Alexa Fluor 405-H', 'Alexa Fluor 405-W',
        'Alexa Fluor 488-A', 'Alexa Fluor 488-H', 'Alexa Fluor 488-W'
Exemplo n.º 7
0
# datafile = '[insert path to your own fcs file]'

# Load data
tsample = FCMeasurement(ID='Test Sample', datafile=datafile)
tsample = tsample.transform('hlog', channels=['Y2-A', 'B1-A', 'V2-A'], b=500.0)

# Create poly gate
from FlowCytometryTools import PolyGate

# HINT: If you have wx-python installed, then you can use the GUI to create the gate.
# You can launch the GUI by executing the command tsample.view_interactively()

gate1 = PolyGate([(-5.441e+02, 7.978e+03), (-8.605e+02, 6.739e+03),
                  (-5.811e+02, 4.633e+03), (1.502e+03, 5.118e+03),
                  (8.037e+02, 8.215e+03), (8.037e+02, 8.215e+03)],
                 ('B1-A', 'Y2-A'),
                 region='in',
                 name='poly gate')

# Gate

gated_sample = tsample.gate(gate1)
inverted_sample = tsample.gate(~gate1)  # Everything outside of gate1

# Plot
gated_sample.plot(('Y2-A', 'B1-A'),
                  gates=[gate1],
                  kind='scatter',
                  color='red',
                  alpha=0.9)
inverted_sample.plot(('Y2-A', 'B1-A'), kind='scatter', color='gray', alpha=0.9)
sgn1.channel_names


# In[5]:


## plot halo control 1
halo1.plot(['FSC-A', 'SSC-A'])
plt.show()


# In[6]:


## draw gate around healthiest cells
gate1= PolyGate([(50000,0),(80000,0), (80000,45000), (50000,45000)],
               ('FSC-A', 'SSC-A'), region='in')
halo1.plot(['FSC-A', 'SSC-A'], gates=gate1)
plt.show()


# In[7]:


##see population that falls inside the gate
halo1_gated=halo1.gate(gate1)
halo1_gated.plot(['FSC-A','SSC-A'], gates=gate1)
plt.show()


# In[8]:
Exemplo n.º 9
0
tsample.plot(['PE-Texas Red-A', 'Pacific Blue-A'],
             cmap=pl.cm.gist_rainbow,
             bins=150)

#%%
import wx

tsample.view_interactively()

#%%
from FlowCytometryTools import PolyGate

gate1 = PolyGate([(3.864e+03, 4.313e+03), (-2.091e+02, 3.875e+03),
                  (-2.813e+01, 7.716e+03), (5.040e+03, 9.256e+03),
                  (7.778e+03, 6.499e+03), (7.778e+03, 6.499e+03),
                  (7.778e+03, 6.499e+03)],
                 ('PE-Texas Red-A', 'Pacific Blue-A'),
                 region='in',
                 name='gate1')

gated_tsample = tsample.gate(gate1)

pl.figure(num=None, figsize=(5.1, 6.6), dpi=80, facecolor='w', edgecolor='k')

tsample.plot(['PE-Texas Red-A', 'Pacific Blue-A'],
             kind='scatter',
             color='gray',
             alpha=0.6,
             label='Original')

gated_tsample.plot(['PE-Texas Red-A', 'Pacific Blue-A'],
Exemplo n.º 10
0
print ''

preP1log = custom_log(preP1_sample, ['FSC-A', 'SSC-A'])
print 'profile after preP1 gating and log10 for FSC and SSC'
print preP1log.data.describe()
print ''

# //////////////////////////////////////////////
# P1 gating based on FSC and SSC (Log10 space)
P1_gatevalue = [(4.481395264353071, 4.727180089479611),
                (1.761395345415388, 3.4679208677492026),
                (1.6699667767116002, 2.8259455782395824),
                (3.7042524303708757, 2.8012542209507507),
                (4.869966681344168, 4.529649231168959)]
P1gate_channel = ('FSC-A', 'SSC-A')
P1gate = PolyGate(P1_gatevalue, P1gate_channel, region='in', name='P1 gate')
P1_sample = preP1log.gate(P1gate)
print 'profile after P1 gating'
print P1_sample.data.describe()
print ''

# ////////////////////////////////////
# threshold gate to remove all negative mCherry (PE-Texas Red) and GFP (FITC) events
prePxth_value1 = 10.0**2.0065723832855875
prePxth_channel1 = 'PE-Texas Red-A'
prePxth_value2 = 10.0**1.426888943216241
prePxth_channel2 = 'FITC-A'
prePxgate1 = ThresholdGate(prePxth_value1, prePxth_channel1, region='above')
prePxgate2 = ThresholdGate(prePxth_value2, prePxth_channel2, region='above')
prePxgate = prePxgate1 & prePxgate2