mandymejia / ciftiTools

ciftiTools R package
46 stars 8 forks source link

any plans to add support for scalar.nii #59

Closed vikramraobm closed 4 months ago

vikramraobm commented 6 months ago

I am trying to use this with pscalar.nii and it seems the intent code for pscalar.nii is not allowed. I am trying to convert a text file of pvalues (one row for each parcel) into a pscalar.nii and then plot using wb_view. I was hoping I could ciftiTools to do this.

Failed Attempts: I tried converting the .txt file into a dscalar.nii instead of a pscalar.nii and then use read_cifti to read that in but looks like the intent code is embedded in file and still gives me an error: Error in check_cifti_type(intent, extn) : This CIFTI file has intent code 3008 which is not yet supported by ciftiTools. Only the following types are: 3002 3006 3007 The extension dscalar.nii is supported but does not match the intent code. Was the file named incorrectly?

mandymejia commented 6 months ago

Hi Vikram,

We don’t have any short-term plans to implement this, but Damon may be able to suggest a workaround.

Damon, let’s talk at some point if this would be a straightforward extension to cifttTools.

Mandy

On Sun, Apr 21, 2024 at 10:24 AM vikramraobm @.***> wrote:

I am trying to use this with pscalar.nii and it seems the intent code for pscalar.nii is not allowed. I am trying to convert a text file of pvalues (one row for each parcel) into a pscalar.nii and then plot using wb_view. I was hoping I could ciftiTools to do this.

Failed Attempts: I tried converting the .txt file into a dscalar.nii instead of a pscalar.nii and then use read_cifti to read that in but looks like the intent code is embedded in file and still gives me an error: Error in check_cifti_type(intent, extn) : This CIFTI file has intent code 3008 which is not yet supported by ciftiTools. Only the following types are: 3002 3006 3007 The extension dscalar.nii is supported but does not match the intent code. Was the file named incorrectly?

— Reply to this email directly, view it on GitHub https://github.com/mandymejia/ciftiTools/issues/59, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHVKUWJXVE3E2QQUUMZDG3Y6MPMXAVCNFSM6AAAAABGQ7GPSCVHI2DSMVQWIX3LMV43ASLTON2WKOZSGI2TIOBWGM4DAMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

damondpham commented 6 months ago

Hi Vikram,

I am away from my computer for the next few days but I return on Thursday. If you send me your original file, I can send you a script for how to convert it to a ciftiTools 'xifti' object. I would need both the data of values for each parcel, as well as the parcellation itself (what vertices belong to each parcel).

Best,

Damon

On Sunday, April 21, 2024, Mandy Mejia @.***> wrote:

Hi Vikram,

We don’t have any short-term plans to implement this, but Damon may be able to suggest a workaround.

Damon, let’s talk at some point if this would be a straightforward extension to cifttTools.

Mandy

On Sun, Apr 21, 2024 at 10:24 AM vikramraobm @.***> wrote:

I am trying to use this with pscalar.nii and it seems the intent code for pscalar.nii is not allowed. I am trying to convert a text file of pvalues (one row for each parcel) into a pscalar.nii and then plot using wb_view. I was hoping I could ciftiTools to do this.

Failed Attempts: I tried converting the .txt file into a dscalar.nii instead of a pscalar.nii and then use read_cifti to read that in but looks like the intent code is embedded in file and still gives me an error: Error in check_cifti_type(intent, extn) : This CIFTI file has intent code 3008 which is not yet supported by ciftiTools. Only the following types are: 3002 3006 3007 The extension dscalar.nii is supported but does not match the intent code. Was the file named incorrectly?

