def resample(original_dir,preprocessed_dir):

    if not os.path.exists(preprocessed_dir):
        os.mkdir(preprocessed_dir)

    for input_swc_path in glob.glob(original_dir + "/*.swc"):
        print input_swc_path
        swc_fn = input_swc_path.split('/')[-1]

        preprocessed_swc_fn = preprocessed_dir+'/' + swc_fn
        bn.resample(input_swc_path, preprocessed_swc_fn)  ## due to the pw alignment, no  alignment are necessary
        ##bn.pre_processing(input_swc_path, preprocessed_swc_fn)

    return
Ejemplo n.º 2
0
def resample_and_sort(data_dir,
                      resampled_dir,
                      sorted_dir,
                      GEN_QSUB=0,
                      overwrite_sorted=1,
                      filelist=None):
    failure_file = open(data_dir + "/failurecases_via_size.txt", "w")
    i = 0
    subfolder = 1
    if filelist == None:
        filelist = glob.glob(data_dir + "/*/*.swc")
        if len(filelist) < 1:
            filelist = glob.glob(data_dir + "/*.swc")
            subfolder = 0

    for input_swc_path in filelist:
        i = i + 1
        print "\n\n "
        print i

        #if( os.path.getsize(input_swc_path) < 1024*1024)):
        if not "tmp_cache_img" in input_swc_path:  # skip the tmp files
            if subfolder > 0:
                swc_fn = "/".join(input_swc_path.split("/")
                                  [-2:])  # to keep the subfolder structure
            else:
                swc_fn = "/".join(input_swc_path.split("/")[-1:])

            sorted_swc_path = sorted_dir + '/' + swc_fn
            resampled_swc_path = resampled_dir + '/' + swc_fn
            if not os.path.isfile(
                    resampled_swc_path
            ) or overwrite_sorted:  # if already generated
                # resample
                resampled_swc_path = resampled_dir + '/' + swc_fn
                print "resample : " + input_swc_path
                bn.resample(input_swc_path, resampled_swc_path, 3, GEN_QSUB,
                            data_dir +
                            '/qsub/resample')  # generate QSUB scripts

                # sort
                sorted_swc_path = sorted_dir + '/' + swc_fn
                #bn.sort_swc(preprocessed_swc_path, sorted_swc_path,GEN_QSUB,data_dir+'/qsub/sort')
        #else:
        #  failure_file.write(input_swc_path+" "+str(os.path.getsize(input_swc_path))+"\n ")

    #failure_file.close()
    #print "failure cases with file sizes that are too big or too small are logged at:"+ data_dir+"/failurecases_via_size.txt"
    print "done resampling "  #and sorting"
    return
Ejemplo n.º 3
0
def resample(original_dir, preprocessed_dir):

    if not os.path.exists(preprocessed_dir):
        os.mkdir(preprocessed_dir)

    for input_swc_path in glob.glob(original_dir + "/*.swc"):
        print input_swc_path
        swc_fn = input_swc_path.split('/')[-1]

        preprocessed_swc_fn = preprocessed_dir + '/' + swc_fn
        bn.resample(input_swc_path, preprocessed_swc_fn
                    )  ## due to the pw alignment, no  alignment are necessary
        ##bn.pre_processing(input_swc_path, preprocessed_swc_fn)

    return
def resample_and_sort(data_dir,resampled_dir,sorted_dir, GEN_QSUB = 0,overwrite_sorted = 1,filelist=None):
    failure_file = open(data_dir +"/failurecases_via_size.txt","w")
    i = 0
    subfolder = 1
    if filelist == None:
        filelist= glob.glob(data_dir+"/*/*.swc")
        if len(filelist)<1 :
            filelist= glob.glob(data_dir+"/*.swc")
            subfolder = 0
         
    for input_swc_path in filelist:
         i = i+1
         print "\n\n "
         print i

         #if( os.path.getsize(input_swc_path) < 1024*1024)):
         if not "tmp_cache_img"  in input_swc_path:   # skip the tmp files
              if subfolder >0:
                   swc_fn = "/".join (input_swc_path.split("/")[-2:]) # to keep the subfolder structure
              else:
                   swc_fn = "/".join (input_swc_path.split("/")[-1:])


              sorted_swc_path = sorted_dir+ '/'+swc_fn
              resampled_swc_path = resampled_dir+ '/'+swc_fn
              if not os.path.isfile(resampled_swc_path) or overwrite_sorted:  # if already generated
                 # resample
                 resampled_swc_path = resampled_dir+ '/'+swc_fn
                 print "resample : "+ input_swc_path
                 bn.resample(input_swc_path, resampled_swc_path,3,GEN_QSUB,data_dir+'/qsub/resample')  # generate QSUB scripts

                 # sort
                 sorted_swc_path = sorted_dir+ '/'+swc_fn
                 #bn.sort_swc(preprocessed_swc_path, sorted_swc_path,GEN_QSUB,data_dir+'/qsub/sort')
         #else:
          #  failure_file.write(input_swc_path+" "+str(os.path.getsize(input_swc_path))+"\n ")

    #failure_file.close()
    #print "failure cases with file sizes that are too big or too small are logged at:"+ data_dir+"/failurecases_via_size.txt"
    print "done resampling "#and sorting"
    return