Unsupervised Learning and NGS

This lab will walk you through some examples of unsupervised learning in NGS.

In [1]:
library(golubEsets)
data(Golub_Merge)
Loading required package: Biobase
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: ‘BiocGenerics’

The following objects are masked from ‘package:parallel’:

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from ‘package:stats’:

    IQR, mad, xtabs

The following objects are masked from ‘package:base’:

    anyDuplicated, append, as.data.frame, as.vector, cbind, colnames,
    do.call, duplicated, eval, evalq, Filter, Find, get, grep, grepl,
    intersect, is.unsorted, lapply, lengths, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unlist, unsplit

Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

MDS/PCA

We have loaded the Golub_Merge data set that was used in this morning’s lecture. It is a pretty complex data type used by Bioconductor.

In [2]:
class(Golub_Merge)
head(Golub_Merge)
summary(Golub_Merge)

Out[2]:
'ExpressionSet'
Out[2]:
ExpressionSet (storageMode: lockedEnvironment)
assayData: 1 features, 72 samples
  element names: exprs
protocolData: none
phenoData
  sampleNames: 39 40 ... 33 (72 total)
  varLabels: Samples ALL.AML ... Source (11 total)
  varMetadata: labelDescription
featureData: none
experimentData: use 'experimentData(object)'
  pubMedIds: 10521349
Annotation: hu6800
Out[2]:
Length         Class          Mode
            1 ExpressionSet            S4
In [3]:
#Fortunately, bioconductor has a function to extract the expression data:

Golub.expression.data=exprs(Golub_Merge)
head(Golub.expression.data)
dim(Golub.expression.data)

Out[3]:
3940424748494143444535363738282930313233
AFFX-BioB-5_at-342-87 22 -243-130-256-62 86 -146-1877 -213-25 -72 -4 15 -318-32 -124-135
AFFX-BioB-M_at-200-248-153-218-177-249-23 -36 -74 -187-100-252-20 -139-116-114-192-49 -79 -186
AFFX-BioB-3_at41 262 17 -163-28 -410-7 -141170 312 -57 136 124 -1 -1252 -95 49 -37 -70
AFFX-BioC-5_at32829527618226624 142252174142132318325392241193312230330337
AFFX-BioC-3_at-224-226-211-289-170-535-233-201-32 114 -377-209-396-324-191-51 -139-367-188-407
AFFX-BioDn-5_at-427-493-250-268-326-810-284-384-318-148-478-557-464-510-411-155-344-508-423-566
Out[3]:
  1. 7129
  2. 72
In [4]:
# Now, we compute the distance matrix:

Golub.distance.matrix=dist(t(Golub.expression.data))

# We used 't' to transpose the matrix. This is just because dist works on rows and we want distance on columns.

as.matrix(Golub.distance.matrix)

dim(as.matrix(Golub.distance.matrix))