— Reply to this email directly, view it on GitHub https://github.com/mandymejia/ciftiTools/issues/59, or unsubscribe https://github.com/notifications/unsubscribe-auth/ ABHVKUWJXVE3E2QQUUMZDG3Y6MPMXAVCNFSM6AAAAABGQ7GPSCVHI2DSMVQW IX3LMV43ASLTON2WKOZSGI2TIOBWGM4DAMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mandymejia/ciftiTools/issues/59#issuecomment-2068081837, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSD47CXF7GBYNCLPFD5DODY6PKHTAVCNFSM6AAAAABGQ7GPSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRYGA4DCOBTG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

vikramraobm commented 6 months ago

Thanks Damon for your quick response. I have attached the text file with a 387X1 row vector. And the associated template.pscalar.nii that goes with the 387 parcels. Vikram Rao, M.S.

Head of R&D | Senior Scientific Programmer

MINDSET Integrated Co (505) 587-3904 | (817) 239-0949 @.** www.mindsetintegrated.com 800 Lomas Blvd NW Suite 100, Albuquerque, NM 87102 [image: facebook] https://www.facebook.com/mindsetintegrated [image: linkedin] https://www.linkedin.com/company/mindset-integrated-co/?viewAsMember=true CONFIDENTIALITY NOTICE: The contents of this email message and any attachments are for the intended addressee(s) only and may contain confidential and/or privileged information and may be legally protected from disclosure. If you are not the intended recipient of this message or their agent, or if this message has been addressed to you in error, please immediately alert the sender by reply email and then delete this message and any attachments. If you are not the intended recipient, you are hereby notified that any use, dissemination, copying, or storage of this message or its attachments is strictly prohibited. Disclaimer: Confidential Information. Recipients shall use reasonable efforts to maintain the confidentiality of the information and materials, whether oral, written or in any form whatsoever, and refrain from information’s disclosure or may immediately return to the provider thereof all Confidential Information not licensed or authorized to be used or enjoyed by any such person or persons that had no access to Confidential Information. Contractors and Experts are additionally bound by the Confidentiality clauses of their individual Contracts. May not be disclosed to third parties, shared, duplicated or disseminated for any use other than that intended by or contracted by MINDSET Integrated Co. All Confidential Information delivered shall be and remain the property of MINDSET Integrated Co. and any documents containing or reflecting the Confidential Information, and all copies thereof, shall be promptly returned upon written request, or destroyed at the disclosing Party’s option. Nothing herein shall be construed as granting or conferring any rights by license or otherwise, express or implied, regarding any idea made, conceived or acquired, nor as granting any right with respect to the use or marketing of any product or service. Parties shall use the Confidential Information only for the Business Relationship*

On Sun, Apr 21, 2024 at 2:32 PM Damon Đ Phạm @.***> wrote:

Hi Vikram,

I am away from my computer for the next few days but I return on Thursday. If you send me your original file, I can send you a script for how to convert it to a ciftiTools 'xifti' object. I would need both the data of values for each parcel, as well as the parcellation itself (what vertices belong to each parcel).

Best,

Damon

On Sunday, April 21, 2024, Mandy Mejia @.***> wrote:

Hi Vikram,

We don’t have any short-term plans to implement this, but Damon may be able to suggest a workaround.

Damon, let’s talk at some point if this would be a straightforward extension to cifttTools.

Mandy

On Sun, Apr 21, 2024 at 10:24 AM vikramraobm @.***> wrote:

I am trying to use this with pscalar.nii and it seems the intent code for pscalar.nii is not allowed. I am trying to convert a text file of pvalues (one row for each parcel) into a pscalar.nii and then plot using wb_view. I was hoping I could ciftiTools to do this.

Failed Attempts: I tried converting the .txt file into a dscalar.nii instead of a pscalar.nii and then use read_cifti to read that in but looks like the intent code is embedded in file and still gives me an error: Error in check_cifti_type(intent, extn) : This CIFTI file has intent code 3008 which is not yet supported by ciftiTools. Only the following types are: 3002 3006 3007 The extension dscalar.nii is supported but does not match the intent code. Was the file named incorrectly?

