extract and add rotation values to maya Matrix - math

I am trying to understand the basic math of a 4x4 matrix in Maya 3d software, and I can't seem to find anything specific enough to my scenario that I can understand.
I basically have an object with a matrix like this:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
I know that the buttom row represents translations, and the 1 in each row is the scale value.
But... if I rotate the object in X by 30*, then I get a matrix like this:
1 0 0 0
0 0.8 0.5 0
0 -0.5 0.8 0
0 0 0 1
Firstly, how would I go about mathematically calculating the rotation x value from knowing only the matrix?
Secondly, how would I go about calculating the matrix value based on only knowing rotations, translations and scale of a 3d object?

As we talk about the Autodesk Maya, we can use the OpenMaya API:
import maya.cmds as cmds
import maya.api.OpenMaya as om
# An object of interest:
object = "pCube1"
# Get the transform matrix as a list of 16 floats
m_list = cmds.xform(object, query=True, matrix=True)
# Create the MMatrix object
m = om.MMatrix(m_list)
# Get the MTransformationMatrix
mt = om.MTransformationMatrix(m)
# Get the rotations
rot = mt.rotation()
# Rotations in radians (as if rotated in the xyz order):
print rot.x, rot.y, rot.z
# Rotations in degrees:
print om.MAngle(rot.x).asDegrees(), om.MAngle(rot.y).asDegrees(), om.MAngle(rot.z).asDegrees()

Related

How to create undirected (i)graph in R for protein-interaction data with tissue information?

I am new to bioinformatics in general and would really appreciate some help and tips with the project Im working on.
My data of protein-protein interactions is stored in a table (in MySQL) with binary information about tissue-specificity. Now I am trying to create an undirected graph with igraph in R, but could not understand what type of data structure I should use without losing the tissue-information (Adjacency matrix, edge list..?).
Thank you in advance!
The data itself about 200k rows, but here is an example of the structure:
symbol1
symbol2
adipose_tissue
adrenal_gland
amygdala
bone
POT1
PRMT7
0
0
0
0
CNBP
HNRNPAB
1
1
1
1
TRIAP1
BAG3
1
1
1
1
NR5A1
RALY
0
1
0
0
TPI1
CCDC8
1
1
1
1
MRPS22
BARD1
0
0
0
1
TOP2A
CCDC8
0
0
0
1
MYH9
TRIM72
0
0
0
0
ATXN7
TAF12
1
0
0
1
PSEN1
STT3B
1
1
1
1
ATP5F1
TSG101
1
1
1
1
BRCA1
UTP4
0
0
1
1
Bioinformatics apart, this is a question of data-wrangling in igraph. Igraph is capable of building graph-objects from both matrices and lists in many formats, so one should avoid too much pre-conversion. I suggest you build your graph using graph_from_data_frame()
I assume that the data structure described above is relational and therefore basically already an edge-list of relations between proteins uniprot2 and uniprot2. This mockup sample-data would then mimics your data-structure.
data <- data.frame(uniprot1 = c('Q94X','Q95X','Q435','QUUU','0982'),
uniprot2 = c('QUUU','Q94X','Q95X','Q95X','Q94X'),
symbol = c('Symbol A', 'Symbol B', 'Symbol C','Symbol D',' Symbol E'),
adipose_tissue = c(1,0,0,1,1),
bone=c(0,0,0,1,1))
To keep variables other than just the relational edges between vertices, you can either create them alongside your graph-objects, or add and manipulate them later manually.
Attributes naturally belong either to vertices or to edges. A veracity-attribute in your data would be a protein name, size or other characteristic. An edge-attribute would be the relational strength, type, or any other characteristic of the link between two proteins. If your graph would have a veracity called understandable_name_of_protein you'd access it like so:
V(g)$understandable_name_of_protein
Edge-attributes follow the same principle through E(g)$attribute. When you load the example data above, all your edge-attributes should jump right into your graph like this:
# Build an undirected graph using the edges described in `data`
g <- graph_from_data_frame(data, directed=FALSE)
# Check sure that data was correctly imported as edge-attributes
E(g)$bone
# Add the edge-attribut `color` which will be displayed when plotting the graph
E(g)$color <- ifelse(E(g)$bone == 0, 'green','black')
# plot to see the graph with the bone-attribute visible as edge-color
plot(g)

what is Boolean x'.y+x.y' equal to

i am stuck with a boolean expression help me solve what x.y'+x'.y =?
i have exam today and i don't know how do solve this type. And in addition can someone recreate the boolean laws that involve two element instead of one for me? Thank you
There are only two inputs to the expression, so write out a truth table with the values of the inputs and for each term until you get the result.
x y x' y' x'.y x.y' x'.y+x.y'
0 0 1 1 0 ...
0 1 1 0 1 ...
1 1 0 0 0 ...
1 0 0 1 0 ...
When you have done that, look for patterns in the last column. You should then recognise the pattern as being the same as a single operator.
The pattern for the inputs is usually a Gray code so that the output column reflects changes due to only one input changing, which usually can help show up the pattern.
Alternatively, when you have your result, plot it in a grid and spot the pattern that way, e.g. for x+y you'd get
x\y 0 1
0 0 1
0 1 1

torch.Tensor manipulation - Comparing two vectors

I've got two tensor objects repenting vectors:
(0110010),
(0111011)
I would like to compare between the two and create a new tensor vector:
(0110010)
Iterating over them in a loop is very slow, I know there is a solution for this in Matlab so I assume there is one for tensors as well.
To do a logical and operation for tensors containing only 1 and 0 elements you could use the :cmul() member function (element-wise multiplication).
th> torch.Tensor({0,1,1,0,0,1,0}):cmul(torch.Tensor({0,1,1,1,0,1,1}))
0
1
1
0
0
1
0
To compare two tensors element-wise you can use :eq():
th> torch.Tensor({0,1,1,0,0,1,0}):eq(torch.Tensor({0,1,1,1,0,1,1}))
1
1
1
0
1
1
0

Find all vertices in a cycle in a directed graph

I have a directed graph i.e matrix of order n x n.
I need to find all the cycles present in it along with the vertices involved in the cycle.
Here is an example:
A B C D
0 1 1 1
1 0 1 0
1 0 0 0
1 0 0 0
The output should be similar to:
No.of cycles found : 4
A->B->A
A->B->C->A
A->C->A
A->D->A
You should be looking for elementary cycles, in which no vertex (other than begin/end) appears more than once. In that case there are linear time algorithms (linear in nodes + edges). See http://www.cs.tufts.edu/comp/150GA/homeworks/hw1/Johnson%2075.PDF, for example. This comes from the second answer at Finding all cycles in a directed graph, which is better than the first IMHO.

plotting variables of procrustes analysis in r?

I have performed non-metric multidimensional scaling (NMDS) on two data frames, each containing different variables but for the same sites. I am using the vegan package:
> head (ResponsesS3)
R1_S3 R10_S3 R11_S3 R12_S3 R2_S3 R3_S3 R4_S3 R6_S3 R7_S3 R8_S3 R9_S3
4 0 0 0 0 0 1 0 0 0 0 0
5 0 0 0 0 0 1 0 0 0 0 0
7 1 0 0 1 0 0 0 0 0 0 0
12 0 0 0 0 0 1 0 0 0 0 0
14 2 2 0 0 0 0 2 0 0 0 0
16 0 0 1 0 0 0 0 0 0 1 0
> head (EnvtS3)
Dep_Mark Dep_Work Dep_Ext Use_For Use_Fish Use_Ag Div_Prod
4 0.06222836 1.0852315 0.8367309 1.1415929 1.644670 0.1006964 0.566474
5 0.25946808 1.3342266 0.0000000 1.7123894 0.822335 0.0000000 0.283237
7 2.20668862 0.0000000 0.8769881 0.4280973 0.822335 0.5244603 0.849711
12 2.26323697 0.0000000 0.8090991 1.1415929 0.000000 1.4957609 1.416185
14 1.65107675 0.5195901 0.2921132 0.5707965 0.822335 1.7873609 0.849711
16 1.82230225 0.4760163 0.1915366 2.2831858 0.000000 1.6614904 0.849711
> ResponsesS3.mds = metaMDS (ResponsesS3, k =2, trymax = 100)
> EnvtS3.mds = metaMDS (EnvtS3, k =2, trymax = 100)
I fit the results using a procrustean superimposition
> pro.ResponsesS3.EnvtS3.mds <- procrustes(ResponsesS3.mds,EnvtS3.mds)
I am most interested in understanding how the variables from each dataset fit together. I would like to use the plot() function to return a graph of the variables from ResponsesS3 and from EnvtS3, rather than the sites (which is what the plot function returns by default).
Is this possible?
No, this is not possible. The problem you'll find you have is that there will be different numbers of variables in the two datasets which causes the procrustes() method to fail if you try procrustes(..., scores = "species").
Even if you fit with procrustes(..., score = "sites") (the default), who do you propose to draw the plot if we could extract the species information? The current plot joins rows from one matric with the rows of other; this works in the default setting because the datasets are assumed to be measurements on the same locations/sites. But this is not possible with species/variables. More fundamentally, how should we pair up species with environmental variables?
Finally, you are trying to look at how the variables compare yet have used a method that essentially throws this information away once dissimilarities are computed.
I would look at the method of coinertia analysis, of which there is a crude interface in my cocorresp package and a fuller one in the ade4 package. If you find yourself wanting to compare two sets of species data, try cocorrespondence analysis, which cocorresp fits.
Like Gav said, the points must match each other one to one for Procrustes rotation. However, once you have a Procrustes rotation, you can naturally apply it to other matrices with the same number of columns. The number of columns is crucial: If you have 2-dim NMDS, your variables also must be mapped into these 2 dim. Function metaMDS() will get you such column scores corresponding to your ordination of row scores, but I don't know how adequate these are in your case. The easiest way to rotate those scores in vegan is to use predict method with newdata. Continuing with your example:
predict(pro.ResponsesS3.EnvtS3.mds, newdata=scores(EnvtS3.mds, "species"))
This will only rotate your column scores ("species") similarly as is rotated your row scores.
We do not know what you try to achieve, and indeed there may be better ways to achieve your goal (check Gavin's answer for a starter). However, this will do the rotation.

Resources