Vous êtes sur la page 1sur 23

Advanced Use of Properties and

Scripts in TIBCO Spotfire


Herwig Van Marck

Janssen Research & Development


C.R.E.A.Te
Community of Research Excellence & Advanced Technology

Overview
Examples of the use of properties
Trellis Simulation
Using $map and $csearch

Examples of the use of scripts


Using comma separated tag columns
Expand marking
Dynamic list box content

15.02.11

Chi Sox

Tadahito Iguchi

Paul Konerko

Joe Crede

Carl Everett

A.J. Pierzynski

Todd Ho llandsw

Michael Barrett

Jerry Hairston

Derrek Lee

Aramis Ramirez

Manny Ramirez

Johnny Damon

Edgar Renteria

Bill Mueller

Tadahito Iguchi

Paul Konerko

Joe Crede

Carl Everett

A.J. Pierzynski

Todd Ho llandsw

Michael Barrett

Jerry Hairston

Derrek Lee

Aramis Ramirez

Manny Ramirez

Johnny Damon

Edgar Renteria

Bill Mueller

Tadahito Iguchi

Paul Konerko

Joe Crede

Carl Everett

A.J. P ierzynski

Todd Ho llandsw

Michael Barrett

Jerry Hairston

Derrek Lee

Aramis Ramirez

Chi Cubs

Chi Cubs

Boston

Chi Sox

Johnny Damon
Manny Ramirez

Boston

Chi Cubs

Boston

Chi Sox

Chi Cubs

Boston

Bill Mueller
Edgar Renteria

At Bats

Trellis Simulation
Chi Sox
Color by
Team

600
Boston
Chi Cubs
Chi Sox

550

500

450

400

350

300

250

200

Team, Player Name


15.02.11
3

Chi S ox

Tadahito Iguchi

Scott Podsednik

Paul K onerko

Juan Uribe

Joe Crede

Jermaine Dye

Carl Everett

Aaron Rowand

A.J. Pierzynski

Todd Walker

Todd Hollandsworth

At Bats

Neifi Perez

Michael Barrett

Jose Macias

Jerry Hairston

Jeromy Burnitz

Derrek Lee

Corey Patterson

Aramis Ramirez

Select page

Trot Nixon

Manny Ramirez

Kevin Millar

Johnny Damon

Jason Varitek

Chi Cubs

Boston

Number of Teams/page

Edgar Renteria

David Ortiz

Bill Mueller

Trellis Simulation
2

per Player per Team


Legend

600
Team

550
Team

Boston

Chi Sox

Chi Cubs

500

450

400

350

300

250

200

15.02.11
4

Trellis Simulation
Number of Teams/page

Select page

At Bats

per Player per Team

Create document properties


teamsPrPageProp (integer)
selectedPage (integer)
valueProp (column name)

Create Calculated column Page:


Integer((DenseRank([Team])-1)/${teamsPrPageProp}+1)

Custom expression on X-axis:


<if([Page]=${selectedPage},[Team],"") as [Team] NEST if([Page]=$
{selectedPage},[Player Name],"") as [Player Name]>

Custom expression on Yaxis:


if([Page]=${selectedPage},$esc(${valueProp}),null) as $esc(${valueProp})

15.02.11

Using $map and $csearch


*run*

15.02.11

Using $map and $csearch


Text Area

Y-Axis property search:*run*

Create Input Field in text area


Create associated document
property SearchProp

15.02.11

Using $map and $csearch


Use custom expression on Y-axis
$map("sum($esc($csearch([Baseball],"${SearchProp}"))) as
$esc($csearch([Baseball],"${SearchProp}"))",", ")
Search columns:
$csearch([Baseball],"${SearchProp}")

Escape columns:
$esc()

Summarization + renaming of the axis label:


sum() as

Handle multiple columns:


$map("",", ")

15.02.11

Comma separated tags column


Data from a literature search (on next generation
sequencing)
Comma separated tags column (Tags)
Tags
De novo Assembly
Genome Annotation, Derivative technology, Multiple Analysis Steps
Alignment
Alignment
Genome Annotation
QC Analysis

15.02.11

19 columns

Comma separated tags column

Detail on single paper

15.02.11

10

Comma separated tags column


Tag processing
Tags

Get tag values

Mark selected row

Text area for parameters and scripts


Drop-down list for column selection
Document property TagColumn

Create document property TagsList


Via temporary List box (multiple select)
Fill with values with Iron Python script

15.02.11

11

Comma separated tags column


GetTags script:

Script parameters

from System import Array


from Spotfire.Dxp.Data import IndexSet
from Spotfire.Dxp.Data import DataValueCursor
rowCount = Document.ActiveDataTableReference.RowCount
rowsToInclude = IndexSet(rowCount,True)

Name

Type

Value

ColumnName

String

${TagColumn}

ListProperty

String

TagsList

#Create a cursor to the Column we wish to get the values from


cursor1 = DataValueCursor.CreateFormatted(Document.ActiveDataTableReference.Columns[ColumnName])
keys=dict()
#Loop through all rows, retrieve value for specific column, and add value into array
for row in Document.ActiveDataTableReference.GetRows(rowsToInclude,cursor1):
value1 = cursor1.CurrentValue
for tag in value1.split(', '):
keys[tag]=1

Get unique tag values

strArray = Array.CreateInstance(str,len(keys))
idx=0
for key in keys:
strArray[idx] = key
idx=idx+1

Put in Tagslist property

#Set property to array created above


Document.Properties.Item[ListProperty]=strArray

Tags

Get tag values

Mark selected row

15.02.11

12

Comma separated tags column


Custom Expression on Y-axis:
$map("Integer(Sum(if(find("", ${TagsList}, "","",
""&[Tags]&"", "")>0,1,null))) as $esc(${TagsList})",
",")
Search for for tag (caveat: quoting the quotes)
if(find("", ${TagsList}, "","", ""&[Tags]&"", "")>0,1,null)

Summarization + renaming of the axis label


Integer(Sum()) as $esc(${TagsList})

Handle multiple tags


14

14
12

12

12
11

10

9
8

8
7

6
4

4
1

Struc tural V ar iants Detection

Raw Data A nalys is

QC A nalys is

Error Correction

Data representation

Data integration

Targeted Res equenc ing

A lignment

Data s torage

De nov o A s sembly

Derivative technology

SNP/DIP Detec tion

Genome A nnotation

Multiple A nalys is Steps

A lignment/A ssembly V iew ers

15.02.11

0
(Empty)

Genoty pe Calling

Copy Number V ariation

Data volumes

$map("", ",")

13

Comma separated tags column


Selection Problem
because all data is derived from all records

Solution:
horizontal bar chart using cross table
Repeat(""|"",Integer(Sum()))

Use column sorting as selector and Iron Python script


Tag count

Tags

Get tag values

Mark selected row

Data volumes

||||||||||||||(14)

Alignment/Assembly Viewers

||||||||||||(12)

Multiple Analysis Steps

||||||||||||(12)

Genome Annotation

|||||||||||(11)

SNP/DIP Detection

|||||||||(9)

Derivative technology

|||||||||(9)

De novo Assembly

||||||||(8)

Data storage

||||||||(8)

Alignment

|||||||(7)

Targeted Resequencing

||||||(6)

Data integration

||||||(6)

Data representation

||||(4)

Error Correction

||||(4)

QC Analysis

|||(3)

Raw Data Analysis

||(2)

Structural Variants Detection

||(2)

Copy Number Variation

|(1)

Genotype Calling

|(1)

15.02.11

14

Comma separated tags column


MarkSelectedRow script:
from
from
from
from

Spotfire.Dxp.Application.Visuals import VisualContent


Spotfire.Dxp.Data import IndexSet
Spotfire.Dxp.Data import RowSelection
Spotfire.Dxp.Data import DataValueCursor

vc = vis.As[VisualContent]()

Script parameters
Name

Type

Value

vis

Visualization

Tagging>HBar

TagsColumn

String

${TagColumn}

dataTable=vc.Data.DataTableReference
marking=vc.Data.MarkingReference
selectRows = IndexSet(vc.Data.DataTableReference.RowCount, False);
if (vc.SortColumnsCategory):
selectedTag=vc.SortColumnsCategory.ToString()
rowCount = dataTable.RowCount
rowsToInclude = IndexSet(rowCount,True)

Get selected tag

#Create a cursor to the Column we wish to get the values from


cursor1 = DataValueCursor.CreateFormatted(dataTable.Columns[TagsColumn])
#Loop through all rows and check for tag
idx=0
for row in dataTable.GetRows(rowsToInclude,cursor1):
value1 = cursor1.CurrentValue
found=False
for tag in value1.split(', '):
if (tag==selectedTag):
found=True
break
if found:
selectRows[idx]=True
idx=idx+1

Find records with


selected tag

marking.SetSelection(RowSelection(selectRows), dataTable)

Set marking

15.02.11

15

Expand marking

15.02.11

16

Expand marking

15.02.11

17

Expand Marking
Expand marking to all other records with the same value for
a chosen column (e.g. Position)
Solution:
Add a second data table containing the unique values
Define relation between the 2 tables on the chosen column
Marking something in data table 1 changes the marking in data
table 2 due to the relation between the data tables
Re-applying the marking in data table 2 changes the marking in
data table 1 (effectively expanding it)
Iron Python script to re-apply a marking

15.02.11

18

Expand Marking
Script to re-apply a marking:
Script parameters
Name

Type

Value

vis

Visualization

Page>Table

from Spotfire.Dxp.Application.Visuals import VisualContent


vc = vis.As[VisualContent]()

Get data table and marking from visualization

dataTable=vc.Data.DataTableReference
marking=vc.Data.MarkingReference
marking.SetSelection(marking.GetSelection(dataTable),dataTable)

Re-apply marking

15.02.11

19

Dynamic list box content


Multi select list box in a text area
How do you dynamicaly change the contents?
Subset of unique values from a column, selected by marking

Approve
A1BG
A1CF
A2LD1
A2M
A2ML1
A4GALT
A4GNT
AAAS
AACS
AADAC
AADACL2
AADACL3
AADACL4
AADAT
AAGAB
AAK1

Load marked symbols


A2LD1
A2M
A4GALT
AAAS
AADAC
AADACL3
AADACL4
AADAT
AAK1

Cross Table

Selected Gene Symbols Chromosome


AAAS
12q13
AADACL3
1p36.21
(Empty)
Selected Gene Symbols

Select symbols for list

15.02.11

20

Dynamic list box content


Define a tag column (e.g. SelectedGenes)
Create a tag Selected

Create a calculated column (e.g. Selected Gene Symbols)


if([SelectedGenes]="Selected",[Approved Symbol],null)

Fill list box with unique values from [Selected Gene Symbols]
Use Iron Python script to modify tag column

15.02.11

21

Dynamic list box content


Script to set tagValue in tagColumn for marked records
Script parameters
Name

Type

Value

dataTable

DataTable

Data Table

markingName

String

Select Marking

tagColumn

String

SelectedGenes

tagValue

String

Selected

from Spotfire.Dxp.Data import DataManager,TagsColumn,IndexSet,RowSelection


selection=Application.GetService[DataManager]().Markings[markingName].GetSelection(dataTable)
col=dataTable.Columns[tagColumn].As[TagsColumn]()
# remove tag in tagColumn for all rows in dataTable
idx=IndexSet(selection.TotalRowCount,True)
col.Tag("",RowSelection(idx))
# tag marked rows in tagColumn with tagValue
col.Tag(tagValue,selection)

Remove all tags in tagColumn


Set tagValue tag in tagColumn for records
marked in markingName

15.02.11

22

15.02.11

23