Mercurial > repos > azomics > check_fcs_header
comparison getFCSheader.R @ 0:2227def10ea4 draft default tip
"planemo upload for repository https://github.com/ImmPortDB/immport-galaxy-tools/tree/master/flowtools/check_fcs_headers commit 6da41781e60ad4e264c4d725c5373b099b4766d4"
| author | azomics | 
|---|---|
| date | Wed, 24 Jun 2020 17:36:27 -0400 | 
| parents | |
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| -1:000000000000 | 0:2227def10ea4 | 
|---|---|
| 1 #!/usr/bin/Rscript --vanilla | |
| 2 # FCS Headers Module for Galaxy | |
| 3 # FlowCore | |
| 4 ###################################################################### | |
| 5 # Copyright (c) 2016 Northrop Grumman. | |
| 6 # All rights reserved. | |
| 7 ###################################################################### | |
| 8 # | |
| 9 # Version 2 | |
| 10 # May 2018 | |
| 11 # Cristel Thomas | |
| 12 # | |
| 13 # | |
| 14 | |
| 15 library(flowCore) | |
| 16 | |
| 17 getFCSChannels <- function(input_fcs) { | |
| 18 fcs <- read.FCS(input_fcs, transformation=F) | |
| 19 return(colnames(fcs)) | |
| 20 } | |
| 21 | |
| 22 getFCSMarkers <- function(input_fcs){ | |
| 23 ffcs <- read.FCS(input_fcs, transformation=F) | |
| 24 fmarkers <- as.vector(pData(parameters(ffcs))$desc) | |
| 25 return(fmarkers) | |
| 26 } | |
| 27 | |
| 28 getFCSMarkerNames <- function(output_file="", file_paths=vector(), | |
| 29 fcs_names=vector()) { | |
| 30 check_files <- sapply(file_paths, isFCSfile) | |
| 31 channels <- lapply(file_paths[check_files], getFCSChannels) | |
| 32 markers <- lapply(file_paths[check_files], getFCSMarkers) | |
| 33 | |
| 34 nb_col <- max(lengths(channels)) | |
| 35 nc <- lapply(channels, `length<-`, nb_col) | |
| 36 ct <- t(as.data.frame(nc)) | |
| 37 | |
| 38 nm <- lapply(markers, `length<-`, nb_col) | |
| 39 mt <- t(as.data.frame(nm)) | |
| 40 | |
| 41 nb_files <- sum(check_files) | |
| 42 Index <- rep(c("channels", "markers"), each=nb_files) | |
| 43 Filename <- rep(fcs_names[check_files], 2) | |
| 44 | |
| 45 idx_nb <- seq(nb_col) | |
| 46 ttt <- rbind(ct,mt) | |
| 47 finalt <- cbind(Filename, Index, ttt) | |
| 48 colnames(finalt)[3:length(colnames(finalt))] <- idx_nb | |
| 49 | |
| 50 | |
| 51 if (nb_files != length(file_paths)){ | |
| 52 not_fcs <- fcs_names[!check_files] | |
| 53 new_df <- cbind(not_fcs, "Not a valid FCS file") | |
| 54 empty_frame <- data.frame(matrix("", nrow=length(not_fcs), ncol=nb_col), | |
| 55 stringsAsFactors = F) | |
| 56 not_fcs_files <- cbind(new_df, empty_frame) | |
| 57 colnames(not_fcs_files) <- colnames(finalt) | |
| 58 new_final <- rbind(finalt, not_fcs_files) | |
| 59 write.table(new_final, file=output_file, quote=F, row.names=F, col.names=T, | |
| 60 sep='\t', append=F) | |
| 61 quit(save = "no", status = 10, runLast = FALSE) | |
| 62 } else { | |
| 63 # output file | |
| 64 write.table(finalt, file=output_file, quote=F, row.names=F, col.names=T, | |
| 65 sep='\t', | |
| 66 append=F) | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 ################################################################################ | |
| 71 ################################################################################ | |
| 72 | |
| 73 args <- commandArgs(trailingOnly = TRUE) | |
| 74 | |
| 75 i <- 1 | |
| 76 nb_files <- (length(args)-1) / 2 | |
| 77 fcs_files <- character(nb_files) | |
| 78 fcs_names <- character(nb_files) | |
| 79 for (j in 1:length(args)){ | |
| 80 if (!j%%2){ | |
| 81 fcs_files[[i]] <- args[[j]] | |
| 82 fcs_names[[i]]<- args[[j+1]] | |
| 83 i <- i + 1 | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 getFCSMarkerNames(args[1], fcs_files, fcs_names) | 
