cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
EugeneB
Level III

Script to select columns from a list in clipboard

Follow up....still problem.  

 

I need to convert a list of strings copied from row values which, when pasted here looks like this

Tcea1 Atp6v1h Oprk1 Rb1cc1 Fam150a

When pasted in the script window it looks like this 

Tcea1

Atp6v1h

Oprk1

Rb1cc1

 

I need code to convert the clipboard contents to this

 

{Tcea1, Atp6v1h, Oprk1, Rb1cc1, Fam150a}

 

and this does not work ....  {"Tcea1, Atp6v1h, Oprk1, Rb1cc1, Fam150a"}

but this does {"Tcea1", "Atp6v1h", "Oprk1", "Rb1cc1", "Fam150a"}

 

so.... how can I alter the Get Clipboard command to generate the proper output?  or alternatively remove the "" in a subseqent line of code?

 

thanks for your help.

 

 

 

Jun 2021

Here is my script (based on help from you all!) which works nicely , in  this case to select columns   "Aasdh,Abca2,Abca7,Abcf1,Abi3"  in a data table.

My new problem:  When I have a large list of column names in my clipboard, I dont' want to have to type or convert to names separate by columns as shown in t script here.  Instead I want the script to use the clipboard directly to select the columns in the data frame.

 

How can one convert the clipboard list into "Aasdh,Abca2,Abca7,Abcf1,Abi3...." directly within the script?

 

thanks!

 

SCRIPT

//with data table where you want to select the columns now open

Names Default To Here( 1 );
dt = currentdatatable();

// Get list of data column names
col_list = dt << Get Column Names( string );


// User specified column names
cc = {Aasdh,Abca2,Abca7,Abcf1,Abi3};

For( i = 1, i <= N Items( cc ), i++,
  If( Contains( col_list, Char( cc[i] ) ),
  Column( dt, Char( cc[i] ) ) << Set Selected( 1 )
  )
);

 

7 REPLIES 7
txnelson
Super User

Re: Script to select columns from a list in clipboard

You can use

myClipboard = Get Clipboard();

to move the list into a memory variable.....in this example, a variable called "myClipboard", and then using JSL, manipulate it as desired

If your clipboard contained the following 

     

Aasdh,Abca2,Abca7,Abcf1,Abi3

You could retrieve it into a JMP list using

myClipboard = words(Get Clipboard(),",");
Jim
EugeneB
Level III

Re: Script to select columns from a list in clipboard

belated ....

My lists are copied into the clipboard from a column in JMP data frame or excel

I need the clipboard contents with e.g. 3 copies  strings, columnQ, columnX, columnB to be converted to this in the script {columnQ, columnX, columnB}.

..... but all the solutions you listed result in "" around the series, and the script does not run.  How to get rid of the "" ??   

 

THANKS

 

myClipboard = Get Clipboard();

/*:

 

"columnQ

columnX

columnB"

//:*/

myClipboard = words (Get Clipboard());

/*:

 

{"columnQ

columnX

columnB"}

//:*/

myClipboard = words(Get Clipboard(),);

/*:

 

{"columnQ

columnX

columnB"}

//:*/

myClipboard = words(Get Clipboard(),",");

/*:

 

{"columnQ

columnX

columnB"}

 

 

 

txnelson
Super User

Re: Script to select columns from a list in clipboard

Get Clipboard() returns everything found in the clipboard as single string.  To get specific values from the returned string one must use the various character handling functions in JMP to get them from the string.

As a note, by default, JMP placed a tab character as a spacer between column values. 

If one opened the sample data table called Big Class, and copied into the paste buffer the first 10 rows for the 1st 3 columns(Name, Sex, Age), the following script would return the name of the individual from the 2nd row copied into the paste buffer.

Names Default To Here( 1 );
myClipboard = Get Clipboard();
theWord = Word( 4, myclipboard, "\!t\!n\!r" );
Show( theWord );

The Word() function returns the nth word from the myclipboard variable, using a Tab, Linefeed and Carriage Return, as the delimiters to look for to determine the word spacing.   \!t is the escape structure that indicates the non printable character for the Tab.

 

From this pattern you should be able to pass through the data and find all of the information you need.

Jim
EugeneB
Level III

Re: Script to select columns from a list in clipboard

Thanks for repeeated efforts to help with this.   However I don't think I am being clear.   

 

When Getclipboard gives me this...

 

 {"Tcea1, Atp6v1h, Oprk1, Rb1cc1, Fam150a"}

 

I need to convert it to  this

{"Tcea1", Atp6v1h", "Oprk1", "Rb1cc1, "Fam150a"} which I prefer because it would make numeric values into strings 

 or into this

 {Tcea1, Atp6v1h, Oprk1, Rb1cc1, Fam150a}   

 

Is there a simple way to script that transformation....?

then the script you provided in June nicely selects all the columns.  Typically my lists have 100s of column labels, so I need to automate.

 

thanks 

 

 

 

 

EugeneB
Level III

Re: Script to select columns from a list in clipboard

I found a Rube Goldberg-esque way to generate the required format .  I will attempt to integrate into a complete script later to share.

he following takes a list in clipboard and converts it to the required format.... e.g. {"Tcea1", Atp6v1h", "Oprk1", "Rb1cc1, "Fam150a"} 

 

 

//here get list from clipboard first .  Here the column names are genes
//COPY columns names from a row in JMP or excel into your clipboard

//PART ONE

// New data table

// Data Table( "TempGeneList" )

New Table( "TempGeneList" );

//MANUALLY paste the list of column names you want to select into first column
// Transpose data table so your list become columns
Data Table( "TempGeneList" ) << Transpose(
    Label( :Column 1 ), 
    Output Table( "Transpose of TempGeneList" )
);

//the open table "Transpose of TempGeneList" should have your list as colmun names
Names Default To Here( 1 );

dt2 = Current Data Table();

//get the column names into a form that works
genelist = dt2 << Get Column Names( string );

//Voila

 

txnelson
Super User

Re: Script to select columns from a list in clipboard

My previous response was intended to show you how to access the item in the clip board.  I assumed from there you would be able to build the list you needed.  Here is a more complete example that takes each item found in the clip board, and adds them to the list called "theList".

So if you copy into the clip board the following

txnelson_0-1632687325181.png

and run the script

Names Default To Here( 1 );
myClipboard = Get Clipboard();
theList ={};
i=1;
while( word(i,myClipboard,"\!t\!n\!r" ) != "",
	insert into(theList,word(i,myClipboard,"\!t\!n\!r" ));
	i++;
);
show(theList);

It creates the JMP list "theList"

theList = {"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM", "JAMES", "ROBERT", "BARBARA", "ALICE"};
Jim
pmroz
Super User

Re: Script to select columns from a list in clipboard

This might be simpler.  Use crlf as a delimiter for the words function.

clipb = get clipboard();
print(clipb);

crlf = hex to char("0D0A");
col_list = words(clipb, crlf);

print(col_list);

I highlighted some names in Big Class and then ran the code.  This is the output from the log window:

"JOE
MICHAEL
DAVID
JUDY
ELIZABETH
LESLIE
CAROL
PATTY"
{"JOE", "MICHAEL", "DAVID", "JUDY", "ELIZABETH", "LESLIE", "CAROL", "PATTY"}