Out[4]:
3940424748494143444535363738282930313233
390 101530.75134165 94405.0427042963115681.471662492116666.76277757993189.9424777159101409.857528743117607.80304894786952.113545330297854.9785856601117779.650470699136031.239191592128620.550613034119218.084769048109230.616353658118539.701636203129537.9602356 105918.973493893108391.366247501121993.463816714
40101530.75134165 0 89502.288428844198459.655006505192980.406081066479182.927964303 81381.9940773142109351.49453025387252.808401793 88662.660190183891413.8671592007129683.258726792114292.294867152107131.46133606190504.105006347690631.1349923414109795.07856001684080.524427479688449.7392703902100042.754050456
4294405.042704296389502.28842884410 106954.73825876188800.742446220691730.070876458 91400.2229975398102774.80301124490296.866745197890580.0811105841113191.21683682 120374.43284186297251.011069294388294.744418906485095.287031656590383.4030339641106316.88261043 96237.059556077594266.572097430295023.7579976713
47115681.47166249298459.6550065051106954.7382587610 115169.014396234109182.77543184293290.2490617321105747.54544669197237.772125856597784.680027088176272.8337286612138114.10801942 125885.089331501121789.679324646110847.20327098998573.1509286378130349.399553661103235.654112327111531.040078536127448.219006779
48116666.76277757992980.406081066488800.7424462206115169.0143962340 96797.566302051292101.8278265964124344.70156383898684.884024859788248.9366564833124334.479690873129861.00468963 112328.335663803102728.6884322 82271.004296775299771.377684183599908.618361981294718.846577647990727.6477155668104320.326796842
4993189.942477715979182.927964303 91730.070876458 109182.77543184296797.56630205120 83416.5873852437115825.70356790489241.891054593992708.7901819455104864.125047606125927.362034627112632.708113585105694.07608281690800.8308772558103478.898269164113053.02247618283822.009335257585829.852883481 100606.532277979
41101409.85752874381381.994077314291400.222997539893290.249061732192101.827826596483416.58738524370 96494.156890456376495.714180599777813.447860893697652.2335689256133363.211951422111403.19593261299165.281918623190331.993064473 77039.4635235734112335.67776089779434.856593311791030.549064586 110556.010537646
43117607.803048947109351.494530253102774.803011244105747.545446691124344.701563838115825.70356790496494.15689045630 107846.317442924114440.595900231110525.995272605144945.732224167130253.294829728117571.748715412122765.185867167104096.191227153139022.393634982115532.774510093119322.482630056120064.588101571
4486952.113545330287252.808401793 90296.866745197897237.772125856598684.884024859789241.891054593976495.7141805997107846.3174429240 73557.527405426 101880.854045301130697.111636027119685.714703134112801.23876979499492.930779025794102.1585831058119220.50960300487250.9331984478100756.936431196117482.216407421
4597854.978585660188662.660190183890580.081110584197784.680027088188248.936656483392708.790181945577813.4478608936114440.59590023173557.527405426 0 103923.933658229131771.386780287112896.807040766102245.01843121782643.276949791982259.8661802947106670.77238869189961.29273193 91779.1921025676109075.024666511
4692051.884836759389667.388832283990853.567106635993137.5871708088103778.04577558897774.985139349486164.8348225655108309.93454896 60701.528069728267341.840366892391772.1338370205131851.136240838122629.851618601113902.08218465598956.689814281995964.4094443351119740.40460930594535.5741929989100760.758279203117334.827498062
7094474.129247111990543.041505131798962.528853096784884.5253329486106380.76342083782446.671006172271787.8693721997102140.09215288675369.685199024273550.320604331878297.3535184938131345.050675692116642.178713363105495.37244353493138.890212413488338.7688447151117137.05262213181481.347000402589789.6259486585115285.709014604
7191210.449231434 75800.996002691276012.2278255282102929.63288091585124.872557907587899.048845820978620.6871949107111293.89755507784107.791119491477705.6944052365104607.345956199121683.652973602102919.91202386492218.727875632774663.241183329383278.0234095406101235.99808862582823.860807137 78003.786574755594976.6624966365
7285805.531937049475909.417353843572368.397432857485522.106446228378803.389406801583746.599584699673045.5381320447106398.91801611575438.371701674575249.089303459387490.7528828047118659.364244884104653.92195708794655.311826648275133.796190529383681.253940174799689.559197540881692.154855897977858.992993744898954.6254654122
68113371.00652724294525.091309133486831.7762745874106406.65430789672720.88323171 93627.370261051379041.1383837556118776.31127880792909.620992661581663.7217924826114034.96953128 116602.289973225106996.968400979105919.58419008378062.971785604 91675.307149744588044.396829099882559.150316606383379.4356541228101970.751968395
69114328.27075575 93648.655334713781837.8932280151116631.87139028560917.928797686595780.401382537586820.861133716 120450.05646325 95714.8069005 82387.9940646694124820.357854799120591.500098473106033.822424734100949.55477861275680.017461678794248.511372859493849.695140687689553.645408771683392.743443299795354.1322125056
67104923.77626162795253.664333714785413.631341841597688.8063341957101947.61344926195155.965288572490714.1880468541113487.21120461194864.515847602495265.8546017407103465.554616017114463.166228268108825.966519944103737.01646471287475.644758984295459.0105490309103849.95781896188200.177941997483420.126036826498790.3822191209
55111413.43271347597525.7608275885106238.20698317586992.5883107291120793.82521470299316.836488079970971.424016994386383.798151042290214.100810239295888.601225588882203.8903094008136278.633640788126178.725120363114127.608566026109515.78284430190223.3165151891127565.10835255989019.2765472737108157.201692721120731.36322845
56108328.44241472398873.494466414 113378.45319989283151.6434594049125261.308076357105717.13700720493574.855233657794646.256777539894726.3140209731101458.69113092368800.5136972101146430.36153749 139515.331716625129760.954235086118854.082416213107286.030488596139303.208017619107856.229500201115581.606456218130999.417517789
59131576.809753847129513.068541364132666.329650744110509.423521255147825.245915574138870.961874684131165.931007255111627.811986978117380.340002063129771.774007293111820.59058152 156134.184171821161512.470227534161294.097706643147646.977646005138725.27630897 157790.703880172137376.70195852 143520.3871929 154930.491379199
52146292.3142137 114630.412605033124510.074323325137416.976200177118992.801652033122808.208646654108944.69472168 137810.530620849127975.314986915118160.595157607137413.985951212122719.62710178 111474.381200346120673.798291095115007.101993746101321.694123223102290.66766817 103982.128281739109921.549356803114675.426835918
53125260.795750306107918.301617474104758.98736624 123460.821874796110098.627543671105379.23237052 110035.813915289133547.878770125119231.604300202113690.045263427119931.670942249102833.58086734184030.4486242933101116.09191419587274.221113682895270.353877793583002.474288421191028.099760458689059.168977708390762.7430061476
51119563.021532579100986.85828364 108365.66591868592753.5421210425122200.837415298106407.59896266896716.9950318971113059.110990667106451.981954307100396.41731655679249.2852144421116907.729616138100996.68666842598948.652815488190167.952516401377172.8046658925107972.89778458382243.319339627891287.371804647898840.1926647252
50111571.33359873491490.727010992896750.9254167628117469.56737385296909.769528154497395.108542472595800.3486580294128645.17912848598890.553123137191703.2451715859111109.11421661192347.280149444678498.299618526890208.975357222663298.629937779983625.720618718770314.784156676565831.912177909663570.732526847677662.2533216749
54121443.978562134105489.585670814110185.626381121106679.414766861115078.243538907104694.66334059289456.525066649 115485.592629557104769.525803069109149.760984621119726.623246461122526.566307067110404.763099243117380.510405263108548.03055790694719.3592619798111749.68112258886262.359178265 106376.698454126115328.910482151
57123630.179992589103912.49746301 112490.833239869109090.610086295127041.121067157109797.54085588684165.9510788062112265.522975667107564.128188723104052.858274052110889.012981449137595.572657699118254.61040061 109267.92150032 112096.122172 78006.4429582583125060.53090004193531.2583845636113456.948557592118941.324126647
58130139.752835173136763.453846413138157.175188262113752.452439497161925.149488892137183.42650991 141270.489749275128731.630052602125774.597641972140812.557280947108790.033969109141391.508889325155024.720170688160183.709564987147040.885460473144644.655303955150611.714411595126887.142382512136219.897214027145257.842769332
60147424.874142731133248.156647662138021.465982651121755.067820604148109.369490927136291.791620039122187.428682332111913.554657155127028.786241544132320.025151146123754.202130675151227.879744444144742.549936085144116.166692013139599.843269969117028.569187186144057.702820779119207.707301164135742.819990598140293.53858963
61101303.33252169 99757.2813182075102612.76668134499438.4519388752119574.99009826496988.601263241299894.5837971209119739.586186023101478.537622494102277.11533867287634.902413365 122285.724841455118976.683270295113977.46017524799096.3693633627107588.439109414111973.78164552686358.421419106594630.516626509 108523.205527666
65102585.49644077483294.325977223789829.0354840794108657.01922103396223.016035665886370.068629126474878.0787947981112490.57714315592767.680762213781078.7661351602107010.646764703109499.22754978792998.241951125188360.146310426673962.761218061672852.795059626991265.474216704871065.673359224678902.049067182 88887.5228926985
9139013.57634778 123645.035472517118097.479020511143624.60884193998682.762142129 112345.758531419108407.497651223150710.661105975123176.488247555120222.489747135146699.292227331136910.169509062119976.1176193 113378.21261159599862.6473712769114983.06039152 112489.181057558103231.297439294102728.343002309117727.734425665
10114732.524590894102559.62979164998142.2834816879118659.65732716497300.346823636896826.122549650882671.5580898292123845.50567138199354.759226722596318.7495194991119183.931081333129445.675319804110752.57634475195866.208608664689345.549693311592008.3159774159106150.65276765884555.544957146493449.8417334133107902.519307938
11121155.11772104498899.728017826297775.9916646208113198.67874670691682.738588024395858.370072727682409.3088916537125961.36071033899511.602228081995037.5594067945108658.080468044131003.997091692109379.75971814991299.469198895183791.141996036886854.1962947099105866.32111299682347.471084423787292.0091703702105676.950571068
1296022.304851529272476.288446636183746.680405852597316.591612119395422.626079981782230.947945405667067.0148359087103177.68292126 76610.144125957670512.486986348793769.594688257 120983.80337466799564.758639791891220.062601381780721.818512716972340.6742089124104126.75164913270954.487123789483955.968519218595691.0556374001
1395335.683870206776779.533737839372302.153543307498117.363330860154920.158484840585930.631953919779471.3575258407113908.06738330779588.327517293679768.78317362 109297.781477942120437.389439493110355.858698123106036.11174972480702.613167108894790.975714990999387.802445773 86223.074782798186036.6400320236101502.044605023
14122539.06285752386400.319108207 96436.0401613422104820.95284817885607.402653041689686.83212713 84886.1335672676121679.45173282198642.514840204790796.5119043678102658.203992667125305.50865784 106099.91290288696654.025875801 79983.957547748388583.7985638457101097.77834354281528.471946921778067.590721118199656.2550169331
15112437.51293496391468.720341983693265.2567733559119314.07379265962914.016991446388941.476904760274370.1613350408125023.73228711490151.458729185388724.6068630343127660.461647293126591.578546916105914.150711791104033.87419970581236.660049512193884.142244577299821.020677009787236.943040205284792.7639129661106186.268241237
16104436.34589547878686.045738745889565.086400896297353.786860090972216.563757908174486.519740151662357.9159048793110010.66010164785278.253933813680303.699827592 100019.98634773 129990.448695279107276.62773409794293.050761972980907.822236172 82033.1470687307102852.53111129577027.574062799178746.5958692819102714.005335202
17133954.967388298110465.27246153 109687.208762007122182.11849530289196.5011141132105574.175417097110887.678531025141384.719634054119712.104517463111443.533755889126160.479814401127940.828072981119079.098056712114987.65532873591755.0827093519114039.075382081107114.109556118101300.27584365290414.9356301269110954.542971435
18101119.27648574282748.265123807992728.4260353857105687.62362263698133.867324181289509.992872304576131.1428720205117148.76817534279813.603370603487630.3912863568115164.659483715124361.384629635103462.47635254 103085.23569842689821.712675722287948.3983992887108145.65915930285409.105562580495232.4906006348105375.902012747
19100086.19532183264888.859228684279378.565696288688448.291922456 76186.583418604680035.850910701366720.9469507141100193.30016523182723.168266211979327.069427781197163.7244603149131099.77723856 103331.21856438291342.050338275279793.841786193 79775.7938725777106041.23985506882937.344833313884740.384062146 98734.3685349737
20151359.742871082136915.485639865126484.84321056 153195.37504115586549.3382470369132540.436663684127927.577019187159623.857627862140017.593751643131565.102683044164602.736310792156631.734192021137475.997774157132309.087730208114711.362606326139102.853967846128396.675837032133710.654377278123043.548262394133408.831326865
21148725.958558014118197.2836363 129459.554297858131772.938735539112888.674356642123780.816663973116439.828027183146233.070462874137791.601663527126421.048805173131572.433883394170422.750860911146724.83903893 130413.308343129122947.558194541119490.790343859143446.055445941133460.273328807131148.811553899140269.916543071
2297039.176408294 85374.030852478888230.050413677197569.3346190287100402.49181668788284.995910970186621.9132783385116733.54487035882845.478440286684413.741144436992753.000032344 131082.47946236 113553.80712243997738.723881581387607.118757553 89204.6454059429114030.68416878 89525.765107035 94743.839604483 107061.308818826
23112395.281942793102193.264499183110792.523994176115054.574906868118659.45373209892951.238485562982646.3679601227116416.812071968100640.332307679109051.501580675104993.622311072145138.914130567125928.893495496107770.582929666109765.968988571100340.875544316132280.91654883695238.0399367816105492.14587826 124174.843881521
24104472.19490850275163.953801007687618.1065590897105327.80030457367916.807757726778223.068528407961829.0135858563114773.64850435 91263.971450951 83036.099059385 106372.340568402125763.465986748104563.05822325692216.661113922473601.005726824185734.674997926 96824.959845073 78036.883170716175527.411964133997411.3731398957
25100455.75441456884006.022611477180387.5345249498106164.40553688484161.407141278286496.654097138487279.4096737598111757.89128737292620.478173026168795.894753975 111773.925921925122262.46444841596529.427279975183103.313862926170099.510283596184342.7388990896101158.01370628 89012.678439647 83513.562706904188594.94136236
2696423.802502286876825.365765481482523.968572772994425.339072729874122.927357195 77243.868365068374618.7847059975113683.02296737278641.472729088768664.176926545998846.3521734616124776.205227599111162.027226027102549.71055541877292.003661439788215.8576050814102767.34016700187414.694559896581665.2573987249103419.008354364
27100889.01969986675352.358582860694413.502275892796053.851146114998867.657375908362402.681232459973547.6111508729108581.91361364 90374.519085857487919.182104930983929.1832618428135903.819850658114696.63340307897311.831808881390015.174315223188584.5657662778116250.63384773482779.243328264489867.6872685617104652.760364933
34116180.33230715187656.892775183496869.941999569798685.652964349493928.620686135990219.120135368284797.7828542704122562.601804139104474.79091627888797.920161454296047.1122314461109823.53723587785722.956826045186804.780450157268493.069050817177836.154189425483969.281591543972144.250436192172573.309832196688704.5455486921
35117779.65047069991413.8671592007113191.21683682 76272.8337286612124334.479690873104864.12504760697652.2335689256110525.995272605101880.854045301103923.9336582290 142114.412544963131936.891167709118725.963179921110432.546941561100834.189494437130860.75436508896707.7814500984107177.240625051123061.562280836
36136031.239191592129683.258726792120374.432841862138114.10801942 129861.00468963 125927.362034627133363.211951422144945.732224167130697.111636027131771.386780287142114.4125449630 90073.2351256465129402.191140645104821.708185852125556.40914744386763.6260998813105636.157985796102278.61778983992275.5335503404
37128620.550613034114292.29486715297251.0110692943125885.089331501112328.335663803112632.708113585111403.195932612130253.294829728119685.714703134112896.807040766131936.89116770990073.23512564650 86477.795265605682499.947981801893191.623507695285492.381356469494378.010786411590187.413584158276670.6436127935
38119218.084769048107131.46133606188294.7444189064121789.679324646102728.6884322 105694.07608281699165.2819186231117571.748715412112801.238769794102245.018431217118725.963179921129402.19114064586477.79526560560 79367.705264799 81027.8421655174107960.40503814393848.731403253493607.467175434287276.1244212872
28109230.61635365890504.105006347685095.2870316565110847.20327098982271.004296775290800.830877255890331.993064473 122765.18586716799492.930779025782643.2769497919110432.546941561104821.70818585282499.947981801879367.705264799 0 82274.160700672 84411.867500962277753.787734103362455.359753987570333.3497496031
29118539.70163620390631.134992341490383.403033964198573.150928637899771.3776841835103478.89826916477039.4635235734104096.19122715394102.158583105882259.8661802947100834.189494437125556.40914744393191.623507695281027.842165517482274.160700672 0 98261.851743186780665.256473899690737.260665065397952.7865453556
30129537.9602356 109795.078560016106316.88261043 130349.39955366199908.6183619812113053.022476182112335.677760897139022.393634982119220.509603004106670.772388691130860.75436508886763.626099881385492.3813564694107960.40503814384411.867500962298261.85174318670 85488.210017522385221.709118041 89968.411289741
31105918.97349389384080.524427479696237.0595560775103235.65411232794718.846577647983822.009335257579434.8565933117115532.77451009387250.933198447889961.29273193 96707.7814500984105636.15798579694378.010786411593848.731403253477753.787734103380665.256473899685488.21001752230 67921.844520007 89268.4855030038
32108391.36624750188449.739270390294266.5720974302111531.04007853690727.647715566885829.852883481 91030.549064586 119322.482630056100756.93643119691779.1921025676107177.240625051102278.61778983990187.413584158293607.467175434262455.359753987590737.260665065385221.709118041 67921.844520007 0 78707.6214289315
33121993.463816714100042.75405045695023.7579976713127448.219006779104320.326796842100606.532277979110556.010537646120064.588101571117482.216407421109075.024666511123061.56228083692275.533550340476670.643612793587276.124421287270333.349749603197952.786545355689968.411289741 89268.485503003878707.62142893150
Out[4]:
  1. 72
  2. 72