— Reply to this email directly, view it on GitHub https://github.com/mandymejia/ciftiTools/issues/59, or unsubscribe https://github.com/notifications/unsubscribe-auth/ ABHVKUWJXVE3E2QQUUMZDG3Y6MPMXAVCNFSM6AAAAABGQ7GPSCVHI2DSMVQW IX3LMV43ASLTON2WKOZSGI2TIOBWGM4DAMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/mandymejia/ciftiTools/issues/59#issuecomment-2068081837>,

or unsubscribe < https://github.com/notifications/unsubscribe-auth/ADSD47CXF7GBYNCLPFD5DODY6PKHTAVCNFSM6AAAAABGQ7GPSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRYGA4DCOBTG4>

. You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/mandymejia/ciftiTools/issues/59#issuecomment-2068189905, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEZDHDUDSWAKN5MH67IRJWTY6QO6DAVCNFSM6AAAAABGQ7GPSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRYGE4DSOJQGU . You are receiving this because you authored the thread.Message ID: @.***>

0.582133105056237 0.001430830897435 0.620232325905399 0.0834675910931748 0.232393425229993 0.0349616254327848 0.617090284762886 0.00439743965304041 0.202655452958193 0.446878699501014 0.191040066721405 0.3547906808414 0.807687101111024 0.319779526927088 0.938611904364727 0.352698602142159 0.0622282893092193 0.896146336268726 0.143677116881096 0.0351081011851493 0.156701424547402 0.205256644447087 0.0465435014294062 0.700588799408142 0.282086667992908 0.195477295826373 0.777648265639513 0.116864725549293 0.839240629199199 0.908067632273543 0.577963621375646 0.400522159390766 0.141266780084579 0.31110853682602 0.944170397583992 0.0267133586385275 0.809758706072417 0.652382831350317 0.0165704612176415 0.0949768619352784 0.0617748819577578 0.43248378834058 0.518134638111416 0.266286154874025 0.6312896918914 0.917868893683269 0.895911249310873 0.816052702144038 0.115648945893192 0.798562943327957 0.041887391941398 0.27329231659929 0.0326450411631657 0.681793589266034 0.0954536794669858 0.0530703049341904 0.865530515630384 0.183611875542234 0.0643878299621916 0.171055354111537 0.161755388253648 0.794868587217863 0.594560225049378 0.986956840671211 0.421084590768893 0.410863232696155 0.181579914835662 0.288284351596435 0.114733526113588 0.0581776033405055 0.113842266224672 0.0124488684901898 0.778897322865333 0.48571738056807 0.765100689221765 0.164931678411032 0.23404292358799 0.179538521797028 0.125858263778898 0.583547692964071 0.17352862978257 0.0651881642724598 0.51094245514329 0.0903238193346923 0.249863991386514 0.542474541787345 0.130836232508423 0.596011690295508 0.0951138292851414 0.252314475892512 0.198158130619059 0.231759019483407 0.0942384619163209 0.0950884470813315 0.723868828465349 0.693437820635859 0.0907611162271541 0.380393097204844 0.346229789182373 0.405766230938337 0.415473552859719 0.152577615616773 0.521890094181127 0.00968189933551501 0.348076181562633 0.0469517856801793 0.141134231318546 0.121318397695549 0.442596465400444 0.416838757222246 0.639446658516925 0.837018425404331 0.226529192878406 0.176537667546727 0.288835982416809 0.477034514485402 0.0762083106403954 0.829588606063065 0.15758531032105 0.215309328980068 0.5939809030334 0.710301861399645 0.333935666426498 0.155066491251207 0.118044308481198 0.603819291225864 0.26792588382109 0.148730152615746 0.258568088969366 0.747541062973445 0.885427743429224 0.76360427204059 0.114416833094595 0.752591983511604 0.882231846953875 0.0989230573558805 0.413578194376573 0.163610427082148 0.1485846239053 0.302041973540633 0.137782679789489 0.366672105588387 0.171234451578297 0.3795471167641 0.586718642483599 0.878201615292112 0.210237448887645 0.574094125137724 0.640598050790435 0.599210835922562 0.314034605299255 0.413427642491901 0.733573202866738 0.890425589615711 0.267959516487214 0.0322883730902658 0.0916726194395519 0.871701819795424 0.264144147941033 0.536878716080917 0.606266235963378 0.81341612848722 0.799329674220282 0.482493935615579 0.18462137923657 0.596808258051744 0.717529329818882 0.126594699468914 0.240919991693879 0.0606545121225557 0.0693459518536646 0.94912904743948 0.820363533612168 0.228616365546009 0.269565288159221 0.359181834126065 0.0545925118475821 0.795633659072604 0.940980705210523 0.912308216181706 0.595919794794192 0.0181061651915725 0.688263730096542 0.139885002133735 0.254667113800672 0.598881284247877 0.369963908309003 0.049622792091927 0.234185022454204 0.348333130804149 0.98716759833875 0.130125305017697 0.805720832141272 0.713488711296766 0.898870951492379 0.398892847060669 0.623761749717297 0.460906307577317 0.81616050433255 0.364913523411088 0.555946440857243 0.188221168014335 0.222533504863681 0.483322092070405 0.485964297229648 0.591282154746798 0.331274504418108 0.056013492919471 0.713499186226268 0.55254464741043 0.142275766142648 0.0563094847761554 0.0270065269161338 0.0431041292782671 0.0496867785881796 0.00194046392995548 0.229938186342905 0.440109032236731 0.191340762523154 0.367102906625804 0.312223473164433 0.408407581903299 0.376419980889914 0.186097823232895 0.413053792854915 0.640064745194347 0.233819489083642 0.832887066027683 0.664267139242354 0.933772821732677 0.171117277040941 0.356042732582368 0.353762301365659 0.34288754683725 0.462148262022601 0.133629107035294 0.289491843362467 0.144656216653146 0.173094658558429 0.272610321089588 0.316672352971247 0.280517520957669 0.383052903460846 0.0973989188263624 0.00289210701059563 0.162202663592305 0.457045471517501 0.0823212016139865 0.0130655405062591 0.362575421807465 0.00547286817793544 0.0172163667354541 0.395380992277548 0.611007002904204 0.185472930323854 0.00734459609429072 0.0341622870116924 0.102797175410925 0.745958682104233 0.517806792145506 0.778815432382214 0.859659832203117 0.83615961698729 0.430206930389387 0.290317337727736 0.0980453442632929 0.0809161014006939 0.487886220710887 0.0114064382978453 0.970909057785408 0.0486183196486959 0.12577952766994 0.110026163082836 0.0739442282534983 0.532671398678653 0.964146914625978 0.57802733261589 0.141522448513498 0.0685604386103614 0.282215229271272 0.289041191370916 0.064070719191022 0.730601543037319 0.350416112958877 0.603336288079605 0.246224127293534 0.878672429623994 0.461271112193722 0.124677961425297 0.24196674411779 0.518857715381686 0.758173128546146 0.454532548067141 0.911092291529013 0.493273609006374 0.30843284759293 0.731088632463389 0.212833629407919 0.979035337421865 0.651793369089952 0.666544711444267 0.40435097295108 0.326410014379858 0.0459003789590678 0.00536381607626995 0.146459186365234 0.852090084968266 0.0145236211243755 0.0478138138060358 0.152717872412408 0.00295253763206663 0.0302980094252166 0.0722566835962478 0.324956308646659 0.219156503212723 0.711768977922522 0.20199051811246 0.103001046571224 0.0631971908406642 0.491429314782582 0.0296189120105697 0.7538123727126 0.735149050510432 0.506700633048166 0.317876740360629 0.944504138817197 0.582178446209553 0.215003926190332 0.16872303686176 0.174935957219492 0.0330768420701678 0.353522575568389 0.581530088571567 0.614176223632582 0.89437964235087 0.195967766857515 0.0351926375372239 0.597964911249406 0.94901209513639 0.362732727910982 0.184733051042108 0.772594162188208 0.309646065093116 0.0860270617432458 0.893826387126999 0.394051224537456 0.393830874806108 0.0101429559234816 0.257447190438913 0.00839408529798315 0.265362488081779 0.0905425127174131 0.620156151275526 0.215322464844286 0.113200946497482 0.00311472377852361 0.0768283162272972 0.723694042700802 0.249594458170612 0.495823961180656 0.332657184699452 0.0814519002525194 0.0325321609322921 0.0680492671665349 0.153608534895873 0.131695676856209 0.639007283783836 0.40917747985463 0.227053304787623 0.490441424665384 0.0283920050906816 0.117948640122386 0.55382310930962 0.0669019321029562 0.985054741282325 0.563219901948593 0.448501883106671 0.28952795057474 0.273861327376983 0.422025531565301 0.793433323895686 0.705646764580281 0.693443323868149 0.421621823680073 0.598823754737091 0.276501506098056 0.175017386161693

damondpham commented 6 months ago

@vikramraobm there seems to be an issue with GitHub/email because I do not see any attachment for "template.pscalar.nii". Can you send this file to me regularly by email at damondpham @ gmail . com ?

Or, you can upload to Google Drive and share a link for me to download. Thanks!

damondpham commented 6 months ago

@vikramraobm thanks for sending in the files!

So I did this:

library(ciftiTools)
ciftiTools.setOption("wb_path", "~/Desktop/workbench")
library(templateICAr)
library(cifti)

pscalar <- cifti::cifti_data("template.pscalar.nii")
pval <- read.csv("C2_MBS-Pre_vs_MBS-Post_pval.txt", header=FALSE)

and I found that pscalar and pval are both numeric vectors of length 387.

So I'm guessing there are 387 parcels--but what are the actual data locations? We would need a file indicating the location of each vertex, and what parcel each vertex belongs to, in order to plot a mesh with the p-values (or the values for pscalar). Otherwise, we wouldn't know what these parcels look like. Do you have this information? It might be in the form of (1) a dlabel.nii CIFTI file containing a locations-length vector, where each value is a number 1 through 387 indicating the parcel identity of that location; and (2) a surf.gii GIFTI file (or two, one for each of the left and right cortex) containing the vertices' locations. (1) is absolutely necessary; for (2) we can use HCP subject-average surfaces if (1) is in-register with it.

