Commits

Marinka Zitnik committed 4734045

add cell info to F5

  • Participants
  • Parent commits 0171f10

Comments (0)

Files changed (2)

File yp/cell_filter.py

     majax  = "AreaShape_MajorAxisLength"
     minax = "AreaShape_MinorAxisLength"
     mean_inten = "Intensity_MeanIntensity_CropImage"
-    obj = "TrackObjects_Label_10"
+    obj = "TrackObjects_Label_20"
     for f in [obj, locx, locy, majax, minax, mean_inten]:
         assert f in namesc, "ERROR: Feature '%s' not found." % f
     

File yp/patch_tracking.py

 matplotlib.rc("xtick", labelsize = 8)
 matplotlib.rc("ytick", labelsize = 8)
 
-def _compute_profile(filepath_patch, res_dir):
+def _compute_profile(filepath_patch, filepath_cell, res_dir):
     """
     Compute and plot profiles of tracked patched during their lifetime (intensity
     and distance profile).
     :type res_dir: `str`
     """
     res_dir = os.path.abspath(res_dir)
+    
+    ###read patch data file
     fpatch = os.path.abspath(filepath_patch)
     print "Opening %s" % fpatch
     fp = open(fpatch, "r")
         it2dist[dline["ImageNumber"]][dline[obj]] = float(dline[dist_travel])
         it2loc[dline["ImageNumber"]][dline[obj]] = (float(dline[locx]), float(dline[locy]))
     fp.close()
+    ###
+    
+    ###Read cell data file
+    fcell = os.path.abspath(filepath_cell)
+    print "Opening %s" % fcell
+    fc = open(fcell, "r")
+    
+    namesc = fc.readline().strip().split(",")
+    print "No. columns %d: %s ..." % (len(namesc), namesc[:min(3, len(namesc))])
+    obj = "TrackObjects_Label_20"
+    assert obj in namesc, "ERROR: Feature '%s' not found." % obj
+    
+    io2t = {str(i): {} for i in xrange(1, 51)} #image x objectNumber -> trackedObjects_Label
+    for line in fc:
+        dline = dict(zip(namesc, line.strip().split(",")))
+        io2t[dline["ImageNumber"]][dline["ObjectNumber"]] = dline[obj]
+    fc.close()
+    ###
 
     to_plot, gl_lifetime, gis = [], [], []
     global_inten_start = defaultdict(list) #global intensity profile alignment centered at start
     
     fname = res_dir + "/patches.txt"
     fres = open(fname, "w")
+    fres.write("Cell file: %s\n" % filepath_cell)
     fres.write("Patch file: %s\n" % filepath_patch)
     fres.write("=====================================\n")
-    fres.write("N (all tracked from 1st including 50th frame): %d\n" % len(done))
+    fres.write("N(patches all tracked from 1st including 50th frame): %d\n" % len(done))
+    fres.write("Avg(N(cells per frame)): %5.3f" % np.mean([len(io2t[img]) for img in io2t]))    
+    fres.write("N(cells in 1st frame): %d" % len(io2t["1"]))
+    fres.write("N(cells in 50th frame): %d" % len(io2t["50"]))
     for k in xrange(0, 46, 5):
         ptch = [p for p, e in gl_lifetime if e >= k and e < k+5]
         fres.write("[%d,%d)\tN: %4d\n" % (k, k+5, len(ptch)))
     host.set_xlabel("Time")
     host.set_ylabel("Intensity")
     par1.set_ylabel("Distance")
-    plt.savefig(res_dir + "/intensity_dist_patch%s.pdf" % (tracked_patch))
+    t = len(time_inten)/5
+    path = res_dir + "/%d-%d" % (t*5, t*5+5)
+    if not os.path.exists(path):
+        os.makedirs(path)
+    plt.savefig(path + "/intensity_dist_patch%s.pdf" % tracked_patch)
     plt.close()
             
 def _plot_gl_int_profile_start(global_inten_start, gis, res_dir):
 
 def main(argv):
     if len(sys.argv) < 3:
-        sys.exit("Usage: %s <DefaultOUT_TrackedPatch.csv path> <res dir>" % sys.argv[0])
+        sys.exit("Usage: %s <DefaultOUT_TrackedPatch.csv path> <DefaultOUT_TrackedCell.csv path> <res dir>" % sys.argv[0])
     if not os.path.exists(sys.argv[1]):
         sys.exit("ERROR: Patch data file %s was not found!" % sys.argv[1])
     if not os.path.exists(sys.argv[2]):
-        print "Res directory %s does not exist and will be created!" % sys.argv[2]
+        sys.exit("ERROR: Cell data file %s was not found!" % sys.argv[2])
+    if not os.path.exists(sys.argv[3]):
+        print "Res directory %s does not exist and will be created!" % sys.argv[3]
         os.makedirs(sys.argv[2])
-    _compute_profile(filepath_patch = sys.argv[1], res_dir = sys.argv[2])
+    _compute_profile(filepath_patch = sys.argv[1], filepath_cell = sys.argv[2], res_dir = sys.argv[3])
 
 if __name__ == "__main__":
     main(sys.argv)