Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Histogram Issue #15

Open
issylarken28 opened this issue Sep 5, 2019 · 2 comments
Open

Histogram Issue #15

issylarken28 opened this issue Sep 5, 2019 · 2 comments
Labels
bug Something isn't working Data visualization R anything related to R programming language

Comments

@issylarken28
Copy link

issylarken28 commented Sep 5, 2019

#set directory
setwd("C:/Users/larke/OneDrive/Desktop/R/R")

#step 1 - import the cilia text file

#import text file #tabs delimited
my_data <- read.csv("pixel intensity data tab.txt", header = TRUE,  sep='\t') 

#testing data class
class(my_data)

#renames columns
names(my_data)[1]<-"Frame"
names(my_data)[2]<-"Mean1"

#step 2 - fourier transform of the values
#will use fft (fast fourier transform)

#will first test fft on one column
Mean1four = fft(my_data$Mean1)

#now do the fft on whole dataframe
fourierd = apply(my_data,2,function(x) fft(as.numeric(x))) #it's now a matrix

#turn it into a data frame
fourierdat = as.data.frame(fourierd)

#fix frame numbers (they were also fft-ed)
fourierdat$Frame = seq(1:256)
#Error in `$<-.data.frame`(`*tmp*`, Frame, value = 1:512) : 
# replacement has 512 rows, data has 256
# Therefore IL canged "(1:512)" to "(1:256)

#step 3 - get the absolute value of the complex numbers resulting from the fft
#in excel this is done using =IMABS(range)

absTest = abs(fourierdat$Mean1) #testing on one column

absTestAll = abs(fourierdat) #converts all the complex numbers to absolute numbers

#step 4 - calculating the CBF

#if frequency resolution is = 0.94
#if is not 0.94, replace with correct value

FRadjusted = absTestAll$Frame*0.94

absTestAll$Frame = FRadjusted #this updates the frame to 0.94

#Pre-defining the matrix
HisDat <- 1

# For each column of data, find the max number & corrisponding row number.
# multiply the two new values together -> HisDat (Histogram Data)
for(i in 1:lengths(absTestAll)){
  MaxNum <- max(absTestAll[[i]]);
  MaxRow <- which(grepl(max(absTestAll[[i]]), absTestAll[[i]]))
  HisDat[i] <- MaxNum*MaxRow
}

# Plot the Histogram
hist(HisDat,
     breaks=256)

#     multiply max ab no. by row number and frequency resolution
#     to result in 1600 data points which = CBF in 1600 areas of interest
|
#Playing with my histogram
histinfo <- hist(HisDat)



#step 5 - CBF Histogram

Data: pixel intensity data tab.txt

@issylarken28
Copy link
Author

Hi @alhenry, do you have the code for this we worked out during code club the other day?

@alhenry
Copy link
Member

alhenry commented Sep 10, 2019

Hi @issylarken28 here's the code and the output (I removed some parts to make it more concise).
Hope this helps

#import text file
my_data <- read.csv("https://github.com/ucl-ihi/CodeClub/files/3579119/pixel.intensity.data.tab.txt", header = TRUE,  sep='\t') 

#now do the fft on whole dataframe
fourierd <- apply(my_data,2,function(x) fft(as.numeric(x))) #it's now a matrix

#turn it into a data frame
fourierdat <- as.data.frame(fourierd)

#step 3 - get the absolute value of the complex numbers resulting from the fft
absTestAll <- abs(fourierdat) 

# histogram
histData <- sapply(absTestAll[2:nrow(absTestAll),], which.max) * 0.94
hist(histData[2:length(histData)], breaks = 1000, xlim = c(0,20), ylim=c(0,150))

Created on 2019-09-10 by the reprex package (v0.3.0)

@alhenry alhenry added bug Something isn't working R anything related to R programming language Data visualization labels Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Data visualization R anything related to R programming language
Projects
None yet
Development

No branches or pull requests

2 participants