I have a simple problem below
f2:{[x;y]
r:sum(x)*sum(y);
r
};
tm:([] pr:(100.01 100.02;100.03 100.04); rv:(15.72 55.64; 16.92 15.17 12.21 34.99))
f2 each [tm`rv][tm`pr]
The result I get is
{[x;y]
r:sum(x)*sum(y);
r
}[(15.72 55.64;16.92 15.17 12.21 34.99)'[(100.01 100.02;100.03 100.04)]]
The result I want is to add tm`rv and add tm`pr and multiply.
tm
pr rv
-------------------------------------
100.01 100.02 15.72 55.64
100.03 100.04 16.92 15.17 12.21 34.99
Hi, you can sum each nested list then do the multiplication:
select result:(sum each pr)*sum each rv from tm
result
--------
14274.14
15863.55
q)
But if you want to use your f2 function:{[x;y] r:sum(x)*sum(y); r }
You should do this:
f2'[tm`rv;tm`pr]
14274.14 15863.55
q)
' apply f2 over pairwise combinations of arguments
Related
I have a data.csv which looks like below having a function name and a dictionary.
function,args
fun1,(`startDate`endDate`sym`rollPerct`expDateThreshold`expDateThresholdExpiry)!(.z.D-5;.z.D;`AAPL;0.8;10;1)
fun2,(`startDate`endDate`sym`rollPerct`expDateThreshold`expDateThresholdExpiry)!(.z.D-5;.z.D;`MSFT`ZAK;0.8;10;1)
fun3,(`startDate`endDate`sym`rollPerct`expDateThreshold`expDateThresholdExpiry)!(.z.D-5;.z.D;`NAFK;0.8;10;1)
And If I read the data
tab:("S*";enlist ",") 0:`$data.csv
Now, I want to iterate all rows from the table like below and call them and save all 3 results to a single table res
fun1 [(`startDate`endDate`sym`rollPerct`expDateThreshold`expDateThresholdExpiry)!(.z.D-5;.z.D;`AAPL;0.8;10;1)]
fun2 [(`startDate`endDate`sym`rollPerct`expDateThreshold`expDateThresholdExpiry)!(.z.D-5;.z.D;`MSFT`ZAK;0.8;10;1)]
fun3 [(`startDate`endDate`sym`rollPerct`expDateThreshold`expDateThresholdExpiry)!(.z.D-5;.z.D;`NAFK;0.8;10;1)]
Code snippet to iterate over f1[args], f2[args] and f3[args]. Combine all 3 results into a single table. I had used loop here, but there should be something better than loop here? let me know if any?
cnt:(count table); //get count of table
ino:0; //initialize out counter to 0
tab::flip (`date`sym`ric!(`date$();`symbol$();`symbol$())); //create a global table so it can hold iteration data
//perform iteration where f1[args],f2[args],f3[args]=tab
while[ino<cnt;
data:exec .[first function;args] from table where i=ino;
upsert[`tab;data];
ino:ino+1
]
//tab now has all the itration data of f1 f2 f3
tab
if your inputs are correctly ordered for all functions, the following simple example should work
q)f1:{x+y+z+2};f2:{x*y*z*22};f3:{x%y%z%42};
q)tab:([]func:`f1`f2`f3;args:`x`y`z!/:3 cut til 9)
q)tab
func args
-----------------
f1 `x`y`z!0 1 2
f2 `x`y`z!3 4 5
f3 `x`y`z!6 7 8
q)update res:func .'get'[args]from tab
func args res
---------------------------
f1 `x`y`z!0 1 2 5
f2 `x`y`z!3 4 5 1320
f3 `x`y`z!6 7 8 0.1632653
NB: if you're loaded args are strings, you'll want to parse these
for example - taking the above again
q)tab:update .Q.s1'[args]from tab
q)tab
func args
-------------------
f1 "`x`y`z!0 1 2"
f2 "`x`y`z!3 4 5"
f3 "`x`y`z!6 7 8"
q)meta tab
c | t f a
----| -----
func| s
args| C
q)tab:update'[reval;parse]'[args]from tab
q)tab
func args
-----------------
f1 `x`y`z!0 1 2
f2 `x`y`z!3 4 5
f3 `x`y`z!6 7 8
q)meta tab
c | t f a
----| -----
func| s
args|
q)update res:func .'get'[args]from tab
func args res
---------------------------
f1 `x`y`z!0 1 2 5
f2 `x`y`z!3 4 5 1320
f3 `x`y`z!6 7 8 0.1632653
reval in the above will try to stop anything dodgy being ran but i would avoid parsing code straight from files where possible
I'm trying to obtain the displacements of a node from an FEA .txt results file using matlab. I want to search for the node (e.g. 5151) and then read the displacements, the problem is the node is mentioned a couple of times before getting to the deformations.
The part of the results I'm interested in looks like this......
N O D E O U T P U T
THE FOLLOWING TABLE IS PRINTED FOR NODES BELONGING TO NODE SET ASSEMBLY_TIP_NODES
NODE FOOT- U1 U2 U3 UR1 UR2 UR3
NOTE
5101 2.6105E-03 -1.1943E-02 6.0023E-03 -8.6770E-02 -1.6432E-02 -1.1048E-02
5102 2.5224E-03 -1.1267E-02 5.6868E-03 -8.6763E-02 -1.6390E-02 -1.0943E-02
5103 2.4340E-03 -1.0589E-02 5.3709E-03 -8.6725E-02 -1.6269E-02 -1.0666E-02
5104 2.3455E-03 -9.9121E-03 5.0549E-03 -8.6542E-02 -1.6052E-02 -1.0267E-02
5105 2.2575E-03 -9.2374E-03 4.7396E-03 -8.6041E-02 -1.5708E-02 -9.7843E-03
5106 2.1710E-03 -8.5682E-03 4.4262E-03 -8.5111E-02 -1.5217E-02 -9.2317E-03
5107 2.0869E-03 -7.9085E-03 4.1164E-03 -8.3688E-02 -1.4585E-02 -8.6334E-03
5108 2.0063E-03 -7.2623E-03 3.8120E-03 -8.1750E-02 -1.3825E-02 -8.0049E-03
5109 1.9299E-03 -6.6336E-03 3.5150E-03 -7.9308E-02 -1.2958E-02 -7.3631E-03
5110 1.8586E-03 -6.0265E-03 3.2271E-03 -7.6400E-02 -1.2011E-02 -6.7206E-03
5111 1.7928E-03 -5.4442E-03 2.9500E-03 -7.3084E-02 -1.1010E-02 -6.0892E-03
5112 1.7329E-03 -4.8897E-03 2.6851E-03 -6.9435E-02 -9.9818E-03 -5.4777E-03
5113 1.6791E-03 -4.3652E-03 2.4334E-03 -6.5533E-02 -8.9528E-03 -4.8933E-03
etc, so what I want to do is search for a unique string ' N O D E O U T P U T' and then search for '5151' and import its displacements into an array.
Example output
nodeDisp = 1.6791E-03 -4.3652E-03 2.4334E-03 -6.5533E-02 -8.9528E-03 -4.8933E-03
I have a table with columns a, b, c. Can I calculate the correlation matrix of cor[a;a], cor[a;b], cor[a;c] using functional form somehow?
?[table; (); 0b; (`aa`ab`ac)!((cor; `a; `a); (cor; `a; `b);(cor; `a; `b));
How can i generate the list of the last argument?
(cor; a;b)
q)show t:([]a:5?1.0;b:5?1.0;c:5?1.0)
a b c
------------------------------
0.389056 0.949975 0.6919531
0.391543 0.439081 0.4707883
0.08123546 0.5759051 0.6346716
0.9367503 0.5919004 0.9672398
0.2782122 0.8481567 0.2306385
q)u cor/:\:u:flip t
| a b c
-| --------------------------------
a| 1 -0.1328262 0.6671159
b| -0.1328262 1 -0.1830702
c| 0.6671159 -0.1830702 1
So manually typed out form:
q)t:([] a:10?10; b:10?10; c:10?10)
q)?[t;();0b;`aa`ab`ac!((cor;`a;`a);(cor;`a;`b);(cor;`a;`c))]
aa ab ac
-----------------------
1 -0.2530506 0.7966834
If you wanted to generate the last argument, assuming you wanted all permutations of first column combined with all columns:
q)a:{(`$raze'[string x])!(cor),/:x}{x[0],/:x}cols t;
q)?[t;();0b;a]
aa ab ac
-----------------------
1 -0.2530506 0.7966834
If you wanted all column permutations:
q)a:{(`$raze'[string x])!(cor),/:x}{x cross x}cols t
q)?[t;();0b;a]
aa ab ac ba bb bc ca cb cc
----------------------------------------------------------------------
1 -0.2530506 0.7966834 -0.2530506 1 -0.268787 0.7966834 -0.268787 1
I can't figure out how to use a variable as a math expression. The following code won't return the expected solution but doesnt throw any errors, instead it will just output the contents of the Q variable again in A.
Q = 7+5=
StringReplace, Q, Q, =,, 1
A := Q
Using %Q% or Q = %Q% doesn't work. And running MsgBox, %A% after it will just return "7+5".
Please help as I'm pretty new to AutoHotKey :)
Check this out:
http://www.autohotkey.com/community/viewtopic.php?t=17058
This should do it though:
Q = 7+5=
StringReplace, Q, Q, =,, 1
StringReplace, Q, Q, +,%A_SPACE%, 1
stringleft, first, Q, 1
stringright, last, Q, 1
x := first + last
MsgBox, %first%, %last%, %x%
I am working on a project(I have to implement it in Perl but I am not good at it) that reads DNA and finds its RNA. Divide that RNA's into triplets to get the equivalent protein name of it. I will explain the steps:
1) Transcribe the following DNA to RNA, then use the genetic code to translate it to a sequence of amino acids
Example:
TCATAATACGTTTTGTATTCGCCAGCGCTTCGGTGT
2) To transcribe the DNA, first substitute each DNA for it’s counterpart (i.e., G for C, C for G, T for A and A for T):
TCATAATACGTTTTGTATTCGCCAGCGCTTCGGTGT
AGTATTATGCAAAACATAAGCGGTCGCGAAGCCACA
Next, remember that the Thymine (T) bases become a Uracil (U). Hence our sequence becomes:
AGUAUUAUGCAAAACAUAAGCGGUCGCGAAGCCACA
Using the genetic code is like that
AGU AUU AUG CAA AAC AUA AGC GGU CGC GAA GCC ACA
then look each triplet (codon) up in the genetic code table. So AGU becomes Serine, which we can write as Ser, or
just S. AUU becomes Isoleucine (Ile), which we write as I. Carrying on in this way, we get:
SIMQNISGREAT
I will give the protein table:
So how can I write that code in Perl? I will edit my question and write the code that what I did.
Try the script below, it accepts input on STDIN (or in file given as parameter) and read it by line. I also presume, that "STOP" in the image attached is some stop state. Hope I read it all well from that picture.
#!/usr/bin/perl
use strict;
use warnings;
my %proteins = qw/
UUU F UUC F UUA L UUG L UCU S UCC S UCA S UCG S UAU Y UAC Y UGU C UGC C UGG W
CUU L CUC L CUA L CUG L CCU P CCC P CCA P CCG P CAU H CAC H CAA Q CAG Q CGU R CGC R CGA R CGG R
AUU I AUC I AUA I AUG M ACU T ACC T ACA T ACG T AAU N AAC N AAA K AAG K AGU S AGC S AGA R AGG R
GUU V GUC V GUA V GUG V GCU A GCC A GCA A GCG A GAU D GAC D GAA E GAG E GGU G GGC G GGA G GGG G
/;
LINE: while (<>) {
chomp;
y/GCTA/CGAU/; # translate (point 1&2 mixed)
foreach my $protein (/(...)/g) {
if (defined $proteins{$protein}) {
print $proteins{$protein};
}
else {
print "Whoops, stop state?\n";
next LINE;
}
}
print "\n"
}