annotate summarize_gff.R @ 11:1d5883a9ec3a draft

Deleted selected files
author petr-novak
date Wed, 14 Aug 2019 11:24:42 -0400
parents d0431a839606
children ddc6bab20889
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
1 ## summarize hits
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
2 output = commandArgs(T)[2] ## output table
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
3 filepath = commandArgs(T)[1] ## input dante gff3
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
4 summarized_by = commandArgs(T)[-(1:2)]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
5
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
6 readGFF3fromDante = function(filepath){
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
7 dfraw=read.table(filepath, as.is = TRUE)
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
8 gff_df = dfraw[,1:8]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
9 colnames(gff_df) = c("seqid", "source", "type", "start", "end", "score",
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
10 "strand", "phase")
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
11 ## assume same order, same attributes names
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
12 gffattr = do.call(rbind,
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
13 lapply(
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
14 strsplit(dfraw[,9],split=c("=|;")),
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
15 function(x)x[c(FALSE,TRUE)]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
16 )
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
17 )
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
18 gff_df$Name = gffattr[,1]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
19 gff_df$Final_Classification = gffattr[,2]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
20 gff_df$Region_Hits_Classifications = gffattr[,3]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
21 gff_df$Best_Hit = gffattr[,4]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
22 gff_df$Best_Hit_DB_Pos = gffattr[,5]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
23 gff_df$DB_Seq = gffattr[,6]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
24 gff_df$Query_Seq = gffattr[,7]
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
25 gff_df$Identity = as.numeric(gffattr[,8])
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
26 gff_df$Similarity = as.numeric(gffattr[,9])
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
27 gff_df$Relat_Length = as.numeric(gffattr[,10])
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
28 gff_df$Relat_Interruptions = as.numeric(gffattr[,11])
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
29 gff_df$Hit_to_DB_Length = as.numeric(gffattr[,12])
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
30 return(gff_df)
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
31 }
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
32
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
33 gff = readGFF3fromDante(filepath)
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
34 # summarize_by = c("Final_Classification", "Name", "seqid")
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
35
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
36 tbl = data.frame(table(gff[,summarize_by]))
d0431a839606 Uploaded
petr-novak
parents:
diff changeset
37 write.table(tbl, file = filepath, row.names =FALSE, quote = FALSE)