vikramraobm commented 6 months ago

Sorry for the delay in response. I sent you the dlabel.nii that should have this. We are using the standard HCP MSMALL surface locations so Ithink any standard HCP atlas *.gii files should be good to use. However, I sent the ones we use just in case. Thanks again for working on this and hopefully there would be a way to read .pscalar.nii files

Vikram Rao, M.S.

Head of R&D | Senior Scientific Programmer

MINDSET Integrated Co (505) 587-3904 | (817) 239-0949 @.** www.mindsetintegrated.com 800 Lomas Blvd NW Suite 100, Albuquerque, NM 87102 [image: facebook] https://www.facebook.com/mindsetintegrated [image: linkedin] https://www.linkedin.com/company/mindset-integrated-co/?viewAsMember=true CONFIDENTIALITY NOTICE: The contents of this email message and any attachments are for the intended addressee(s) only and may contain confidential and/or privileged information and may be legally protected from disclosure. If you are not the intended recipient of this message or their agent, or if this message has been addressed to you in error, please immediately alert the sender by reply email and then delete this message and any attachments. If you are not the intended recipient, you are hereby notified that any use, dissemination, copying, or storage of this message or its attachments is strictly prohibited. Disclaimer: Confidential Information. Recipients shall use reasonable efforts to maintain the confidentiality of the information and materials, whether oral, written or in any form whatsoever, and refrain from information’s disclosure or may immediately return to the provider thereof all Confidential Information not licensed or authorized to be used or enjoyed by any such person or persons that had no access to Confidential Information. Contractors and Experts are additionally bound by the Confidentiality clauses of their individual Contracts. May not be disclosed to third parties, shared, duplicated or disseminated for any use other than that intended by or contracted by MINDSET Integrated Co. All Confidential Information delivered shall be and remain the property of MINDSET Integrated Co. and any documents containing or reflecting the Confidential Information, and all copies thereof, shall be promptly returned upon written request, or destroyed at the disclosing Party’s option. Nothing herein shall be construed as granting or conferring any rights by license or otherwise, express or implied, regarding any idea made, conceived or acquired, nor as granting any right with respect to the use or marketing of any product or service. Parties shall use the Confidential Information only for the Business Relationship*

On Fri, Apr 26, 2024 at 10:43 AM Damon Đ Phạm @.***> wrote:

@vikramraobm https://github.com/vikramraobm thanks for sending in the files!

So I did this:

library(ciftiTools) ciftiTools.setOption("wb_path", "~/Desktop/workbench") library(templateICAr) library(cifti)

pscalar <- cifti::cifti_data("template.pscalar.nii") pval <- read.csv("C2_MBS-Pre_vs_MBS-Post_pval.txt", header=FALSE)

and I found that pscalar and pval are both numeric vectors of length 387.

So I'm guessing there are 387 parcels--but what are the actual data locations? We would need a file indicating the location of each vertex, and what parcel each vertex belongs to, in order to plot a mesh with the p-values (or the values for pscalar). Otherwise, we wouldn't know what these parcels look like. Do you have this information? It might be in the form of (1) a dlabel.nii CIFTI file containing a locations-length vector, where each value is a number 1 through 387 indicating the parcel identity of that location; and (2) a surf.gii GIFTI file (or two, one for each of the left and right cortex) containing the vertices' locations. (1) is absolutely necessary; for (2) we can use HCP subject-average surfaces if (1) is in-register with it.

— Reply to this email directly, view it on GitHub https://github.com/mandymejia/ciftiTools/issues/59#issuecomment-2079644668, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEZDHDX5LTOHH4WHKBOBNJLY7JY3LAVCNFSM6AAAAABGQ7GPSCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZZGY2DINRWHA . You are receiving this because you were mentioned.Message ID: @.***>

damondpham commented 6 months ago

Thanks @vikramraobm! I think this is it:

library(ciftiTools)
ciftiTools.setOption("wb_path", "~/Desktop/workbench")
library(templateICAr)

valsVec <- read.csv("C2_MBS-Pre_vs_MBS-Post_pval.txt", header=FALSE)[,1]
# valsVec <- c(cifti::cifti_data("template.pscalar.nii")) # not used?

parc <- read_cifti("N387_CerebellarParcellation.dlabel.nii")
parcKeys <- parc$meta$cifti$labels$`#1`$Key
# Add `NA` to start for medial wall key==0.
parcVals <- c(NA, valsVec)[parcKeys+1]

xii <- ciftiTools::parc_vals_to_xifti(parc, parcVals)
# Move `NA` to medial wall mask
xii <- move_to_mwall(xii, NA)
# Add surface for plotting (optional)
xii <- add_surf(xii,
  surfL = "/Users/ddpham/Desktop/StatMIND/Vikram/Q1-Q6_RelatedParcellation210.L.midthickness_MSMAll_2_d41_WRN_DeDrift.32k_fs_LR.surf.gii",
  surfR = "/Users/ddpham/Desktop/StatMIND/Vikram/Q1-Q6_RelatedParcellation210.R.midthickness_MSMAll_2_d41_WRN_DeDrift.32k_fs_LR.surf.gii"
)
plot(xii)

write_cifti(xii, "~/Desktop/StatMIND/Vikram/pvals.dscalar.nii")

A few things to note: