File size: 1,433 Bytes
90f526e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#
# Transform feature counts output to simple counts.
#

# The results files to be compared.

# Count file produced by featurecounts.
counts_file <- "counts.txt"

# The sample file must be in CSV format and must have the headers "sample" and "condition".
design_file = "design.csv"

# The name of the output file.
output_file = "counts.csv"

# Inform the user.
print("# Tool: Parse featurecounts")
print(paste("# Design: ", design_file))
print(paste("# Input: ", counts_file))

# Read the sample file.
sample_data <- read.csv(design_file, stringsAsFactors=F)

# Turn conditions into factors.
sample_data$condition <- factor(sample_data$condition)

# The first level should correspond to the first entry in the file!
# Required when building a model.
sample_data$condition <- relevel(sample_data$condition, toString(sample_data$condition[1]))

# Read the featurecounts output.
df <- read.table(counts_file, header=TRUE)

#
# It is absolutely essential that the order of the featurecounts headers is the same
# as the order of the sample names in the file! The code below will overwrite the headers!
#

# Subset the dataframe to the columns of interest.
counts <- df[ ,c(1, 7:length(names(df)))]

# Rename the columns
names(counts) <- c("name", sample_data$sample)

# Write the result to the standard output.
write.csv(counts, file=output_file, row.names=FALSE, quote=FALSE)

# Inform the user.
print(paste("# Output: ", output_file))