0
$\begingroup$

I have some code written here which uses ComponentMeasurements to output some data, specifically the one below:

dnaList = ComponentMeasurements[dnaFragsL, "Length"]
Histogram[dnaList]

The first line of code generates the output

{1 -> 177.7, 2 -> 80.4449, 3 -> 338.173, 4 -> 270.588, 5 -> 379.699, 
 6 -> 93.3377, 7 -> 69.6693, 8 -> 214.073, 9 -> 370.709, 10 -> 81.386,
  11 -> 160.486, 12 -> 90.3487, 13 -> 208.946, 14 -> 138.308, 
 15 -> 86.0753, 16 -> 65.237, 17 -> 65.2137, 18 -> 106.573, 
 19 -> 141.393, 20 -> 129.238, 21 -> 79.7561, 22 -> 60.7805, 
 23 -> 73.7609, 24 -> 86.4439, 25 -> 101.005, 26 -> 120.764, 
 27 -> 229.084, 28 -> 131.506, 29 -> 98.6205, 30 -> 26.1816, 
 31 -> 387.531, 32 -> 179.419, 33 -> 62.0383, 34 -> 60.3329}

which does not appear to be an array or list and cannot be fed into the Histogram function. What transform has to be carried out in order for it to generate usefully formatted output?

The image dnaFragsL is attached below.

test image

$\endgroup$
0

3 Answers 3

3
$\begingroup$

If you want to transform the measures returned by ComponentMeasurements you can do the following Rule replacement:

 lengths = dnaList  /. Rule[a_, b_] -> b
{177.7, 80.4449, 338.173, 270.588, 379.699, 93.3377, 69.6693,
214.073, 370.709, 81.386, 160.486, 90.3487, 208.946, 138.308,
86.0753, 65.237, 65.2137, 106.573, 141.393, 129.238, 79.7561, 
60.7805, 73.7609, 86.4439, 101.005, 120.764, 229.084, 131.506, 
98.6205, 26.1816, 387.531, 179.419, 62.0383, 60.3329}

The function i used here as a shortcut (/.) is called ReplaceAll. Passing the resulting list lengths to Histogram gives you:

Histogram[lengths]

enter image description here

$\endgroup$
4
$\begingroup$

You can extract the lengths:

Histogram[#[[2]] & /@ dnaList]

enter image description here

Apologies, if I have misinterpreted your question.

$\endgroup$
2
  • $\begingroup$ Better performance can be had with dnaList[[All, 2]]; greater readability may be had with Last /@ dnaList (+1 for first answer nevertheless) $\endgroup$
    – Mr.Wizard
    Jul 29, 2013 at 12:18
  • $\begingroup$ Points taken, thank you. $\endgroup$
    – ubpdqn
    Jul 30, 2013 at 2:26
2
$\begingroup$

In version 9 you can use the Suggestion Bar to do this for you:

suggestion bar

The action you're looking for is "apply rules to variables".

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.