In [5]:
# cmdscale takes the distance matrix and produces a 72x2 matrix,
#    while preserving the distances between the 72 subjects.

MDS=cmdscale(Golub.distance.matrix)
as.matrix(dist(MDS))[,1:3]

Out[5]:
394042
390 16038.243443918629333.9767138976
4016038.24344391860 13605.9705171535
4229333.976713897613605.97051715350
4723552.942383675539417.412169362152201.8324270926
4864453.984993395649578.213370278840471.7633405931
4923270.23851114877549.203655317338813.71057559277
4118897.468525797612677.086758664722203.3989837184
4324877.927519687939980.534524087352022.3289901934
4411608.836589873219495.187489319632620.364496308
4521986.180776137 12334.768929369119276.3804044188
4612353.197441228127480.575242166341065.2781010112
7011567.233848545825791.26659 39396.0382737991
7132141.624437690116404.84231034258766.06274749528
7221340.21310005148112.7706234778414064.7548887292
6846960.488117714 30967.841193979319043.3116656109
6960749.412670276344960.977422993333626.7933561275
6723261.040174396313495.340631858913501.6078622663
5528240.253815718743921.796204093156440.5931774652
5643148.724666914359156.897035825972449.6131464191
5960222.261399839575936.396607841288284.3689607091
5268650.757288352856900.812650235145852.5701350388
5366068.753728533855304.867970462645202.5765837667
5134445.442312861239368.209084302944407.9441518336
5061453.661678579 50071.025612709339578.0327057698
5438451.916365950734484.938640651932855.4111082329
5722336.961284075226702.353115392533277.0791621479
5878923.951411839590817.418490582299201.3293937777
6047008.886096991258032.465207692666401.4950917156
6131936.161808978838859.938899306 45389.6195458329
6541662.856109954 30493.639778679 21729.9704590229
984087.769639034768371.594556194356914.274729172
1043710.161748848628192.592946172718740.4977464523
1147169.600766167132728.466749713425695.9432660911
1215850.42552603532929.8990881044813527.1845868817
1338671.042277634523960.290917186717704.451396332
1442313.08972269 26675.200084795116940.5991114831
1563945.965204139548678.772678135738722.0035208157
1639902.322589974826454.031869601922482.6239271085
1760941.432262875444903.209549870132095.0352657368
1828732.089068402412930.6532369879806.15210698752
1927388.720098915814671.521087550216341.8068731787
2098883.036666297183615.341777309973062.1020631234
2152623.723702172 41433.732781224938914.2628467944
2216569.075660765714722.649518132625846.3448111743
2321246.994613296919170.840593601228929.5176668179
2449496.967631307834589.970934422726278.4788852099
2538157.821157286522204.469778679111306.9727314499
2630319.854665535817702.386386065318000.4687557743
2714045.361414225514890.926907063527010.6740378817
3444953.250377016831688.225513120620194.2070803233
3532381.164058553148259.476595258560995.7334108935
3696731.941222466889595.742132260381809.3499966411
3779560.163908188868649.063604238358065.0319637561
3846883.788182610931260.944255886517656.2585875449
2855168.9428012 39794.515299522126215.2530753636
2925746.277934528 13666.881386056310084.299011982
3082071.025867796 69898.039315770158247.5862369418
3137452.564965451 27353.925976757620502.1114293489
3250914.929709389737305.236361112 25121.432732103
3369612.214125771458251.048453857347514.468595391
In [6]:
# Now, we just plot the result.

plot(MDS,col=c(2,4)[ pData(Golub_Merge)[["ALL.AML"]]],pch=19,type="n",xlab="",ylab="")
text(MDS,as.character(pData(Golub_Merge)[["ALL.AML"]]),col=c(2,4)[pData(Golub_Merge)[["ALL.AML"]]])

# We observe the clustering of AML patients together and ALL patients together.

Heat Map

We will now generate the ‘noisy’ heatmap from this morning’s lecture. We will generate data with no correspondence between gene expression and group membership.

In [7]:
# Simulate noisy HM
# load the necessary libraries

library(pheatmap)
library(genefilter)




Attaching package: ‘genefilter’

The following object is masked from ‘package:base’:

    anyNA

In [8]:
# n = number of members of each group, m = number of genes, alpha = significance level
# The data simulation is almost exactly the same as the noise simulation from the supervised learning lab

simulate.noise.heatmap=function(n,m,alpha)
  {
    # Simulate Expression Matrix

    EXPRS=matrix(rnorm(2*n*m),m,2*n) # Just randomly chosen, normally distributed values (N(0,1))

    rownames(EXPRS)=paste("Gene",1:m,sep="")
    colnames(EXPRS)=paste("patient id",1:(2*n),sep="")

    # Assign first n patients to group 1, second n patients to group 2
    grp=factor(rep(0:1,c(n,n)))

    # Get the two sample t-statistics
    # run rowttests on the expression values and extract the p-values for each gene
    pvals=rowttests(EXPRS, grp)$p.value


    #Choose the genes that have p-values smaller than significance level
    topgenes=which(pvals<alpha)
    EXPRS=EXPRS[topgenes,]

    # Just annotate which group each patient is in
    annodat=data.frame(Condition=ifelse(grp==0,"N","Y"),row.names=colnames(EXPRS))


    # draw heatmap
    pheatmap(EXPRS,
             border_color =NA,
             show_rownames = FALSE,
             show_colnames=FALSE,
             annotation_col=annodat,
             color=colorRampPalette(c("red3", "black", "green3"))(50),
             annotation_colors=list(Condition=c(Y="blue",N="yellow")))

    return(length(topgenes))  # return the number of topgenes found
}


In [9]:
set.seed(765)

# run with sample of 20000 genes and significance 0.005
aa=simulate.noise.heatmap(20,20000,0.005)
print(aa)


[1] 104
In [10]:
#Now simulate 40000 genes with significance 0.0025
aa=simulate.noise.heatmap(20,40000,0.0025)
print(aa)


[1] 99
In [11]:
# And now a sample of only 6 patients, with 20000 genes and significance level of 0.005
aa=simulate.noise.heatmap(3,20000,0.005)
print(aa)
[1] 110
In [ ]: