text:
import os, sys, re
import shutil
import optparse
import shutil
import pandas
import numpy
import subprocess
import fnmatch
from joblib import Parallel, delayed
import multiprocessing
from Bio import SeqIO
import glob

#####################################
#This is the script to produce SSL file outputs for skyline spectral library construction
#
#Fraction parsing is taken from from after the final "-" in the file name.  For example, "2015-10-05-wb-HEK293-BioRep1-F1.mzML"
#would belong to fraction "F1"
#
#VERSION 1.8.0
version="1.8.0"
#DATE: 9/18/2017
date="9/18/2017"
#####################################
print "-----------------------------------------------------------------------"
print "Welcome to the SSL file converter for Galaxy, Wohlschlegel Lab UCLA"
print "Written by William Barshop"
print "Version: ",version
print "Date: ",date

def applyParallel(dfGrouped, func):
    retLst = Parallel(n_jobs=multiprocessing.cpu_count())(delayed(func)(group) for name, group in dfGrouped)
    return pandas.concat(retLst)

def applyParallelQuarter(dfGrouped, func):
    retLst = Parallel(n_jobs=multiprocessing.cpu_count()/4)(delayed(func)(group) for name, group in dfGrouped)
    return pandas.concat(retLst)

def applyParallelHalf(dfGrouped, func):
    retLst = Parallel(n_jobs=multiprocessing.cpu_count()/2)(delayed(func)(group) for name, group in dfGrouped)
    return pandas.concat(retLst)

def fido_filter(unfiltered):#dataframe,float arguments...

    #filtered=[]
    #print unfiltered,"This is it GOING IN...."
    #unfiltered.apply(fido_filter_row,axis=1)
    for index,eachrow in unfiltered.iterrows():
        prot_q_vals = eachrow['protein q-values'].split(',')
        protein_ids = eachrow['protein id'].split(',')
        indicies = eachrow['peptide prot-indicies'].split(',')
        new_q_vals=[]
        new_prot_ids=[]
        new_indicies=[]

        for each_tuple in zip(protein_ids,prot_q_vals,indicies):
            if float(each_tuple[1])<=gfido_q_threshold: #KEEP IT
                new_q_vals.append(each_tuple[1])
                new_prot_ids.append(each_tuple[0])
                new_indicies.append(each_tuple[2])
            else:
                pass # THROW IT OUT

        if len(new_prot_ids) >= 1:
            unfiltered.loc[index,'protein q-values']=",".join(new_q_vals)
            unfiltered.loc[index,'protein id']=",".join(new_prot_ids)
            unfiltered.loc[index,'indicies']=",".join(new_indicies)
            unfiltered.loc[index,'fido_filter']=1 #This means we'll keep it when we do our df filter... We'll end up dropping this column later.
        else:
            unfiltered.loc[index,'fido_filter']=0

        #print changed,type(changed),"this is changed..."
    return unfiltered

def fido_filter_row(eachrow):
    #print eachrow,"this is my row!",type(eachrow)
    #print str(gfido_q_threshold),"this is the threshold..."
    prot_q_vals = eachrow['protein q-values'].split(',')
    protein_ids = eachrow['protein id'].split(',')
    indicies = eachrow['peptide prot-indicies'].split(',')
    new_q_vals=[]
    new_prot_ids=[]
    new_indicies=[]

    for each_tuple in zip(protein_ids,prot_q_vals,indicies):
        if float(each_tuple[1])<=gfido_q_threshold: #KEEP IT
            new_q_vals.append(each_tuple[1])
            new_prot_ids.append(each_tuple[0])
            new_indicies.append(each_tuple[2])
        else:
            pass # THROW IT OUT

    if len(new_prot_ids) >= 1:
        eachrow['protein q-values']=",".join(new_q_vals)
        eachrow['protein id']=",".join(new_prot_ids)
        eachrow['indicies']=",".join(new_indicies)
        eachrow['fido_filter']=1 #This means we'll keep it when we do our df filter... We'll end up dropping this column later.
    else:
        eachrow['fido_filter']=0

####################################
#Argument parsing! So much fun!
#We'll use OptParse even though some
#people really rave about argparse...
#
#
# NB: With Optparse, if an option is
#     not specified, it will take a
#     value of None
####################################

fractions=False

#print sys.argv,"THESE ARE THE ARGS"

parser = optparse.OptionParser()
parser.add_option("--pout",action="store",type="string",dest="operation_folder")
parser.add_option("--qthresh",action="store", type="float", dest="q_threshold")
parser.add_option("--fidoq",action="store", type="float", dest="fido_q_threshold")
parser.add_option("--fido_q_raw",action="store", type="string", dest="fido_q_raw")
parser.add_option("--pRS_prob_thresh",action="store", type="float", dest="prs_prob_threshold")
parser.add_option("--ptmRS_prob_thresh",action="store", type="float", dest="ptmrs_prob_threshold")
parser.add_option("--FLRthresh",action="store", type="float", dest="flr_threshold")
parser.add_option("--LFLR",action="store_true", dest="local_flr")
parser.add_option("--mzml",action="store",type="string",dest="mzml_files")
parser.add_option("--mass_corrected_mzml",action="store",type="string",dest="mc_mzml_files")
parser.add_option("--blib",action="store_true",dest="blib")
parser.add_option("--fasta",action="store",type="string",dest="fasta")
parser.add_option("--ffasta",action="store",type="string",dest="ffasta") # THIS IS THE FILTERED FIDO OUTPUT
parser.add_option("--expgroups",action="store",type="string",dest="exp_group_file")
parser.add_option("--ssl",action="store",type="string",dest="ssl_output_folder")
parser.add_option("--fractions",action="store_true",dest="fractions")
parser.add_option("--OnePPS",action="store_true",dest="one_pps")
parser.add_option("--only_mod",action="store_true",dest="only_mod")
parser.add_option("--highest_intensity",action="store_true",dest="highest_intensity")
parser.add_option("--diaumpire",action="store_true",dest="diaumpire")
parser.add_option("--no_mzml",action="store_true",dest="no_mzml")
#parser.add_option("--saint",action="store",type="string",dest="saint_outputs")

(options,args) = parser.parse_args()

if options.fractions is True:
    fractions=True
else:
    print "We'll give outputs by acquisition (runs), not by experimental set."

#saint=False
#if options.saint_outputs is not None:
#    saint=True
#    saint_interact,saint_bait,saint_prey=options.saint_outputs.split(",")

#### Check for FIDO q-filter
fido_q=False
if options.fido_q_threshold is not None:
    fido_q=True
    global gfido_q_threshold #For paralell access via JobLib/Multiprocessing...
    gfido_q_threshold = options.fido_q_threshold
    print "We're going to filter by Fido Q-Value of ",options.fido_q_threshold

#### Check for LuciPHOr
luciphor=False
if options.flr_threshold is not None:
    luciphor=True
    print "We will filter by LuciPHOr FLR of ",options.flr_threshold

#### Check for PhosphoRS
phosphoRS=False
if options.prs_prob_threshold is not None:
    phosphoRS=True
    print "We will filter by a PhosphoRS probability of ",options.prs_prob_threshold

#### Check for ptmRS
ptmRS=False
if options.ptmrs_prob_threshold is not None:
    ptmRS=True
    options.ptmrs_prob_threshold=options.ptmrs_prob_threshold*100.0
    print "We will filter by a ptmRS probability of ",options.ptmrs_prob_threshold

psms_files=[]
for root, subFolders, files in os.walk(options.operation_folder):
    for eachfile in files:
        if 'target.psms.txt' in eachfile and 'uncorrected' not in eachfile:
            psms_files.append(str(os.path.join(root,eachfile)))

dataframe_vector=[]
for eachfile in psms_files:
    newdf=pandas.read_csv(eachfile,sep='\t',index_col=False)
    dataframe_vector.append(newdf)
combined_results=pandas.concat(dataframe_vector)
#print combined_results.columns
#print combined_results['file']
#sys.exit(2)
del dataframe_vector

group_information = pandas.read_csv(options.exp_group_file,sep='\t',dtype={'Fractionation Group ID String': object,'Fractionation Group Name':object,'Biological Condition':object})

run_dict={} # Key is file_idx, value is file_name.mzML
rev_run_dict={} #Key is file_nzme.mzML, value is file_idx
group_to_run_dict={} # Key is group, value is [1, 2, 3, 4] list of file_idx belonging to runs in the group...
run_to_group_dict={} # Key is file_idx, value is group...
group_to_file_name={} # key is group, value is ["xxxx.mzML", "xxxx.mzML"]
if fractions:
    fractions_to_run_dict={}

for index,row in group_information.iterrows():
    print row
    run_dict[str(row['Crux File Integer'])]=row['Original File Name']+".mzML"
    rev_run_dict[row['Original File Name']+".mzML"]=str(row['Crux File Integer'])
    if row['Fractionation Group ID String'] in group_to_run_dict:
        group_to_run_dict[row['Fractionation Group ID String']].append(str(row['Crux File Integer']))
    else:
        group_to_run_dict[row['Fractionation Group ID String']] = [str(row['Crux File Integer'])]
    if str(row['Crux File Integer']) in run_to_group_dict:
        #run_to_group_dict[str(row['Crux File Integer'])].append(row['Fractionation Group ID String'])
        print "YOU HAVE MULTIPLE COPIES OF A RUN IN THE EXPERIMENTAL INFORMATION FILE... WARNING!"
    else:
        run_to_group_dict[str(row['Crux File Integer'])]=row['Fractionation Group ID String']

    if row['Fractionation Group ID String'] in group_to_file_name:
        group_to_file_name[row['Fractionation Group ID String']].append(str(row['Original File Name'])+".mzML")
    else:
        group_to_file_name[row['Fractionation Group ID String']] = [str(row['Original File Name'])+".mzML"]
    if fractions:
        fraction_tag=str(row['Original File Name'].rsplit("-",1)[1])
        if fraction_tag in fractions_to_run_dict:
            fractions_to_run_dict[fraction_tag].append(str(row['Crux File Integer']))#str(row['Original File Name'])+".mzML")
        else:
            fractions_to_run_dict[fraction_tag]=[str(row['Crux File Integer'])]

combined_results['file_idx']=combined_results['file_idx'].astype(str)
#print combined_results['file']
combined_results['file']=combined_results['file'].astype(str)
#sys.exit(2)
####################### We'll handle putting in the file names just to be sure this has been handled!
fix_combined=[]
#print run_dict,"This is run dict"
#print rev_run_dict,"this is rev dict"
for each_idx in run_dict:
    mask = combined_results[(combined_results.file.str.contains(run_dict[each_idx]))] # MODIFIED....
    mask['file']=run_dict[each_idx]
    fix_combined.append(mask)
#print fix_combined
combined_results=pandas.concat(fix_combined)
#sys.exit(2)
if options.diaumpire:
    print "DIAUmpire inputs: Decrementing scans to match mzML file index."
    combined_results['scan']=combined_results['scan']-1

if luciphor and 'luci_numPPS' not in combined_results.columns.values.tolist():
    print "LuciPHOr erroneously called for filtering... turning it off!"
    luciphor=False
if phosphoRS and 'pRS_peptideLocalizationProbability' not in combined_results.columns.values.tolist():
    print "phosphoRS erroneously called for filtering... turning it off!"
    phosphoRS=False
if ptmRS and 'ptmRS_peptideLocalizationProbability' not in combined_results.columns.values.tolist():
    print "ptmRS erroneously called for filtering... turning it off!"
    ptmRS=False

if luciphor:
    #print combined_results
    combined_results['luci_numPPS']=combined_results['luci_numPPS'].fillna(0)
    combined_results['luci_numPPS']=combined_results['luci_numPPS'].astype(int).fillna(0)
    combined_results['luci_globalFLR']=combined_results['luci_globalFLR'].astype(float).fillna(0.0)
    combined_results['luci_localFLR']=combined_results['luci_localFLR'].astype(float).fillna(0.0)
if phosphoRS:
    combined_results['pRS_peptideLocalizationProbability']=combined_results['pRS_peptideLocalizationProbability'].astype(float).fillna(1.00)
    combined_results['pRS_numPPS']=combined_results['pRS_numPPS'].astype(int).fillna(0)
if ptmRS:
    combined_results['ptmRS_peptideLocalizationProbability']=combined_results['ptmRS_peptideLocalizationProbability'].astype(float).fillna(100.00)
    combined_results['ptmRS_totalNumPPS']=combined_results['ptmRS_totalNumPPS'].fillna(0).astype(int)
#for i,each in combined_results.iterrows():

new_results={} # KEY IS GROUP NAME
results_per_run={} # KEY IS FILE_IDX
#print "tehse are items in group to run dict",group_to_run_dict

#for each_group in group_to_run_dict:
#    bool_filter=combined_results.copy(deep=True)
#    bool_filter['file_idx']=bool_filter['file_idx'].astype(str)
#    #mask8=combined_results[(bool_filter.file_idx == "8" )]
#    mask = combined_results[(combined_results.file_idx.str.contains('|'.join(group_to_run_dict[each_group])))]         #############Was this inappropriate set to file instead of file_idx? #bad idea to use "in"/contains here...
#    new_results[each_group]=mask # results by group
#    for each_file in set(mask['file_idx']):
#        each_file_mask=mask[(mask.file_idx == each_file)]
#        results_per_run[str(each_file)]=each_file_mask # results by run
#print group_to_file_name,"these are the groups of new interest"
for each_group in group_to_file_name:
    #print "-------------------------------------------------------------"
    #print "working on",each_group
    #bool_filter=combined_results.copy(deep=True)
    #bool_filter['file_idx']=bool_filter['file_idx'].astype(str)
    #mask8=combined_results[(bool_filter.file_idx == "8" )]
    #print "masking for",group_to_file_name[each_group]
    mask = combined_results[(combined_results.file.str.contains('|'.join(group_to_file_name[each_group])))]
    new_results[each_group]=mask # results by group
    #print mask
    print "CONSTRUCTING DICTIONARIES!"
    for each_file in set(mask['file']):
        each_file_mask=mask[(mask.file.str.contains(each_file))]
        results_per_run[str(rev_run_dict[each_file])]=each_file_mask # results by run
        #print each_file,str(rev_run_dict[each_file])
        #print len(each_file_mask)
        #print "---------------------"
#print combined_results
#sys.exit(2)
####################################################

if options.one_pps is True:
    print "Allowing Unambiguous Localization Peptides Through..."

basedir=os.getcwd()
if not fractions: #This is for all times when we have 1-D runs to compare.
    for eachgroup in set(group_information['Fractionation Group ID String']):
        os.chdir(basedir)
        os.chdir(options.operation_folder+eachgroup+".pin_out/crux-output/")
        #os.mkdir(basedir+"/"+options.ssl_output_folder+"/"+eachgroup)

        #if not options.no_mzml:
        for eachfile in group_to_file_name[eachgroup]:
            #shutil.copy(os.path.join(basedir,eachfile),basedir+"/"+options.ssl_output_folder+"/"+eachgroup+"/"+eachfile)
            shutil.copy(os.path.join(basedir,eachfile),basedir+"/"+options.ssl_output_folder+"/"+eachfile)
        if not fractions:
            for eachrun in group_to_run_dict[eachgroup]:
                #print "-----------------------------------------------"
                #print results_per_run.keys()
                this_run_results=results_per_run[eachrun]
                this_run_results['protein q-values']=this_run_results['protein q-values'].astype(str)

                if fido_q:
                    this_run_results['fido_filter']=1
                    this_run_grouped=this_run_results.groupby(numpy.arange(len(this_run_results))//multiprocessing.cpu_count())
                    this_run_results=applyParallelHalf(this_run_grouped,fido_filter)
                    #print type(this_run_results),"and type"
                    this_run_results=this_run_results[this_run_results['fido_filter']==1]
                    this_run_results=this_run_results.drop('fido_filter',axis=1)
                    del this_run_grouped

                if luciphor:
                    if options.local_flr is True:
                        if options.one_pps is True:
                            mask=this_run_results[numpy.logical_or(( this_run_results.luci_localFLR <= options.flr_threshold ) , (this_run_results.luci_numPPS - this_run_results.luci_numRPS == 0))]
                            type2_mask=this_run_results[numpy.logical_and(( this_run_results.luci_localFLR > options.flr_threshold ), (this_run_results.luci_numPPS - this_run_results.luci_numRPS > 0))] #Unambiguous and poorly localized.

                        else:
                            mask=this_run_results[( this_run_results.luci_localFLR <= options.flr_threshold)]
                            type2_mask=this_run_results[( this_run_results.luci_localFLR > options.flr_threshold )] #Unambiguous and poorly localized.

                    else:
                        if options.one_pps is True:
                            mask=this_run_results[numpy.logical_or(( this_run_results.luci_globalFLR <= options.flr_threshold ) , (this_run_results.luci_numPPS - this_run_results.luci_numRPS == 0))]
                            type2_mask=this_run_results[numpy.logical_and(( this_run_results.luci_globalFLR > options.flr_threshold ), (this_run_results.luci_numPPS - this_run_results.luci_numRPS > 0))] #Unambiguous and poorly localized.

                        else:
                            mask=this_run_results[( this_run_results.luci_globalFLR <= options.flr_threshold)]
                            type2_mask=this_run_results[( this_run_results.luci_globalFLR > options.flr_threshold )] #Unambiguous and poorly localized.
                elif phosphoRS:
                    if options.one_pps is True:
                        mask=this_run_results[numpy.logical_or(( this_run_results.pRS_peptideLocalizationProbability >= options.prs_prob_threshold ) , (this_run_results.pRS_numPPS - this_run_results.numModSites == 0))]
                        type2_mask=this_run_results[numpy.logical_and(( this_run_results.pRS_peptideLocalizationProbability >= options.prs_prob_threshold ), (this_run_results.pRS_numPPS - this_run_results.numModSites > 0))] #Unambiguous and poorly localized.
                    else:
                        mask=this_run_results[( this_run_results.pRS_peptideLocalizationProbability >= options.prs_prob_threshold)]
                        type2_mask=this_run_results[( this_run_results.pRS_peptideLocalizationProbability < options.prs_prob_threshold )] #Unambiguous and poorly localized.
                elif ptmRS:
                    #if options.one_pps is True:
                    #    mask=this_run_results[numpy.logical_or(( this_run_results.ptmRS_peptideLocalizationProbability >= options.ptmrs_prob_threshold ) , (this_run_results.ptmRS_numPPS - this_run_results.numModSites == 0))]
                    #    type2_mask=this_run_results[numpy.logical_and(( this_run_results.ptmRS_peptideLocalizationProbability >= options.ptmrs_prob_threshold ), (this_run_results.ptmRS_numPPS - this_run_results.numModSites > 0))] #Unambiguous and poorly localized.
                    #else:
                    #print len(this_run_results),"before filtering..."
                    #print "filtering at ",options.ptmrs_prob_threshold
                    mask=this_run_results[( this_run_results.ptmRS_peptideLocalizationProbability >= options.ptmrs_prob_threshold)]
                    #print mask['ptmRS_peptideLocalizationProbability'].min(),"minimum value..."
                    #for key,eachrow in mask.iterrows():
                    #    if eachrow['ptmRS_peptideLocalizationProbability']<=options.ptmrs_prob_threshold:
                    #        print eachrow
                    #print len(mask),"after filtering..."
                    type2_mask=this_run_results[( this_run_results.ptmRS_peptideLocalizationProbability < options.ptmrs_prob_threshold )] #Unambiguous and poorly localized.
                    #print type2_mask
                else:
                    mask=this_run_results
                if options.only_mod is True:
                    if luciphor:
                        mask=mask[mask['luci_numRPS'] >= 1].copy(deep=True)
                    elif phosphoRS:
                        mask=mask[mask['numModSites'] >= 1].copy(deep=True)
                    elif ptmRS:
                        mask=mask[mask['ptmRS_numMods'] >= 1].copy(deep=True)

                if luciphor:
                    ssl_df=mask[['file','scan','charge','luci_sequence','percolator q-value']]
                    ssl_df.rename(columns={'luci_sequence':'sequence'}, inplace=True)
                elif phosphoRS:
                    ssl_df=mask[['file','scan','charge','sequence','percolator q-value']]
                    #ssl_df.rename(columns={'pRS_sequence':'sequence'}, inplace=True)
                elif ptmRS:
                    ssl_df=mask[['file','scan','charge','sequence','percolator q-value']]
                    #ssl_df.rename(columns={'ptmRS_sequence':'sequence'}, inplace=True)
                else:
                    ssl_df=mask[['file','scan','charge','sequence','percolator q-value']]
                ssl_df.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
                ssl_df_filtered=ssl_df[(ssl_df['percolator qvalue']<=options.q_threshold)]
                #with open(basedir+"/"+options.ssl_output_folder+"/"+eachgroup+"/"+run_dict[eachrun].replace(".mzML","")+".ssl",'wb') as ssl_writer:
                with open(basedir+"/"+options.ssl_output_folder+"/"+run_dict[eachrun].replace(".mzML","")+".ssl",'wb') as ssl_writer:
                    ssl_df_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                    ssl_df_filtered['score-type']="PERCOLATOR QVALUE"
                    ssl_df_filtered.to_csv(path_or_buf=ssl_writer,sep="\t",index=False,header=True)
                if luciphor:
                    with open(basedir+"/"+options.ssl_output_folder+"/"+run_dict[eachrun].replace(".mzML","")+"_type2.ssl",'wb') as type2_ssl_writer:
                        ssl_df_type2=type2_mask[['file','scan','charge','luci_sequence','percolator q-value']]
                        ssl_df_type2.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
                        ssl_df_type2.rename(columns={'luci_sequence':'sequence'}, inplace=True)
                        ssl_df_type2_filtered=ssl_df_type2[(ssl_df_type2['percolator qvalue']<=options.q_threshold)]
                        ssl_df_type2_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                        ssl_df_type2_filtered['score-type']="PERCOLATOR QVALUE"
                        ssl_df_type2_filtered.to_csv(path_or_buf=type2_ssl_writer,sep="\t",index=False,header=True)
                elif phosphoRS:
                    with open(basedir+"/"+options.ssl_output_folder+"/"+run_dict[eachrun].replace(".mzML","")+"_type2.ssl",'wb') as type2_ssl_writer:
                        #ssl_df_type2=type2_mask[['file','scan','charge','pRS_sequence','percolator q-value']]
                        ssl_df_type2=type2_mask[['file','scan','charge','sequence','percolator q-value']]
                        ssl_df_type2.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
                        #ssl_df_type2.rename(columns={'pRS_sequence':'sequence'}, inplace=True)
                        ssl_df_type2_filtered=ssl_df_type2[(ssl_df_type2['percolator qvalue']<=options.q_threshold)]
                        ssl_df_type2_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                        ssl_df_type2_filtered['score-type']="PERCOLATOR QVALUE"
                        ssl_df_type2_filtered.to_csv(path_or_buf=type2_ssl_writer,sep="\t",index=False,header=True)
                elif ptmRS:
                    with open(basedir+"/"+options.ssl_output_folder+"/"+run_dict[eachrun].replace(".mzML","")+"_type2.ssl",'wb') as type2_ssl_writer:
                        #ssl_df_type2=type2_mask[['file','scan','charge','ptmRS_sequence','percolator q-value']]
                        ssl_df_type2=type2_mask[['file','scan','charge','sequence','percolator q-value']]
                        ssl_df_type2.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
                        #ssl_df_type2.rename(columns={'ptmRS_sequence':'sequence'}, inplace=True)
                        ssl_df_type2_filtered=ssl_df_type2[(ssl_df_type2['percolator qvalue']<=options.q_threshold)]
                        ssl_df_type2_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                        ssl_df_type2_filtered['score-type']="PERCOLATOR QVALUE"
                        ssl_df_type2_filtered.to_csv(path_or_buf=type2_ssl_writer,sep="\t",index=False,header=True)

    if options.highest_intensity:
        #We'll need the pin files for this...
        os.chdir(basedir)
        pin_files=[]
        for root,dirs,files in os.walk(basedir):
            for file in files:
                if file.endswith(".pin"):
                    pin_files.append(os.path.join(root,file))
        pins_df=[]
        for each_pin in pin_files:
            cols = pandas.read_csv(each_pin, nrows=1,sep="\t",index_col=False).columns.tolist()[:-1]
            pins_df.append(pandas.read_csv(each_pin,usecols=cols,index_col=False,sep="\t",skiprows=[1],engine='python'))
        merged_pins=pandas.concat(pins_df)
        merged_pins['file_idx']=merged_pins['SpecId'].str.split("_").str.get(1)
        merged_pins['file']=merged_pins['file_idx'].map(run_dict)
        os.chdir(basedir+"/"+options.ssl_output_folder)
        for file in glob.glob("*.ssl"):
            this_ssl=pandas.read_csv(file,index_col=False,sep='\t')
            this_ssl_with_MS2=pandas.merge(this_ssl,merged_pins[['file','ScanNr','lnMS2IonCurrent']],left_on=['file','scan'],right_on=['file','ScanNr'])
            this_ssl_with_MS2=this_ssl_with_MS2.drop_duplicates()
            this_ssl_with_MS2_filtered=this_ssl_with_MS2.loc[this_ssl_with_MS2.groupby(['file','sequence','charge'])["lnMS2IonCurrent"].idxmax()]
            this_ssl_with_MS2_filtered.drop(labels=['lnMS2IonCurrent','ScanNr'],axis=1,inplace=True)
            os.rename(file,file.rsplit(".",1)[0]+".redundant_library")
            this_ssl_with_MS2_filtered.to_csv(path_or_buf=file,sep="\t",index=False,header=True)
        print "We're stripped down the ssl files to only the highest explained MS2 Ion Current per peptide ID per run."

    if options.blib:
        print "Let's build some blib files..."
        os.chdir(basedir)
        os.chdir(basedir+"/"+options.ssl_output_folder)
        #cmd = '/galaxy-central/tools/wohl-proteomics/ssl_converter/blibbuild/bin/BlibBuild -a milkyway-galaxy *.ssl combined_spectral_lib.blib'
        #cmd = 'ls *.ssl | /galaxy-central/tools/wohl-proteomics/ssl_converter/blibbuild/bin/BlibBuild -a milkyway-galaxy -m 1000M combined_spectral_lib.blib'
        #cmd = 'wine /galaxy-central/tools/wohl-proteomics/ssl_converter/skylineblib/BlibBuild.exe -a milkyway-galaxy -m 1000M *.ssl redundant_spectral_lib.blib'
        #print "running command ",cmd
        #subprocess.call(cmd,shell=True)
        #filtercmd='wine /galaxy-central/tools/wohl-proteomics/ssl_converter/skylineblib/BlibFilter.exe redundant_spectral_lib.blib filtered_spectral_lib.blib'
        #subprocess.call(filtercmd,shell=True)
        for file in glob.glob("*type2.ssl"):
            os.rename(file,file.split(".")[0]+".not_ssl")
            print "protected",file,"from inclusion in spectral lib..."
        cmd = 'wine /galaxy-central/tools/wohl-proteomics/ssl_converter/skylineblib/BlibBuild.exe -a milkyway-galaxy -m 1000M *.ssl combined_spectral_lib.blib'
        print "running command ",cmd
        subprocess.call(cmd,shell=True)
        for file in glob.glob("*.not_ssl"):
            os.rename(file,file.split(".")[0]+".ssl")
        filtercmd='wine /galaxy-central/tools/wohl-proteomics/ssl_converter/skylineblib/BlibFilter.exe combined_spectral_lib.blib filtered.blib'
        subprocess.call(filtercmd,shell=True)

        if options.mc_mzml_files is not None: #and not options.no_mzml:
            for file in glob.glob("*.mzML"):
                os.remove(file)
                print "removing ",file
            os.chdir(basedir)
            for file in glob.glob("mc_*.mzML"):
                print "replacing ",file
                shutil.copy(file,basedir+"/"+options.ssl_output_folder+"/"+file.split("_",1)[1])

else: #This is for when fractions is true... so we'll organize the output into fractions
      #fractions_to_run_dict[fraction_tag].append(str(row['Original File Name'])+".mzML")
    blib_cmds=[]
    filter_cmds=[]

    for eachfraction in fractions_to_run_dict:
        fraction_set=fractions_to_run_dict[eachfraction]
        for each_chrom_fraction in fraction_set:
            if not os.path.isdir(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"):
                os.mkdir(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/")
            #if not options.no_mzml:
            shutil.copy(os.path.join(basedir,run_dict[each_chrom_fraction]),basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"+run_dict[each_chrom_fraction])

    for eachfraction in fractions_to_run_dict:
        os.chdir(basedir)
        fraction_set=fractions_to_run_dict[eachfraction]
        for eachrun in fraction_set:
            this_run_results=results_per_run[eachrun]
            if fido_q:
                this_run_results['fido_filter']=0
                this_run_grouped=this_run_results.groupby(numpy.arange(len(this_run_results))//multiprocessing.cpu_count())
                this_run_results=applyParallelHalf(this_run_grouped,fido_filter)
                print this_run_results.columns,"this is columns..."
                this_run_results=this_run_results[this_run_results['fido_filter']==1]
                this_run_results=this_run_results.drop('fido_filter',axis=1)
                del this_run_grouped

            #print "------------------------------"
            #print "each run is ",eachrun
            #print set(this_run_results['file_idx']),"idx set..."
            #print set(this_run_results['file']),"file set..."
            #print "------------------------------"

            os.chdir(basedir)
            os.chdir(options.operation_folder+str(run_to_group_dict[eachrun])+".pin_out/crux-output/")

            if luciphor:
                if options.local_flr is True:
                    if options.one_pps is True:
                        mask=this_run_results[numpy.logical_or(( this_run_results.luci_localFLR <= options.flr_threshold ) , (this_run_results.luci_numPPS - this_run_results.luci_numRPS == 0))]
                        type2_mask=this_run_results[numpy.logical_and(( this_run_results.luci_localFLR >= options.flr_threshold ), (this_run_results.luci_numPPS - this_run_results.luci_numRPS > 0))] #Unambiguous and poorly localized.

                    else:
                        mask=this_run_results[( this_run_results.luci_localFLR <= options.flr_threshold)]
                        type2_mask=this_run_results[( this_run_results.luci_localFLR >= options.flr_threshold )] #Unambiguous and poorly localized.
                else:
                    if options.one_pps is True:
                        mask=this_run_results[numpy.logical_or(( this_run_results.luci_globalFLR <= options.flr_threshold ) , (this_run_results.luci_numPPS - this_run_results.luci_numRPS == 0))]
                        type2_mask=this_run_results[numpy.logical_and(( this_run_results.luci_globalFLR >= options.flr_threshold ), (this_run_results.luci_numPPS - this_run_results.luci_numRPS > 0))] #Unambiguous and poorly localized.

                    else:
                        mask=this_run_results[( this_run_results.luci_globalFLR <= options.flr_threshold)]
                        type2_mask=this_run_results[( this_run_results.luci_globalFLR >= options.flr_threshold )] #Unambiguous and poorly localized.
            elif phosphoRS:
                if options.one_pps is True:
                    mask=this_run_results[numpy.logical_or(( this_run_results.pRS_peptideLocalizationProbability >= options.prs_prob_threshold ) , (this_run_results.pRS_numPPS - this_run_results.numModSites == 0))]
                    type2_mask=this_run_results[numpy.logical_and(( this_run_results.pRS_peptideLocalizationProbability >= options.prs_prob_threshold ), (this_run_results.pRS_numPPS - this_run_results.numModSites > 0))] #Unambiguous and poorly localized.
                else:
                    mask=this_run_results[( this_run_results.pRS_peptideLocalizationProbability >= options.prs_prob_threshold)]
                    type2_mask=this_run_results[( this_run_results.pRS_peptideLocalizationProbability < options.prs_prob_threshold )] #Unambiguous and poorly localized.
            elif ptmRS:
                #if options.one_pps is True:
                #    mask=this_run_results[numpy.logical_or(( this_run_results.ptmRS_peptideLocalizationProbability >= options.ptmrs_prob_threshold ) , (this_run_results.ptmRS_numPPS - this_run_results.ptmRS_numMods == 0))]
                #    type2_mask=this_run_results[numpy.logical_and(( this_run_results.ptmRS_peptideLocalizationProbability >= options.ptmrs_prob_threshold ), (this_run_results.ptmRS_numPPS - this_run_results.ptmRS_numMods > 0))] #Unambiguous and poorly localized.

                mask=this_run_results[( this_run_results.ptmRS_peptideLocalizationProbability >= options.ptmrs_prob_threshold)]
                type2_mask=this_run_results[( this_run_results.ptmRS_peptideLocalizationProbability < options.ptmrs_prob_threshold )] #Unambiguous and poorly localized.

            else:
                mask=this_run_results
            if options.only_mod is True:
                if luciphor:
                    mask=mask[mask['luci_numRPS'] >= 1].copy(deep=True)
                elif phosphoRS:
                    mask=mask[mask['numModSites'] >= 1].copy(deep=True)
                elif ptmRS:
                    mask=mask[mask['ptmRS_numMods'] >= 1].copy(deep=True)
            if luciphor:
                ssl_df=mask[['file','scan','charge','luci_sequence','percolator q-value']]
                ssl_df.rename(columns={'luci_sequence':'sequence'}, inplace=True)
            elif phosphoRS:
                ssl_df=mask[['file','scan','charge','sequence','percolator q-value']]
                #ssl_df.rename(columns={'pRS_sequence':'sequence'}, inplace=True)
            elif ptmRS:
                ssl_df=mask[['file','scan','charge','sequence','percolator q-value']]
                #ssl_df.rename(columns={'ptmRS_sequence':'sequence'}, inplace=True)
            else:
                ssl_df=mask[['file','scan','charge','sequence','percolator q-value']]
            ssl_df.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
            ssl_df_filtered=ssl_df[(ssl_df['percolator qvalue']<=options.q_threshold)]
            with open(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"+run_dict[eachrun].replace(".mzML","")+".ssl",'wb') as ssl_writer:
                ssl_df_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                ssl_df_filtered['score-type']="PERCOLATOR QVALUE"
                ssl_df_filtered.to_csv(path_or_buf=ssl_writer,sep="\t",index=False,header=True)
                if luciphor:
                    with open(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"+run_dict[eachrun].replace(".mzML","")+"_type2.ssl",'wb') as type2_ssl_writer:
                        ssl_df_type2=type2_mask[['file','scan','charge','luci_sequence','percolator q-value']]
                        ssl_df_type2.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
                        ssl_df_type2.rename(columns={'luci_sequence':'sequence'}, inplace=True)
                        ssl_df_type2_filtered=ssl_df_type2[(ssl_df_type2['percolator qvalue']<=options.q_threshold)]
                        ssl_df_type2_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                        ssl_df_type2_filtered['score-type']="PERCOLATOR QVALUE"
                        ssl_df_type2_filtered.to_csv(path_or_buf=type2_ssl_writer,sep="\t",index=False,header=True)
                elif phosphoRS:
                    with open(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"+run_dict[eachrun].replace(".mzML","")+"_type2.ssl",'wb') as type2_ssl_writer:
                        #ssl_df_type2=type2_mask[['file','scan','charge','pRS_sequence','percolator q-value']]
                        ssl_df_type2=type2_mask[['file','scan','charge','sequence','percolator q-value']]
                        ssl_df_type2.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
                        #ssl_df_type2.rename(columns={'pRS_sequence':'sequence'}, inplace=True)
                        ssl_df_type2_filtered=ssl_df_type2[(ssl_df_type2['percolator qvalue']<=options.q_threshold)]
                        ssl_df_type2_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                        ssl_df_type2_filtered['score-type']="PERCOLATOR QVALUE"
                        ssl_df_type2_filtered.to_csv(path_or_buf=type2_ssl_writer,sep="\t",index=False,header=True)
                elif ptmRS:
                    with open(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"+run_dict[eachrun].replace(".mzML","")+"_type2.ssl",'wb') as type2_ssl_writer:
                        #ssl_df_type2=type2_mask[['file','scan','charge','ptmRS_sequence','percolator q-value']]
                        ssl_df_type2=type2_mask[['file','scan','charge','sequence','percolator q-value']]
                        ssl_df_type2.rename(columns={'percolator q-value':'percolator qvalue'}, inplace=True)
                        #ssl_df_type2.rename(columns={'ptmRS_sequence':'sequence'}, inplace=True)
                        ssl_df_type2_filtered=ssl_df_type2[(ssl_df_type2['percolator qvalue']<=options.q_threshold)]
                        ssl_df_type2_filtered.rename(columns={'percolator qvalue':'score'}, inplace=True)
                        ssl_df_type2_filtered['score-type']="PERCOLATOR QVALUE"
                        ssl_df_type2_filtered.to_csv(path_or_buf=type2_ssl_writer,sep="\t",index=False,header=True)
        if options.blib:
            print "We're going to build blib files!"
            os.chdir(basedir)
            #os.chdir(basedir+"/"+options.ssl_output_folder)
            os.chdir(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/")
            #cmd = '/galaxy-central/tools/wohl-proteomics/ssl_converter/blibbuild/bin/BlibBuild -a milkyway-galaxy *.ssl '+eachfraction.replace("-","")+".ssl" #combined_spectral_lib.blib
            for file in glob.glob("*type2.ssl"):
                os.rename(file,file.split(".")[0]+".not_ssl")
                print "protected",file,"from inclusion in spectral lib..."

            command_folder=basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"
            cmd = 'wine /galaxy-central/tools/wohl-proteomics/ssl_converter/skylineblib/BlibBuild.exe -a milkyway-galaxy -m 1000M {0}*.ssl {0}combined_spectral_lib.blib'.format(command_folder)
            blib_cmds.append(cmd)
            print "storing command to run later",cmd
            #subprocess.call(cmd,shell=True)
            filtercmd='wine /galaxy-central/tools/wohl-proteomics/ssl_converter/skylineblib/BlibFilter.exe {0} {1}'.format(command_folder+"combined_spectral_lib.blib",command_folder+"filtered_spectral_lib.blib")
            filter_cmds.append(filtercmd)
            print "storing command for filter later",filtercmd
            #subprocess.call(filtercmd,shell=True)

            #cmd = 'ls *.ssl | /galaxy-central/tools/wohl-proteomics/ssl_converter/blibbuild/bin/BlibBuild -a milkyway-galaxy -m 1000M combined_spectral_lib.blib'
            #print "Running command ...",cmd
            #subprocess.call(cmd,shell=True)

if fractions and options.blib:
    chunk_size=8 # Max concurrency...
    job_list=[blib_cmds[i:i + chunk_size] for i in range(0, len(blib_cmds), chunk_size)]
    for each_jobset in job_list:
        processes=[]
        for each_job in each_jobset:
            print "Running ...",each_job
            processes.append(subprocess.Popen(each_job,shell=True))
        for each_proc in processes:
            each_proc.wait()

    job_list=[filter_cmds[i:i + chunk_size] for i in range(0, len(filter_cmds), chunk_size)]
    for each_jobset in job_list:
        processes=[]
        for each_job in each_jobset:
            print "Running Filter...",each_job
            processes.append(subprocess.Popen(each_job,shell=True))
        for each_proc in processes:
            each_proc.wait()

    for eachfraction in fractions_to_run_dict:
        os.chdir(basedir)
        fraction_set=fractions_to_run_dict[eachfraction]
        for eachrun in fraction_set:
            os.chdir(basedir)
            os.chdir(basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/")

            if options.mc_mzml_files is not None:
                file_list=[file for file in glob.glob("*.mzML")]
                for file in file_list:
                    os.remove(file)
                os.chdir(basedir)
                for file in glob.glob("mc_*.mzML"):
                    if file.split("_",1)[1] in file_list:
                        shutil.copy(file,basedir+"/"+options.ssl_output_folder+"/"+eachfraction.replace("-","")+"/"+file.split("_",1)[1])
            for file in glob.glob("*.not_ssl"):
                os.rename(file,file.split(".")[0]+".ssl")

            os.chdir(basedir)

if options.fido_q_threshold is not None:
    os.chdir(basedir)
    #While we're here, let's go ahead and handle database filtering!
    #fido_q_df = pandas.read_csv(options.fido_q_raw,sep=",")
    fido_q_df = pandas.read_csv(options.fido_q_raw,sep="\t")
    fido_q_df=fido_q_df[fido_q_df['q-value']<=options.fido_q_threshold] #filter down...
    proteins_to_keep=fido_q_df['protein group'].unique().tolist()#this is the list of proteins we want to keep.

    with open(options.fasta,'rb') as fasta_file:
        fasta_dict=SeqIO.to_dict(SeqIO.parse(fasta_file,"fasta"))
    new_fasta=[]
    for eachprotein in proteins_to_keep:
        if eachprotein in fasta_dict:
            new_fasta.append(fasta_dict[eachprotein])

        #print new_fasta,len(new_fasta),len(proteins_to_keep)
    shutil.copy(options.fasta,basedir+"/"+options.ssl_output_folder+"/"+"UNFILTERED_"+options.fasta)
    with open(basedir+"/"+options.ssl_output_folder+"/"+"FIDO_FILTERED_"+options.fasta,'wb') as fasta_writer:
        SeqIO.write(new_fasta,fasta_writer,"fasta")
    print "FIDO filtered FASTA written!"
    if options.ffasta is not None:
        shutil.copy(basedir+"/"+options.ssl_output_folder+"/"+"FIDO_FILTERED_"+options.fasta,options.ffasta)
        print "Copied the filtered fasta to the output location specified..."
else:
    os.chdir(basedir)
    shutil.copy(options.fasta,basedir+"/"+options.ssl_output_folder+"/"+"UNFILTERED_"+options.fasta)

os.chdir(basedir)
if options.no_mzml:
    mzml_files=[]
    for root, dirs, files in os.walk("."):
        for file_name in fnmatch.filter(files, '*.mzML'):
            mzml_files.append(os.path.join(root,file_name))
            #print "will have to remove ",file_name

    for each_file in mzml_files:
        os.remove(each_file)

print "All done!"
sys.exit(0)


text:
console.log('loading thunk...');
script.ready('plugin', function() {
  console.log('bar & baz loaded');
  console.log(thunkor + thunky);
});

redpajama_set_name: RedPajamaGithub


text:
Changelog:
===

1.0
---

Initial release.  Analyzes an Infomedia dump and mail reports as attachements.

1.1
---

Now follows symbolic links, and does not fail if no files were processed.


text:
#ifndef TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_CONFIGURATION_C_NNAPI_PLUGIN_H_
#define TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_CONFIGURATION_C_NNAPI_PLUGIN_H_

// This header file is for the delegate plugin for NNAPI.
//
// For the C++ delegate plugin interface, the NNAPI delegate plugin is added to
// the DelegatePluginRegistry by the side effect of a constructor for a static
// object, so there's no public API needed for this plugin, other than the API
// of tflite::delegates::DelegatePluginRegistry, which is declared in
// delegate_registry.h.
//
// But to provide a C API to access the NNAPI delegate plugin, we do expose
// some functions, which are declared below.

#include "tensorflow/lite/experimental/acceleration/configuration/c/delegate_plugin.h"

#ifdef __cplusplus
extern "C" {
#endif

// C API for the NNAPI delegate plugin.
// Returns a pointer to a statically allocated table of function pointers.
const TfLiteDelegatePlugin* TfLiteXnnpackDelegatePluginCApi();

#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // TENSORFLOW_LITE_EXPERIMENTAL_ACCELERATION_CONFIGURATION_C_NNAPI_PLUGIN_H_


text:
require 'rails_helper'

describe "_form.html.erb" do
  include GoUtil
  include FormUI
  include ReflectiveUtil

  before(:each) do
    @material_config = TfsMaterialConfig.new(GoCipher.new, UrlArgument.new("http://10.4.4.101:8080/tfs/Sample"), "loser", "domain" ,"passwd", "walk_this_path")
    @material_config.setAutoUpdate(true)
    @material_config.setName(CaseInsensitiveString.new("Tfs Material Name"))
    @material_config.setFolder("boulder")
    @ignored_file = IgnoredFiles.new("/sugar")
    @material_config.setFilter(Filter.new([@ignored_file, IgnoredFiles.new("/jaggery")].to_java(IgnoredFiles)))

    assign(:cruise_config, @cruise_config = BasicCruiseConfig.new)
    set(@cruise_config, "md5", "abc")
  end

  it "should render all tfs material attributes" do
    in_params(:pipeline_name => "pipeline_name")

    render :partial => "admin/materials/tfs/form.html", :locals => {:scope => {:material => @material_config, :url => "http://google.com", :method => "POST", :submit_label => "FOO"}}

    expect(response.body).to have_selector("input[type='hidden'][name='current_tab'][value='materials']", {visible: :hidden})
    expect(response.body).to have_selector(".popup_form input[type='text'][name='material[#{com.thoughtworks.go.config.materials.AbstractMaterialConfig::MATERIAL_NAME}]'][value='Tfs Material Name']")
    expect(response.body).to have_selector(".popup_form input[type='text'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::URL}]'][value='http://10.4.4.101:8080/tfs/Sample']")
    expect(response.body).to have_selector(".popup_form input[type='text'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::USERNAME}]'][value='loser']")
    expect(response.body).to have_selector(".popup_form input[type='text'][name='material[#{com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig::DOMAIN}]'][value='domain']")
    expect(response.body).to have_selector(".popup_form input[type='password'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::PASSWORD}]'][value='passwd']")
    expect(response.body).to have_selector(".popup_form input[type='hidden'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::ENCRYPTED_PASSWORD}]'][value='#{@material_config.getEncryptedPassword()}']", {visible: :hidden})
    expect(response.body).to have_selector(".popup_form input[type='text'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::FOLDER}]'][value='boulder']")
    expect(response.body).to have_selector(".popup_form input[type='checkbox'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::AUTO_UPDATE}]'][checked='checked']")
    expect(response.body).to have_selector(".popup_form input[type='text'][name='material[#{com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig::PROJECT_PATH}]'][value='walk_this_path']")
    expect(response.body).to have_selector(".popup_form textarea[name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::FILTER}]']", :text => "/sugar,/jaggery")
    expect(response.body).to have_selector(".form_buttons button[type='submit'] span", :text => "FOO")

    expect(response.body).not_to have_selector(".popup_form input[type='text'][name='material[workspaceOwner]']")
    expect(response.body).not_to have_selector(".popup_form input[type='text'][name='material[workspace]']")
  end

  it "should display the password field disabled in edit mode" do
    in_params(:pipeline_name => "pipeline_name")

    render :partial => "admin/materials/tfs/form.html", :locals => {:scope => {:material => @material_config, :url => "http://google.com", :method => "POST", :submit_label => "FOO", :edit_mode => true}}

    expect(response.body).to have_selector(".popup_form input[disabled='disabled'][type='password'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::PASSWORD}]'][value='']")
    expect(response.body).to have_selector(".popup_form input[type='checkbox'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::PASSWORD_CHANGED}]']")
  end

  it "should display the password field as textbox in new mode" do
    in_params(:pipeline_name => "pipeline_name")

    render :partial => "admin/materials/tfs/form.html", :locals => {:scope => {:material => @material_config, :url => "http://google.com", :method => "POST", :submit_label => "FOO", :edit_mode => false}}

    expect(response.body).to have_selector(".popup_form input[type='password'][name='material[#{com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig::PASSWORD}]']")
    Capybara.string(response.body).find(".popup_form  div[class='hidden']").tap do |popup_form|
      expect(popup_form).to have_selector("input[type='checkbox'][name='material[#{com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig::PASSWORD_CHANGED}]'][value='1'][checked='checked']")
    end
  end

  it "should display check connection button" do
    in_params(:pipeline_name => "pipeline_name")

    render :partial => "admin/materials/tfs/form.html", :locals => {:scope => {:material => @material_config, :url => "http://google.com", :method => "POST", :submit_label => "FOO"}}

    expect(response.body).to have_selector(".popup_form button#check_connection_tfs", :text => "CHECK CONNECTION")
    expect(response.body).to have_selector(".popup_form #vcsconnection-message_tfs", :text => "", visible: false)
    expect(response.body).to have_selector(".url")
    expect(response.body).to have_selector(".username")
    expect(response.body).to have_selector(".password")
  end

  it "should display new tfs material view with errors" do
    error = config_error(com.thoughtworks.go.config.materials.ScmMaterialConfig::URL, "Url is wrong")
    error.add(com.thoughtworks.go.config.materials.ScmMaterialConfig::USERNAME, "Username is wrong")
    error.add(com.thoughtworks.go.config.materials.ScmMaterialConfig::MATERIAL_NAME, "Material Name is so wrong")
    error.add(com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig::PROJECT_PATH, "path you talk and path you walk are different.")
    error.add(com.thoughtworks.go.config.materials.ScmMaterialConfig::PASSWORD, "Password is wrong")
    error.add(com.thoughtworks.go.config.materials.ScmMaterialConfig::AUTO_UPDATE, "AUTO_UPDATE is wrong")
    error.add(com.thoughtworks.go.config.materials.ScmMaterialConfig::FOLDER, "Folder is wrong")
    set(@material_config, "errors", error)
    set(@ignored_file, "configErrors", config_error(com.thoughtworks.go.config.materials.IgnoredFiles::PATTERN, "Filter is wrong"))

    in_params(:pipeline_name => "pipeline_name")

    render :partial => "admin/materials/tfs/form.html", :locals => {:scope => {:material => @material_config, :url => "http://google.com", :method => "POST", :submit_label => "foo"}}

    Capybara.string(response.body).find('.popup_form').tap do |popup_form|
      expect(popup_form).to have_selector("div.field_with_errors input[type='text'][name='material[#{com.thoughtworks.go.config.materials.AbstractMaterialConfig::MATERIAL_NAME}]'][value='Tfs Material Name']")
      expect(popup_form).to have_selector("div.form_error", :text => "Material Name is so wrong")

      expect(popup_form).to have_selector("div.field_with_errors input[type='text'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::URL}]'][value='http://10.4.4.101:8080/tfs/Sample']")
      expect(popup_form).to have_selector("div.form_error", :text => "Url is wrong")

      expect(popup_form).to have_selector("div.field_with_errors input[type='text'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::USERNAME}]'][value='loser']")
      expect(popup_form).to have_selector("div.form_error", :text => "Username is wrong")

      expect(popup_form).to have_selector("div.field_with_errors input[type='password'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::PASSWORD}]'][value='passwd']")
      expect(popup_form).to have_selector("div.form_error", :text => "Password is wrong")

      expect(popup_form).to have_selector("div.field_with_errors input[type='text'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::FOLDER}]'][value='boulder']")
      expect(popup_form).to have_selector("div.form_error", :text => "Folder is wrong")

      expect(popup_form).to have_selector("div.field_with_errors input[type='checkbox'][name='material[#{com.thoughtworks.go.config.materials.ScmMaterialConfig::AUTO_UPDATE}]'][checked='checked']")
      expect(popup_form).to have_selector("div.form_error", :text => "AUTO_UPDATE is wrong")

      expect(popup_form).to have_selector("div.field_with_errors input[type='text'][name='material[#{com.thoughtworks.go.config.materials.tfs.TfsMaterialConfig::PROJECT_PATH}]'][value='walk_this_path']")
      expect(popup_form).to have_selector("div.form_error", :text => "path you talk and path you walk are different.")

      #Have skipped asserting on the div fieldWithError thats rendered around the text area , since the keys mismatch (pattern vs filter). Div around the actual text area is currently
      #not affecting functionality in any way.
      expect(popup_form).to have_selector("div.form_error", :text => "Filter is wrong")

      expect(popup_form).not_to have_selector("div.field_with_errors input[type='text'][name='material[workspaceOwner]'][value='m1cr050f7']")
      expect(popup_form).not_to have_selector("div.field_with_errors input[type='text'][name='material[workspace]'][value='work_in_space']")
    end
  end

  it "should not generate the id for url, domain, username and project_path fields" do
    render :partial => "admin/materials/tfs/form.html", :locals => {:scope => {:material => @material_config, :url => "http://google.com", :method => "POST", :submit_label => "FOO"}}

    Capybara.string(response.body).all(".form_item .form_item_block").tap do |text_field|
      expect(text_field[1]).to_not have_selector("input[type='text'][class='form_input url'][id]")
      expect(text_field[3]).to_not have_selector("input[type='text'][class='form_input domain'][id]")
      expect(text_field[4]).to_not have_selector("input[type='text'][class='form_input username'][id]")
      expect(text_field[6]).to_not have_selector("input[type='text'][class='form_input project_path'][id]")
    end
  end
end


text:
title: Expand Behavior
page_title: Expand Behavior - RadPivotGrid
description: Expand Behavior
slug: winforms/pivotgrid/expand-behavior
tags: expand,behavior
published: True
position: 16
previous_url: pivotgrid-expand-behavior
---

# Expand Behavior

In this article we will show you how to change the initial expand/collapse behavior of __RadPivotGrid__ rows and columns.

>important Initial state is the state of __RadPivotGrid__ after refresh of the used data provider.
>

## GroupsExpandBehavior

In order to control the expand/collapse state of rows and columns in __RadPivotGrid__ you have to use an instance of __GroupsExpandBehavior__ class from *Telerik.Pivot.Core* namespace. It has two properties that you can modify:

* __Expanded__: Bool property which controls the state. When it is *true* the groups will be expanded. When the value is *false* the groups will be collapsed.

* __UpToLevel__: Integer property which controls the levels for which to apply the behavior.

You can combine the two properties to achieve the desired result. The default value of __Expanded__ property is *true*, so if you don't set it (or if you do not set ExpandBehavior), all groups will be expanded. If you do not set __UpToLevel__, the behavior will be applied to all groups (which is its default state). For example, if you set Expanded = false and UpToLevel = 2, all levels up to the set one (levels 0 and 1) will be collapsed, all groups with level greater than or equal to 2 will be expanded. So at initial state you will see all groups collapsed, but if you expand the first two levels, all other groups below them will be expanded.

>caption Figure 1: Group Levels

![pivotgrid-expand-behavior 001](images/pivotgrid-expand-behavior001.png)

## Set Expand Behavior

__RadPivotGrid__ has two properties to control the expand behavior - __RowGroupsExpandBehavior__ and __ColumnGroupsExpandBehavior__. As you can guess, the first one controls the expand behavior of the rows and the second one - columns behavior. If you do not set these properties, all groups in rows and columns will be expanded.

#### Expanding Groups

{{source=..\SamplesCS\PivotGrid\ExpandBehavior.cs region=expand}}
{{source=..\SamplesVB\PivotGrid\ExpandBehavior.vb region=expand}}

````C#

RadPivotGrid pivot = new RadPivotGrid();
pivot.RowGroupsExpandBehavior = new GroupsExpandBehavior()
{
    Expanded = false,
    UpToLevel = 2
};
pivot.ColumnGroupsExpandBehavior = new GroupsExpandBehavior() { Expanded = false };

````
````VB.NET
Dim pivot As New RadPivotGrid()
pivot.RowGroupsExpandBehavior = New GroupsExpandBehavior() With {.Expanded = False, .UpToLevel = 2}
pivot.ColumnGroupsExpandBehavior = New GroupsExpandBehavior() With {.Expanded = False}

````

{{endregion}}

## Change Behavior at Run-time

If you want to collapse all groups in __RadPivotGrid__ you can change the behavior at run-time and refresh the data provider to apply the change immediately. For example, you may add two buttons in your application and handle the *Click* event for each of them in order to expand/collapse the groups. Note that the new behavior will be applied each time when the data provider is refreshed.

#### Changing Expand Behavior

{{source=..\SamplesCS\PivotGrid\ExpandBehavior.cs region=click}}
{{source=..\SamplesVB\PivotGrid\ExpandBehavior.vb region=click}}

````C#

public void ExpandGroupsButton_Click(object sender, RoutedEventArgs e)
{
    (this.pivot.RowGroupsExpandBehavior as GroupsExpandBehavior).Expanded = true;
    (this.pivot.ColumnGroupsExpandBehavior as GroupsExpandBehavior).Expanded = true;
    this.pivot.DataProvider.Refresh();
}

private void CollapseGroupsButton_Click(object sender, RoutedEventArgs e)
{
    (this.pivot.RowGroupsExpandBehavior as GroupsExpandBehavior).Expanded = false;
    (this.pivot.ColumnGroupsExpandBehavior as GroupsExpandBehavior).Expanded = false;
    this.pivot.DataProvider.Refresh();
}

````
````VB.NET
Public Sub ExpandGroupsButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    TryCast(Me.pivot.RowGroupsExpandBehavior, GroupsExpandBehavior).Expanded = True
    TryCast(Me.pivot.ColumnGroupsExpandBehavior, GroupsExpandBehavior).Expanded = True
    Me.pivot.DataProvider.Refresh()
End Sub
Private Sub CollapseGroupsButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    TryCast(Me.pivot.RowGroupsExpandBehavior, GroupsExpandBehavior).Expanded = False
    TryCast(Me.pivot.ColumnGroupsExpandBehavior, GroupsExpandBehavior).Expanded = False
    Me.pivot.DataProvider.Refresh()
End Sub

````

{{endregion}}

# See Also

* [Layout Settings]({%slug winforms/pivotgrid/layout-settings%})
* [End-user Functionalities]({%slug winforms/pivotgrid/end-user-functionalities%})


text:
#region License, Terms and Conditions
//
// Product.cs
//
// Authors: Kori Francis <twitter.com/djbyter>
// Copyright (C) 2015 Kori Francis. All rights reserved.
//
// THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW:
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#endregion

namespace ShopifyDotNet.Products
{
    #region Imports
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    #endregion

    /// <summary>
    /// A product variant is a different version of a product, such as differing sizes or differing colors.
    /// </summary>
    public class Variant
    {
        /// <summary>
        /// The unique numeric identifier for the product variant.
        /// </summary>
        public long id { get; set; }

        /// <summary>
        /// The unique numeric identifier for the product.
        /// </summary>
        public long product_id { get; set; }

        /// <summary>
        /// The title of the product variant.
        /// </summary>
        public string title { get; set; }

        /// <summary>
        /// A unique identifier for the product in the shop.
        /// </summary>
        public string sku { get; set; }

        /// <summary>
        /// The order of the product variant in the list of product variants. 1 is the first position.
        /// </summary>
        public int position { get; set; }

        /// <summary>
        /// The weight of the product variant in grams.
        /// </summary>
        public int grams { get; set; }

        /// <summary>
        /// Specifies whether or not customers are allowed to place an order for a product variant when it's out of stock. Valid values are: "deny" (default) or "continue"
        /// </summary>
        public string inventory_policy { get; set; }

        /// <summary>
        /// Service who is doing the fulfillment. Valid values are: manual,
        /// </summary>
        public string fulfillment_service { get; set; }

        /// <summary>
        /// Specifies whether or not Shopify tracks the number of items in stock for this product variant. Valid values are: "blank" or "shopify"
        /// </summary>
        public string inventory_management { get; set; }

        /// <summary>
        /// The price of the product variant.
        /// </summary>
        public string price { get; set; }

        /// <summary>
        /// The competitors prices for the same item.
        /// </summary>
        public object compare_at_price { get; set; }

        /// <summary>
        /// Custom properties that a shop owner can use to define product variants. Multiple options can exist.
        /// </summary>
        public string option1 { get; set; }

        /// <summary>
        /// Custom properties that a shop owner can use to define product variants. Multiple options can exist.
        /// </summary>
        public object option2 { get; set; }

        /// <summary>
        /// Custom properties that a shop owner can use to define product variants. Multiple options can exist.
        /// </summary>
        public object option3 { get; set; }

        /// <summary>
        /// The date and time when the product variant was created. The API returns this value in ISO 8601 format.
        /// </summary>
        public DateTime created_at { get; set; }

        /// <summary>
        /// The date and time when the product variant was last modified. The API returns this value in ISO 8601 format.
        /// </summary>
        public DateTime updated_at { get; set; }

        /// <summary>
        /// Specifies whether or not a tax is charged when the product variant is sold.
        /// </summary>
        public bool taxable { get; set; }

        /// <summary>
        /// Specifies whether or not a customer needs to provide a shipping address when placing an order for this product variant.
        /// </summary>
        public bool requires_shipping { get; set; }

        /// <summary>
        /// The barcode, UPC or ISBN number for the product.
        /// </summary>
        public string barcode { get; set; }

        /// <summary>
        /// The number of items in stock for this product variant.
        /// </summary>
        public int inventory_quantity { get; set; }

        /// <summary>
        /// The original stock level the client believes the product variant has. This should be sent to avoid a race condition when the item being adjusted is simultaneously sold online.
        /// </summary>
        public int old_inventory_quantity { get; set; }

        /// <summary>
        /// The identifier of the image
        /// </summary>
        public long? image_id { get; set; }

        /// <summary>
        /// The weight of the product variant in the unit system specified with weight_unit.
        /// </summary>
        public double weight { get; set; }

        /// <summary>
        /// The unit system that the product variant's weight is measure in. The weight_unit can be either "g", "kg, "oz", or "lb".
        /// </summary>
        public string weight_unit { get; set; }
    }

    /// <summary>
    /// The product option
    /// </summary>
    public class Option
    {
        /// <summary>
        /// The option identifier
        /// </summary>
        public long id { get; set; }

        /// <summary>
        /// The identifier of the product the option belongs to
        /// </summary>
        public long product_id { get; set; }

        /// <summary>
        /// The name of the option
        /// </summary>
        public string name { get; set; }

        /// <summary>
        /// The option position
        /// </summary>
        public int position { get; set; }

        /// <summary>
        /// The values associated with the option
        /// </summary>
        public List<string> values { get; set; }
    }

    /// <summary>
    /// Products are easier to sell if customers can see pictures of them, which is why there are product images.
    /// </summary>
    public class Image
    {
        /// <summary>
        /// A unique numeric identifier for the product image.
        /// </summary>
        public long id { get; set; }

        /// <summary>
        /// The id of the product associated with the image.
        /// </summary>
        public long product_id { get; set; }

        /// <summary>
        /// The order of the product image in the list. The first product image is at position 1 and is the "main" image for the product.
        /// </summary>
        public int position { get; set; }

        /// <summary>
        /// The date and time when the product image was created. The API returns this value in ISO 8601 format.
        /// </summary>
        public DateTime created_at { get; set; }

        /// <summary>
        /// The date and time when the product image was last modified. The API returns this value in ISO 8601 format.
        /// </summary>
        public DateTime updated_at { get; set; }

        /// <summary>
        /// Specifies the location of the product image.
        /// </summary>
        public string src { get; set; }

        /// <summary>
        /// An array of variant ids associated with the image
        /// </summary>
        public List<long> variant_ids { get; set; }
    }

    /// <summary>
    /// A list of products
    /// </summary>
    public class ProductList
    {
        /// <summary>
        /// The list of products
        /// </summary>
        public List<Product> products { get; set; }
    }

    /// <summary>
    /// A product is an individual item for sale in a Shopify shop. Products are often physical, but don't have to be;
    /// a digital download (such as a movie, music or ebook file) also qualifies as a product, as do services (such as
    /// equipment rental, work for hire, customization of another product or an extended warranty). Simply put: if
    /// it's something for sale in a shop, it's a Product.
    /// </summary>
    public class Product
    {
        /// <summary>
        /// The unique numeric identifier for the product. Product ids are unique across the entire Shopify system; no two products will have the same id, even if they're from different shops.
        /// </summary>
        public long id { get; set; }

        /// <summary>
        /// The name of the product. In a shop's catalog, clicking on a product's title takes you to that product's page. On a product's page, the product's title typically appears in a large font.
        /// </summary>
        public string title { get; set; }

        /// <summary>
        /// The description of the product, complete with HTML formatting.
        /// </summary>
        public string body_html { get; set; }

        /// <summary>
        /// The name of the vendor of the product.
        /// </summary>
        public string vendor { get; set; }

        /// <summary>
        /// A categorization that a product can be tagged with, commonly used for filtering and searching.
        /// </summary>
        public string product_type { get; set; }

        /// <summary>
        /// The date and time when the product was created. The API returns this value in ISO 8601 format.
        /// </summary>
        public DateTime created_at { get; set; }

        /// <summary>
        /// A human-friendly unique string for the Product automatically generated from its title. They are used by the Liquid templating language to refer to objects.
        /// </summary>
        public string handle { get; set; }

        /// <summary>
        /// The date and time when the product was last modified. The API returns this value in ISO 8601 format.
        /// </summary>
        public DateTime updated_at { get; set; }

        /// <summary>
        /// The date and time when the product was published. The API returns this value in ISO 8601 format.
        /// </summary>
        public DateTime published_at { get; set; }

        /// <summary>
        /// The suffix of the liquid template being used. By default, the original template is called product.liquid, without any suffix. Any additional templates will be: product.suffix.liquid.
        /// </summary>
        public object template_suffix { get; set; }

        /// <summary>
        /// The sales channels in which the product is visible.
        /// </summary>
        public string published_scope { get; set; }

        /// <summary>
        /// A categorization that a product can be tagged with, commonly used for filtering and searching. Each comma-separated tag has a character limit of 255.
        /// </summary>
        public string tags { get; set; }

        /// <summary>
        /// A list of variant objects, each one representing a slightly different version of the product. For example, if a product comes in different sizes and colors, each size and color permutation (such as "small black", "medium black", "large blue"), would be a variant.
        /// </summary>
        public List<Variant> variants { get; set; }

        /// <summary>
        /// Custom product property names like "Size", "Color", and "Material". Products are based on permutations of these options. A product may have a maximum of 3 options. 255 characters limit each.
        /// </summary>
        public List<Option> options { get; set; }

        /// <summary>
        /// A list of image objects, each one representing an image associated with the product.
        /// </summary>
        public List<object> images { get; set; }

        /// <summary>
        /// The product image information
        /// </summary>
        public Image image { get; set; }
    }
}


text:
CODA => CO(re) D(ump) A(nalyzer) or C(ore) O(bject) D(ebugger) and A(nalyzer)
--------

This tool probes _Linux-x86\_64_ coredumps in batch mode as well as interactively.
coredump has to be full(not a data/stack segment dump only).
If the coredump is not full, backtraces will be curtailed.
This tool does not require binaries, only full core dump is required.

## Architecture supported
    compile on x86_64 Linux box.

## How to enable full coredump in linux

On bash prompt:

    $> cat /proc/$$/coredump_filter
    00000033

    $> echo 0x7f > /proc/$$/coredump_filter
    $> cat /proc/$$/coredump_filter
    0000007f

For furter info 'man core'.

## Compilation
    $> apt-get install binutils-dev #for opcodes library
    $> make

## Help
    $> ./coda
    Argument Missing, provide (corefile)

    Usage: ./coda <options> corefile
    options:
      -B Backtrace all
      -m Show, if mini-coredump
      -d Enable de-mangling
      -i Interactive mode

    $> ./coda -i core.segfault.full
    Welcome to coda interactive command line.
    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND.
    Supported on x86_64-linux.
    Coredump generated by command line => ./segfault_thr
    coda > help
    help       - Help for all interactive commands.
    demangle   - demangle 0|1
    dis        - Show disassembly of the function.
    btregs     - Show backtrace of the selected thread with registers.
    bt         - Show backtrace of the selected thread.
    mmap       - Show memory map.
    thread     - thread <number>.
    threads    - Show all threads.
    strings    - Extract strings from coredump under probe.
                     Usage: strings <pattern>
    xuint      - Extract unsigned int.
                     Usage: xuint addr <count>
    xchar      - Extract char.
                     Usage: xchar addr <count>
    xulong     - Extract unsigned long.
                     Usage: xulong addr <count>
    xint       - Extract int.
                     Usage: xint addr <count>
    xlong      - Extract long.
                     Usage: xlong addr <count>
    xaddr      - Extract address.
                     Usage: xaddr addr <count>
    q          - Exit program.

### For better backtrace, compile the binary with -rdynamic compiler flag and then generate the coredump.

Some time back I posted an answer on stackoverflow in response to a question - [get-backtrace-from-core-file-without-gdb](http://stackoverflow.com/questions/22461254/get-backtrace-from-core-file-without-gdb).

## How to extract backtrace from core dump

Getting a backtrace from a core file is very much architecture and OS specific, if you plan to extract it all by yourself.
gdb is a portable program which works on multiple architectures.

### gdb uses two techniques to extract the backtrace from coredump -

* Following the link list of frame pointer (ebp in case of x86 architecture).
* Using the exception handling frame work to do virtual unwinding. gdb requires binaries to extract the backtrace from coredump.
   Since binaries contains information, how to start the virtual unwinding.

### After this point my answer is specific to linux-x86_64 architecture.

Using the frame pointer i.e. rbp does not work when it comes to extracting backtrace reliably
if frame pointer is omitted or it is optimized program. On _x86\_64 architecture, compilers e.g. gcc_ emits
_.eh\_frame_ section which is used by gdb to do _virtual unwinding_(remember I am not talking about source level debugging of gdb). But gdb requires binaries to do virtual unwinding since gdb assumes core is without executable contents since, on linux box, kernel by default dumps only data segments.


text:
import * as React from 'react';

export function find(children: React.ReactNode, func: Function, context?: any) {
  let index = 0;
  let result: React.ReactNode;

  React.Children.forEach(children, child => {
    if (result) {
      return;
    }
    index += 1;
    if (func.call(context, child, index)) {
      result = child;
    }
  });

  return result;
}

export function map(children: React.ReactNode, func: Function, context?: any) {
  let index = 0;
  return React.Children.map(children, child => {
    if (!React.isValidElement(child)) {
      return child;
    }
    const handle = func.call(context, child, index);
    index += 1;
    return handle;
  });
}

export function mapCloneElement(children: React.ReactNode, func: Function, context?: any) {
  return map(
    children,
    (child: React.DetailedReactHTMLElement<any, HTMLElement>, index: number) =>
      React.cloneElement(child, {
        key: index,
        ...func(child, index)
      }),
    context
  );
}

export function count(children: React.ReactChildren) {
  return React.Children.count(Array.isArray(children) ? children.filter(child => child) : children);
}

function some(children: React.ReactNode, func: Function, context?: any) {
  let index = 0;
  let result = false;

  React.Children.forEach(children, child => {
    if (result) {
      return;
    }
    if (!React.isValidElement(child)) {
      return;
    }

    /* eslint-disable */
    if (func.call(context, child, (index += 1))) {
      result = true;
    }
  });

  return result;
}

export default {
  mapCloneElement,
  count,
  some,
  map,
  find
};


text:
<?php

namespace RESTfm;

/**
 * RESTfm Field Response class.
 */
class FieldResponse extends Response {

    /**
     * Output the response.
     *
     * Overrides parent method.
     */
    public function output() {
        $this->addHeader('X-RESTfm-Version', Version::getVersion());
        $this->addHeader('X-RESTfm-Protocol', Version::getProtocol());
        $this->addHeader('X-RESTfm-Status', $this->code);
        $this->addHeader('X-RESTfm-Reason', $this->reason);
        $this->addHeader('X-RESTfm-Method', $this->request->method);

        // Check if we need to authorise this origin (CORS)
        if (isset($_SERVER["HTTP_ORIGIN"]) && Config::checkVar('origins', 'allowed')) {
            $configOrigins = Config::getVar('origins', 'allowed');
            $request_origin = $_SERVER['HTTP_ORIGIN'];
            $allow_origin = null;
            if (in_array('*', $configOrigins)) {
                $allow_origin = '*';
            } else {
                // Case insensitive match for allowed origin.
                foreach ($configOrigins as $origin) {
                    if (strtolower($request_origin) == strtolower($origin)) {
                        $allow_origin = $request_origin;
                    }
                }
            }
            if ($allow_origin != null) {
                $this->addHeader('Access-Control-Allow-Origin', $allow_origin);
            }
        }

        // Ensure we have a response body!
        if ($this->body == NULL) {
            $this->body = '';
        }

        // Modification of original tonic version.
        if (php_sapi_name() != 'cli' && !headers_sent()) {

            if ($this->reason != '') {
                header('HTTP/1.1 ' . $this->code . ' ' . $this->reason);
            } else {
                header('HTTP/1.1 ' . $this->code);
            }
            foreach ($this->headers as $header => $value) {
                header($header.': '.$value);
            }
        }

        if (strtoupper($this->request->method) !== 'HEAD') {
            echo $this->body;
        }
    }

    /**
     * Set response body, and content metadata.
     *
     * @param string $data
     * @param string $contentType
     * @param string $contentLength
     */
    public function setBody($data, $contentType = NULL, $contentLength = NULL) {
        $this->body = $data;

        if ($contentType !== NULL) {
            $this->addHeader('Content-Type', $contentType);
        }

        if ($contentLength !== NULL) {
            $this->addHeader('Content-Length', $contentLength);
        } else {
            $this->addHeader('Content-Length', strlen($data));
        }
    }

}


text:
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.extensions.impl;

import com.intellij.openapi.extensions.DefaultPluginDescriptor;
import com.intellij.openapi.extensions.LoadingOrder;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import org.picocontainer.defaults.DefaultPicoContainer;

import java.io.IOException;
import java.io.StringReader;

import static org.junit.Assert.assertEquals;

/**
 * @author Alexander Kireyev
 */
public class ExtensionComponentAdapterTest {
  @Test
  public void testLoadingOrderReading() {
    assertEquals(LoadingOrder.ANY, createAdapter("<extension/>").getOrder());
    assertEquals(LoadingOrder.FIRST, createAdapter("<extension order=\"FIRST\"/>").getOrder());
    assertEquals(LoadingOrder.LAST, createAdapter("<extension order=\"LAST\"/>").getOrder());
    assertEquals(LoadingOrder.before("test"), createAdapter("<extension order=\"BEFORE test\"/>").getOrder());
    assertEquals(LoadingOrder.after("test"), createAdapter("<extension order=\"AFTER test\"/>").getOrder());
  }

  @Test
  public void testUnknownAttributes() {
    String name = TestExtensionClassOne.class.getName();
    Element element = readElement("<bean implementation=\"123\"/>");
    DefaultPicoContainer container = new DefaultPicoContainer();
    DefaultPluginDescriptor descriptor = new DefaultPluginDescriptor("test");
    new ExtensionComponentAdapter(name, element, container, descriptor, false).getComponentInstance(container);
  }

  private static ExtensionComponentAdapter createAdapter(String text) {
    Element element = readElement(text);
    return new ExtensionComponentAdapter(Object.class.getName(), element, new DefaultPicoContainer(), new DefaultPluginDescriptor(""), false);
  }

  @NotNull
  public static Element readElement(@NotNull String text) {
    try {
      return new SAXBuilder().build(new StringReader(text)).getRootElement();
    }
    catch (JDOMException e) {
      throw new RuntimeException(e);
    }
    catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}


text:
package com.ntsdev.http.routes

import akka.http.scaladsl.server.Directives
import com.danielasfregola.twitter4s.http.unmarshalling.{JsonSupport => Twitter4sJsonSupport}
import com.ntsdev.domain.Person
import com.ntsdev.http.marshalling.JsonSupport
import com.ntsdev.service.PersonService

import scala.concurrent.ExecutionContext

class JsonRoutes(var personService: PersonService)(implicit executionContext: ExecutionContext) extends Directives with Twitter4sJsonSupport with JsonSupport {

  val route = {
    logRequestResult("atlanta-scala-microservice") {
      get {
        pathPrefix("person"){
          val shallowPeople: Iterable[Person] = personService.peopleWithContactsDepthOne
          complete(shallowPeople)
        }
      }
    }
  }
}


text:
using System;
namespace NGin.Core
{
    public interface INGinCore: IDisposable, INGinManager
    {
        TService GetService<TService>();
        TService GetService<TService>( params object[] parameters );
        object GetService( Type serviceType );
        event CoreStateDelegate RunStarted;
        event CoreStateDelegate RunStopped;

        void Run();
        void Stop();
        void WaitForEnd();
        void WaitForEnd( TimeSpan timeout );
    }
}


text:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">

<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="generator" content="Manpage converted by man2html - see http://invisible-island.net/scripts/readme.html#others_scripts">
<TITLE>curs_kernel 3x</TITLE>
<link rev=made href="mailto:bug-ncurses@gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

curs_kernel 3x

curs_kernel(3x)                                         curs_kernel(3x)

NAME

       def_prog_mode, def_shell_mode, reset_prog_mode,
       reset_shell_mode, resetty, savetty, getsyx, setsyx,
       ripoffline, curs_set, napms - low-level curses routines

SYNOPSIS

       #include <curses.h>

       int def_prog_mode(void);
       int def_shell_mode(void);
       int reset_prog_mode(void);
       int reset_shell_mode(void);
       int resetty(void);
       int savetty(void);
       void getsyx(int y, int x);
       void setsyx(int y, int x);
       int ripoffline(int line, int (*init)(WINDOW *, int));
       int curs_set(int visibility);
       int napms(int ms);

DESCRIPTION

       The  following  routines  give low-level access to various
       curses capabilities.  These routines  typically  are  used
       inside library routines.

def_prog_mode, def_shell_mode

       The  def_prog_mode  and  def_shell_mode  routines save the
       current terminal modes as the  "program"  (in  curses)  or
       "shell"   (not  in  curses)  state  for  use  by  the  re-
       set_prog_mode and reset_shell_mode routines.  This is done
       automatically by initscr.  There is one such save area for
       each screen context allocated by newterm().

reset_prog_mode, reset_shell_mode

       The reset_prog_mode and reset_shell_mode routines  restore
       the  terminal  to "program" (in curses) or "shell" (out of
       curses) state.  These are  done  automatically  by  endwin
       and,  after  an  endwin, by doupdate, so they normally are
       not called.

resetty, savetty

       The resetty and savetty  routines  save  and  restore  the
       state  of  the  terminal modes.  savetty saves the current
       state in a buffer and resetty restores the state  to  what
       it was at the last call to savetty.

getsyx

       The  getsyx routine returns the current coordinates of the
       virtual screen cursor in y and x.  If leaveok is currently
       TRUE,  then -1,-1 is returned.  If lines have been removed
       from the top of the screen, using ripoffline, y and x  in-
       clude  these lines; therefore, y and x should be used only
       as arguments for setsyx.

setsyx

       The setsyx routine sets the virtual screen cursor to y, x.
       If y and x are both -1, then leaveok is set.  The two rou-
       tines getsyx and setsyx are designed to be used by  a  li-
       brary  routine,  which manipulates curses windows but does
       not want to change the current position of  the  program's
       cursor.   The library routine would call getsyx at the be-
       ginning, do its manipulation of  its  own  windows,  do  a
       wnoutrefresh  on  its  windows, call setsyx, and then call
       doupdate.

ripoffline

       The ripoffline routine provides access to the same facili-
       ty  that  slk_init  [see  curs_slk(3x)] uses to reduce the
       size of the screen.   ripoffline  must  be  called  before
       initscr or newterm is called, to prepare these initial ac-
       tions:

       o   If line is positive, a line is removed from the top of
           stdscr.

       o   if  line  is negative, a line is removed from the bot-
           tom.

       When the resulting initialization is done inside  initscr,
       the routine init (supplied by the user) is called with two
       arguments:

       o   a window pointer to the one-line window that has  been
           allocated and

       o   an integer with the number of columns in the window.

       Inside  this initialization routine, the integer variables
       LINES and COLS (defined in <curses.h>) are not  guaranteed
       to  be  accurate  and  wrefresh  or  doupdate  must not be
       called.  It is allowable to call wnoutrefresh  during  the
       initialization routine.

       ripoffline  can  be called up to five times before calling
       initscr or newterm.

curs_set

       The curs_set routine sets the cursor state  to  invisible,
       normal, or very visible for visibility equal to 0, 1, or 2
       respectively.  If the terminal supports the visibility re-
       quested, the previous cursor state is returned; otherwise,
       ERR is returned.

napms

       The napms routine is used to sleep for ms milliseconds.

RETURN VALUE

       Except for curs_set, these routines always return OK.

       curs_set returns the previous cursor state, or ERR if  the
       requested visibility is not supported.

       X/Open  defines  no error conditions.  In this implementa-
       tion

       def_prog_mode, def_shell_mode, reset_prog_mode,
       reset_shell_mode
            return  an error if the terminal was not initialized,
            or if the I/O call to obtain  the  terminal  settings
            fails.

       ripoffline
            returns  an error if the maximum number of ripped-off
            lines exceeds the maximum (NRIPS = 5).

NOTES

       Note that getsyx is a macro, so & is not necessary  before
       the variables y and x.

       Older  SVr4  man  pages  warn  that  the  return  value of
       curs_set "is currently  incorrect".   This  implementation
       gets  it  right, but it may be unwise to count on the cor-
       rectness of the return value anywhere else.

       Both ncurses and SVr4 will  call  curs_set  in  endwin  if
       curs_set  has  been  called  to make the cursor other than
       normal, i.e., either invisible or very visible.  There  is
       no  way  for ncurses to determine the initial cursor state
       to restore that.

PORTABILITY

       The functions setsyx and getsyx are not described  in  the
       XSI  Curses standard, Issue 4.  All other functions are as
       described in XSI Curses.

       The SVr4 documentation describes setsyx and getsyx as hav-
       ing  return  type  int.  This  is  misleading, as they are
       macros with no documented semantics for the return value.

SEE ALSO

       curses(3x), curs_initscr(3x),  curs_outopts(3x),  curs_re-
       fresh(3x),   curs_scr_dump(3x),  curs_slk(3x),  curs_vari-
       ables(3x).

                                                        curs_kernel(3x)

NAME

SYNOPSIS

DESCRIPTION

def_prog_mode, def_shell_mode

reset_prog_mode, reset_shell_mode

resetty, savetty

getsyx

setsyx

ripoffline

curs_set

napms

RETURN VALUE

NOTES

PORTABILITY

SEE ALSO


text:
(function(jQuery) {
	jQuery.fn.ImageUploadHelper = function(method){

		function isNumeric(mixed_var) {
			return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
		}

		function isFunction(functionToCheck) {
			var getType = {};
			return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
		}

		function isString(data) {
			return typeof data === 'string';
		}

		if (window.File && window.FileReader && window.FileList && window.Blob) {

		} else {
			console.log('The File APIs are not fully supported in this browser.');
			return;
		}

		var methods = {
			"init": function(opts){
				var selector = this.selector;
				jQuery.each(this,function(key,element){

					if(!element)
					{
						console.log('No DOM element selected.');
						return;
					} /*else if (!this.files) {
						console.log("This browser doesn't seem to support the `files` property of file inputs.");
						return;
					}*/

					var defaults = {
							maxNumberOfFiles: 10,
							higherNumberOfFiles: function(options){},
							fileLoaded: function(file,fr){
								//console.log(fr);
							},
							cssSupport: true,
							dataFor: function(){
								return $('[data-for="'+jQuery(element).attr('name')+'"]');
							},
							fileTemplate: function(file,fr){
								/*if( typeof(jQuery(element).attr('multiple')) == 'undefined')
								{
									var _this = this;
									console.log(_this);
									var img = new Image();
									img.onload = function(){
										//if(isFunction(options.dataFor))
										//	var datafor = options.dataFor.apply(element,[]);
										//else
										//	var datafor = options.dataFor;
										//var fakeImage = jQuery('');
										//fakeImage.css({ position: 'relative', overflow: 'hidden' });
										//fakeImage.append(_this);
										//jQuery(datafor).append(fakeImage);
										if(options.cssSupport)
										{
											jQuery(_this).parent().addClass('img-responsive').addClass('img-thumbnail').removeClass('btn');
											jQuery(_this).parent().css({
												width: img.width+'px',
												height: img.height+'px',
												backgroundImage: "url('"+fr.result+"')"
											});
										}
									};
									img.src = fr.result;
									return '';
								}*/
								return '';
							},
							allFileLoaded: function(files,frs){
							}
						};

					if( typeof(jQuery(element).attr('multiple')) != 'undefined')
					{
						var blobing = function(file,fr){
							options.fileLoaded.apply(element,[file,fr]);
							if(isFunction(options.dataFor))
								var datafor = options.dataFor.apply(element,[]);
							else
								var datafor = options.dataFor;

							if(isFunction(options.fileTemplate))
								var fileTemplate = options.fileTemplate.apply(element,[file,fr]);
							else
								var fileTemplate = options.fileTemplate.replace('{fr.result}',fr.result);
							jQuery(datafor).append(fileTemplate);
						};
						var beforeAppend = function(){
							if(isFunction(options.dataFor))
								var datafor = options.dataFor.apply(element,[]);
							else
								var datafor = options.dataFor;
							jQuery(datafor).empty();
						};
						var options = {};
						var change  = function(){
							if (!this.files[0]) {
								console.log("Please select a file at least!");
							} else {
								beforeAppend.apply(jQuery(selector),[]);
								var count = 0;
								var length = 0;
								var frs = [];
								var files = [];
								if(element.files.length > options.maxNumberOfFiles)
									options.higherNumberOfFiles.apply(jQuery(selector),[options]);
								else
								jQuery.each(element.files, function(key,file)
								{
									length++;
									var fr = new FileReader();
									frs.push(fr);
									files.push(file);
									fr.onload = function(){
										count++;
										blobing.apply(jQuery(selector),[file,fr]);
										if(count == length)
										{
											options.allFileLoaded.apply(jQuery(selector),[files,frs]);
										}
									};
									//function(){
										//console.log(fr.result);
									//};
									//fr.readAsText(file);
									fr.readAsDataURL(file);
								});
							}
						};

						options = element.options = $.extend({},defaults,opts);
						if(options.cssSupport)
						{
							jQuery(element).css({ display: 'block', position: 'absolute', 'font-size': '999px', bottom: 0, right: 0, cursor: jQuery(this).parent().css('cursor') }).fadeTo(0,0);
							jQuery(element).parent().css({ position: 'relative', overflow: 'hidden' });
						}
						jQuery(element).on('change',change);
						jQuery(element).trigger('change');
					}
					else
					{
						var blobing = function(file,fr){
							options.fileLoaded.apply(element,[file,fr]);
							if(isFunction(options.dataFor))
								var datafor = options.dataFor.apply(element,[]);
							else
								var datafor = options.dataFor;

							if(isFunction(options.fileTemplate))
								var fileTemplate = options.fileTemplate.apply(element,[file,fr]);
							else
								var fileTemplate = options.fileTemplate.replace('{fr.result}',fr.result);
							jQuery(datafor).append(fileTemplate);
						};
						var beforeAppend = function(){
							if(isFunction(options.dataFor))
								var datafor = options.dataFor.apply(element,[]);
							else
								var datafor = options.dataFor;
							jQuery(datafor).empty();
						};
						var options = {};
						var change  = function(){
							if (!this.files[0]) {
								console.log("Please select a file at least!");
							} else {
								beforeAppend.apply(jQuery(selector),[]);
								var count = 0;
								var length = 0;
								var frs = [];
								var files = [];
								jQuery(selector).each(function(key,_element){
									var thisInputLength = 0;
									jQuery.each(_element.files, function(key,file)
									{
										thisInputLength++;
										length++;
										var fr = new FileReader();
										frs.push(fr);
										files.push(file);
										fr.onload = function(){
											count++;
											blobing.apply(jQuery(selector),[file,fr]);
											if(count == length)
											{
												options.allFileLoaded.apply(jQuery(selector),[files,frs]);
											}
										};
										//function(){
											//console.log(fr.result);
										//};
										//fr.readAsText(file);
										fr.readAsDataURL(file);
									});
									if(thisInputLength == 0)
									{
										if(options.cssSupport)
											jQuery(element).parent().remove();
										else
											jQuery(element).remove();
									}
								});
								if(options.cssSupport)
								{
									var the = jQuery(selector).first().parent();
									if(options.maxNumberOfFiles > jQuery(selector).length)
									{
										var clone = the.clone(true,true);
										jQuery('input[type="file"]',clone).val('');
										jQuery(selector).first().parent().before(clone);
										//console.log('clone',clone);
										//console.log('origin',jQuery(selector).first().parent());
										//the.hide();
									}
									else if(options.maxNumberOfFiles < jQuery(selector).length)
										options.higherNumberOfFiles.apply(jQuery(selector),[options]);
								}
								else
								{
									var the = jQuery(selector).first();
									if(options.maxNumberOfFiles > jQuery(selector).length)
									{
										var clone = the.clone(true,true);
										jQuery('input[type="file"]',clone).val('');
										jQuery(selector).first().before(clone);
										//console.log('clone',clone);
										//console.log('origin',jQuery(selector).first());
										//the.hide();
									}
									else if(options.maxNumberOfFiles < jQuery(selector).length)
										options.higherNumberOfFiles.apply(jQuery(selector),[options]);
								}
							}
						};

						options = element.options = $.extend({},defaults,opts);
						if(options.cssSupport)
						{
							jQuery(element).css({ display: 'block', position: 'absolute', 'font-size': '999px', bottom: 0, right: 0, cursor: jQuery(this).parent().css('cursor') }).fadeTo(0,0);
							jQuery(element).parent().css({ position: 'relative', overflow: 'hidden' });
						}
						jQuery(element).on('change',change);
						jQuery(element).trigger('change');

					}

				});
			}
		}

		if ( methods[ method ] ) {
				return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ) );
		} else if ( typeof method === "object" || ! method ) {
				return methods.init.apply( this, arguments );
		} else {
				$.error( "jQuery.dialogExtend Error : Method <" + method + "> does not exist" );
		}
	};
})(jQuery);