谢谢亚历山大,
我可以使用较小的数据表,但是使用较大的列表(> 1000个条目)时却没有任何响应。这可能是红杉的限制吗?
否则,我认为脚本会非常快地调用数据。
这是我从数据表中调用的〜10个有机体ID条目的一个小修改。
dt3 = Open("N:\Projects\High pH Amylase\ADW_GODperid\Summary data\Joined_data_Screening to FSW.xlsx",
0,
0,
0,
0);
Namespace("JSON") << show contents;
base_url = "http://nzdb.nzcorp.net/organism/all/large" || "?accept=application%2Fjson";
query_columns = {"identifier", "code", "synonym", "from"};
cols = "&cols=" || Concat Items(query_columns, "%2C" );
query_terms = dt3:organism id << get values;
query = "&q=" || Concat Items(query_terms, " OR " );;
url = base_url ||cols || query;
show(url);
dt = JSON:Make Table( open(url, HTML Table(2)) );
close (dt3, nosave);
你好
可能的,但是您必须自己编写脚本,因为还没有预配置的脚本。但是,我只是花一些时间来举例说明。您可能可以弄清楚如何使用它从SEQUOIA获得所需的信息。不要指望它能很快运行,因为有一种不同的方式,但是它需要更多的预配置(总之:将数据湖添加为JMP中的数据源,然后使用SQL查询来获取您将喜欢得到)。
我包含的脚本由一大堆代码组成,这些代码解析来自SEQUOIA的JSON格式的响应,您无需执行任何操作。在下面的几行代码中,向您展示如何查询信息并将其放入JMP表中,然后可以进一步在JMP中进行操作以将其与数据连接起来。
请注意,您需要进行更改纯化样品取决于您在SEQUOIA中搜索的位置/内容。
这是您需要处理的部分代码,以将您感兴趣的数据获取到JMP中:
base_url = "http://nzdb.nzcorp.net/purifiedsample/all/large" || "?accept=application%2Fjson";
query_columns = {"organism_code","identifier", "a280"};
cols = "&cols=" || Concat Items(query_columns, "%2C" );
query_terms = {"U6ESJ","U8GF4"};
query = "&q=" || Concat Items(query_terms, " OR " );;
url = base_url ||cols || query;
show(url);
dt = JSON:Make Table( open(url, HTML Table(2)) ); (以上代码需要一些附加功能,这些附加功能包含在本文所附的jsl脚本中,请下载* .jsl文件以运行示例)
作为参考,下面是完整的脚本:
New Namespace("JSON",
{
Char Escape = Function({c},
Match(c,
"\!"", "\!"",
"b", "\!u0008",
"f", "\!u000C",
"n", "\!u000A",
"r", "\!u000D",
"t", "\!u0009",
c
)
);
,
Unicode Escape = Function( {u},
u = "\!"\!\!u" || u || "\!"";
Parse( u );
);
,
Pattern Name =
"\!"" // leading quotation mark
+ pattest( value = ""; 1) // init string accumulator
+ patrepeat(
(Pat break( "\!\\!"" ) >> temp + Pat Test( value ||= temp; 1; )) // run of characters that are not \ or "
|
("\u"+patlen(4)>>temp+pattest(value ||= JSON:Unicode Escape(temp);1)) // \uXXXX
|
("\"+patlen(1)>>temp+pattest(value ||= JSON:Char Escape(temp);1)) // \", for example...embedded quotation mark
)
+ "\!""; // trailing quotation mark
,
Pattern Number = patspan("0123456789-+eE.") >> temp + pattest(value=num(temp);1);
,
starttime=0;
,
progressTable=0;
,
progress = Function( {p},
If( Is Empty( JSON:progressTable ),
JSON:progressTable = New Table( "JSON Parsing Progress Log", New Column( "Time" ), New Column( "Percent" ) );
JSON:progressTable << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :Time ), Y( :Percent ) ),
Elements(
Points( X, Y, Legend( 1 ), Jitter( 1 ) ),
Line Of Fit(
X,
Y,
Legend( 3 ),
Confidence of Fit( 1 ),
Confidence of Prediction( 0 ),
Degree( "Linear" ),
Equation( 0 ),
Root Mean Square Error( 0 ),
R²( 0 )
)
)
);
);
JSON:progressTable << addrows( 1 );
JSON:progressTable:time = Tick Seconds() - JSON:starttime;
JSON:progressTable:percent = 100 * p;
);
,
PatternParse = patpos(0) + patrepeat(patpos(/* remember how far we parsed for error message */)>>failpos
/* comment out this line for a little more speed */+pattest(if(tickseconds()-lasttime>1,JSON:progress(failpos/totalLen);lasttime=tickseconds();wait(0));1)
+patfence(/* fence off previously parsed text...ain't no going back */)
+( patregex("\s*") // ignore whitespace
| JSON:Pattern Name
| ( ":" + pattest(key=value;1) )
| JSON:Pattern Number
| ("true" + pattest(value = 1;1))
| ("false" + pattest(value = 0;1))
| ("null" + pattest(value = .;1))
| ("[" + pattest(Insert Into( stack, {{}}, 1 );value = Empty();1))
| ("{" + pattest(Insert Into( stack, Associative Array(), 1 );value = Empty();Insert Into( keys, key, 1 );1))
| ("]" + pattest(If( !Is Empty( value ),Insert Into( stack[1], value, 1 /*needs reverse later*/ ));value = stack[1];value=reverse(value);Remove From( stack, 1 );1))
| ("}" + pattest(If( !Is Empty( value ),stack[1][key] = value);value = stack[1];Remove From( stack, 1 );key = keys[1];Remove From( keys, 1 );1))
| ("," + pattest(If( Is List( stack[1] ),Insert Into( stack[1], value, 1 /*needs reverse later*/ ),stack[1][key] = value);value = Empty();1))
)) + patrpos(0);
,
Parse = Function( {json},
{stack = {}, keys = {}, key = "", value = Empty(), temp=0,totalLen = length(json),lasttime = tickseconds(),failpos=0},
JSON:starttime = tickseconds();
JSON:progressTable=empty();
if( !try(patmatch(json,JSON:PatternParse),0), Throw( "unrecognized JSON at " || Char( failpos ) ));
value;
);
,
Append Rows = Function( {dt, start, prefix, a},
{key, value, dc, c, nc, r, delta, added = 0},
If(
Is List( a ),
For( r = 1, r <= Length( a ), r++,
delta = JSON:Append Rows( dt, start + added, prefix, a[r] );
added += delta;
);
// fill empty cells
nc = N Col( dt );
For( c = 1, c <= nc, c++,
dc = Column( dt, c );
value = dc[start];
For( r = start + 1, r <= N Row( dt ), r++,
If( dc[r] == "",
dc[r] = value
)
);
);,
Is Associative Array( a ),
key = a << First;
While( !Is Empty( key ),
value = a[key];
delta = JSON:Append Rows( dt, start, If( prefix == "", key, prefix || "." || key ), value );
added = Max( added, delta );
key = a << Next( key );
);,
// else a literal
If( prefix == "",
prefix = "v"
); // can only happen in a top array of literals
dc = Try( Column( dt, prefix ), dt << New Column( prefix, "Character" ) );
added = 1; // don't count padding
If( N Rows( dt ) < start,
dt << Add Rows( start - N Rows( dt ) )
);
// fill to end in case a previous column was a JSON array
For( r = start, r <= N Rows( dt ), r++,
dc[r] = Char( a )
);
);
added;
);
,
Make Table = Function( {json},
{dt},
If( Is String( json ),
json = JSON:Parse( json )
);
dt = New Table();
dt << Begin Data Update();
JSON:Append Rows( dt, N Rows( dt ) + 1, "", json );
dt << End Data Update();
dt;
);
}); // end namespace
Delete Globals();
Namespace("JSON") << show contents;
base_url = "http://nzdb.nzcorp.net/purifiedsample/all/large" || "?accept=application%2Fjson";
query_columns = {"organism_code","identifier", "a280"};
cols = "&cols=" || Concat Items(query_columns, "%2C" );
query_terms = {"U6ESJ","U8GF4"};
query = "&q=" || Concat Items(query_terms, " OR " );;
url = base_url ||cols || query;
show(url);
dt = JSON:Make Table( open(url, HTML Table(2)) );