Skip to content

Instantly share code, notes, and snippets.

View imoutsatsos's full-sized avatar

Ioannis K. Moutsatsos imoutsatsos

  • Novartis (ioannis.moutsatsos@novartis.com)
  • Arlington, MA
  • X @ioannismou
View GitHub Profile
@imoutsatsos
imoutsatsos / csvRowFilter.groovy
Last active June 2, 2016 15:52
Assert whether a CSV file row is selected by a query clause. Query is expressed in a special Groovy syntax
/*Helper code for selecting rows from a CSV file that satisfy certain user-defined selection criteria (the query)
The criteria are expressed in a special Groovy Syntax that allows it to be evaluated as a Groovy Map to provide the WHERE CLAUSE components
Author: Ioannis K. Moutsatsos
*/
/*Example Selection Criteria in Groovy Format.
All criteria are used in AND format
Basic format is that of a Groovy map. You have to delimit single quotes and string map values
The map keys are the names of the file columns that will be tested by a selection criterium
The criteria values can be in the format of an List, Range or another Map (see examples and formatting below)
@imoutsatsos
imoutsatsos / ListToTable.groovy
Created August 3, 2016 02:04
Write a table like delimited file from Groovy list
/*writes a table like delimited file from Groovy list
works with both simple lists and lists of lists
author IoannisK. Moutsatsos
since Aug-2-2016
*/
/* list of lists */
//theList=[[1,"LoadData"],[2,"IdentifyPrimaryObjects"],[3,"IdentifySecondaryObjects"],[4,"MaskImage"],[5,"CorrectIlluminationCalculate"],[6,"CorrectIlluminationApply"],[7,"IdentifyPrimaryObjects"],[3,"MaskImage"],[3,"CorrectIlluminationCalculate"],[3,"CorrectIlluminationApply"],[3,"IdentifyPrimaryObjects"]]
//theList=[['ModuleIndex','ModuleName'],[1,"LoadData"],[2,"IdentifyPrimaryObjects"],[3,"IdentifySecondaryObjects"],[4,"MaskImage"],[5,"CorrectIlluminationCalculate"],[6,"CorrectIlluminationApply"],[7,"IdentifyPrimaryObjects"],[3,"MaskImage"],[3,"CorrectIlluminationCalculate"],[3,"CorrectIlluminationApply"],[3,"IdentifyPrimaryObjects"]]
/*a simple list */
theList = ["LoadData", "IdentifyPrimaryObjects", "IdentifySecondaryObjects", "MaskImage", "CorrectIlluminationCalculate", "CorrectIlluminationApply", "IdentifyPrimaryObjects", "MaskIma
@imoutsatsos
imoutsatsos / listInferDataType.groovy
Last active June 25, 2017 01:06
Infer data type of list ietms
/* A groovy example for inferring data types of elements in an ArrayList
* Perhaps useful for when analyzing values to be create column in database
* by IKM-July 29, 2016
*/
a=[2.345, 3.2, 4.1, 2.23]
c=[1,23,33,23,34]
d=['text','read',2,45,'how',10,234.45]
println "a-contains:, ${a.collect{it.getClass().simpleName}.unique()}"
@imoutsatsos
imoutsatsos / copyProjectFiles.groovy
Created May 30, 2017 11:38
Jenkins scriptlet copies project files by reading a list from a CSV table
/*
Required Parameters
vDestination: folder where files are copied
VPropFilePath:CSV file path
vArtifactCol: CSV file column (index-1) where file path value is located
vArtifactPath: null for auto-discovery from full path, or a standard path where file artifacts are found
*/
//collect environment variables that may be useful for path expansion
def env = System.getenv()
def JENKINS_URL=env['JENKINS_URL']
@imoutsatsos
imoutsatsos / addHeaderToHeadelessCsvFiles
Created July 25, 2017 18:30
Groovy script adds a CSV header to headless CSV files in a parent folder
/*
Groovy script adds a CSV header to headless CSV files in a parent folder
CSV files with header are saved as originalName_h.csv
*/
//The CSV header to be added
def headerPath = 'D:/mydata/data/header.csv'
def header = new File(headerPath)
assert header.exists()
def parentPath = 'D:/workspace/MySQLout'
@imoutsatsos
imoutsatsos / numericalCoordinatesFromWellIds.groovy
Last active July 10, 2018 14:27
Map alphanumeric well IDs to numeric row/column coordinates
/*
Wells in assay plates are frequently labelled with alphanumeric identifiers (A04, E11 etc)
Script assign row/columns numbers to alphanumeric Well IDs
Note that the column is returned as a formatted String
*/
rowIds='A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,AA,AB,AC,AD,AE,AF'.tokenize(',')
columnIds=(1..48)
plate=GroovyCollections.combinations(rowIds,columnIds.collect{String.format('%02d',it)})
assert plate.size()==1536
@imoutsatsos
imoutsatsos / qPluginName.groovy
Last active March 16, 2018 19:06
Query Jenkins for Plugin Name
/*
Script example for querying the Jenkins PluginManager for plugin names
Requires the class name of the plugin, typically found in the appropriate step of the configuration file
*/
import jenkins.model.Jenkins;
import hudson.PluginWrapper;
Jenkins instance = Jenkins.getInstance();
uc= instance.getPluginManager().whichPlugin(org.biouno.unochoice.model.ScriptlerScript);
println uc.getLongName()
@imoutsatsos
imoutsatsos / propertiesToCSV.groovy
Last active March 31, 2018 15:39
Creates a CSV Table from a custom format of Java style Properties
/*
Creates a CSV table from properties formatted by the following convention
prefixID.CSV_Column.Value=ObjId01,ObjId02,....,ObjId0n
Semantics of this format are that each object has a unique 'ObjId' and a 'Value' for the column header 'CSV_Column'
You would somehow first group the properties by the identifying prefix
In this example the
property prefixId: 'metadata.plate'
Header CSV_Column: ['fixation','probe','cell_line']
fixation.Value:['PFA','methanol','none']
@imoutsatsos
imoutsatsos / buildStep_unzipMyFile.groovy
Created September 6, 2018 21:14
Uses the Jenkins API to unzip an uploaded archive to the job workspace
import hudson.model.*
// get current thread / Executor
def thr = Thread.currentThread()
// get current build
def build = thr?.executable
// get job 'file-type' parameter named 'My_file
def resolver = build.buildVariableResolver
my_file=resolver.resolve("My_file")
@imoutsatsos
imoutsatsos / AC_IMAGE_GALLERY.groovy
Created October 10, 2018 14:18
Active Choices Reactive Parameter for parametrizing JavaScript from a Jenkins Global Variable