-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.molgen.mpg.de/loosolab/masterJLU…
…2018 into dev
- Loading branch information
Showing
7 changed files
with
214 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
# Splitting BED-files depending on their cluster. | ||
# The Sequences of each cluster are writen as an FASTA-file. | ||
# @parameter bedInput <string> BED-file with sequences and cluster-id as column"TEs | ||
# @parameter prefix <string> prefix for filenames | ||
# @parameter min_seq <INT> min. number of sequences per cluster | ||
|
||
args = commandArgs(trailingOnly = TRUE) | ||
|
||
bedInput <- args[1] | ||
prefix <- args[2] | ||
min_seq <- args[3] | ||
|
||
bed <- data.table::fread(bedInput, header = FALSE, sep = "\t") | ||
|
||
clusters <- split(bed, bed$V8, sorted = TRUE, flatten = FALSE) # <---- Spalte mit Cluster | ||
discard <- lapply(1:length(clusters), function(i){ | ||
clust <- as.data.frame(clusters[i]) | ||
print(nrow(clust)) | ||
if (nrow(clust) >= as.numeric(min_seq) ) { | ||
sequences <- as.list(clust[[7]]) # <---- Splate mit Sequenz | ||
outfile <- paste0(prefix,"_cluster_",i,".FASTA") | ||
seqinr::write.fasta(sequences = sequences, names = clust[[4]], file.out = outfile, as.string = TRUE) # <---- Spalte mit Name | ||
} else { | ||
print(paste0("Cluster: ",i," is to small")) | ||
} | ||
}) | ||
#!/usr/bin/env Rscript | ||
|
||
# Splitting BED-files depending on their cluster. | ||
# The Sequences of each cluster are writen as an FASTA-file. | ||
# @parameter bedInput <string> BED-file with sequences and cluster-id as columns: Sequence: Column 7; ID:Column 8 | ||
# @parameter prefix <string> prefix for filenames | ||
# @parameter min_seq <INT> min. number of sequences per cluster | ||
|
||
args = commandArgs(trailingOnly = TRUE) | ||
|
||
bedInput <- args[1] | ||
prefix <- args[2] | ||
min_seq <- args[3] | ||
|
||
bed <- data.table::fread(bedInput, header = FALSE, sep = "\t") | ||
|
||
clusters <- split(bed, bed$V8, sorted = TRUE, flatten = FALSE) # <---- Spalte mit Cluster | ||
discard <- lapply(1:length(clusters), function(i){ | ||
clust <- as.data.frame(clusters[i]) | ||
print(nrow(clust)) | ||
if (nrow(clust) >= as.numeric(min_seq) ) { | ||
sequences <- as.list(clust[[7]]) # <---- Splate mit Sequenz | ||
outfile <- paste0(prefix,"_cluster_",i,".FASTA") | ||
seqinr::write.fasta(sequences = sequences, names = clust[[4]], file.out = outfile, as.string = TRUE) # <---- Spalte mit Name | ||
} else { | ||
print(paste0("Cluster: ",i," is to small")) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
# Merging FASTA-files, which motifs are similar. | ||
# | ||
# @parameter tsv_in <string> Path to TSV file generated by Tomtom. | ||
# The input for Tomtom is a from all clusters merged meme-file. | ||
# @parameter file_list <string> Numerically sorted whitespace separated list of absolute fasta-file paths | ||
# @parameter min_weight <INT> Minimum weight of edge allowed in graph clusters. | ||
|
||
|
||
args = commandArgs(trailingOnly = TRUE) | ||
|
||
tsv_in <- args[1] | ||
file_list <- args[2] | ||
min_weight <- args[3] | ||
|
||
files <- unlist(as.list(strsplit(file_list, ","))) | ||
|
||
# split the string on the character "." in the first to columns and safe the last value each, to get the number of the cluster. | ||
tsv <- data.table::fread(tsv_in, header = TRUE, sep = "\t",colClasses = 'character') | ||
query_cluster <- unlist(lapply(strsplit(tsv[["Query_ID"]],"\\."), function(l){ | ||
tail(l,n=1) | ||
})) | ||
target_cluster <- unlist(lapply(strsplit(tsv[["Target_ID"]],"\\."), function(l){ | ||
tail(l,n=1) | ||
})) | ||
|
||
# create data.table with only the cluster-numbers | ||
sim_not_unique <- data.table::data.table(query_cluster,target_cluster) | ||
# convert from character to numeric values | ||
sim_not_unique[, query_cluster := as.numeric(query_cluster)] | ||
sim_not_unique[, target_cluster := as.numeric(target_cluster)] | ||
|
||
# remove rows if column 1 is idential to column 2 | ||
edgelist <- sim_not_unique[query_cluster != target_cluster] | ||
|
||
# create graph from data.frame | ||
g <- igraph::graph_from_edgelist(as.matrix(edgelist)) | ||
# converting graph to adjacency matrix | ||
adj_matrix <- igraph::get.adjacency(g, names = T) | ||
# generating weighted graph from adjacency matrix | ||
g_adj <- igraph::graph_from_adjacency_matrix(adj_matrix, weighted = T) | ||
|
||
# get subgraphs from graph with edges of weight > min_weight | ||
s1 <- igraph::subgraph.edges(g_adj, igraph::E(g_adj)[igraph::E(g_adj)$weight>min_weight], del=F) | ||
png('motif_clusters.png') | ||
plot(s1) | ||
dev.off() | ||
clust <- igraph::clusters(s1) | ||
|
||
# merge FASTA-files depending on the clustered graphs | ||
a <- lapply(seq(from = 1, to = clust$no, by = 1), function(i){ | ||
cl <- as.vector(which(clust$membership %in% c(i))) | ||
fasta_list <- paste(files[cl], collapse = " ") | ||
name <- paste0("Cluster_",i,".fasta") | ||
system(paste("cat",fasta_list,">",name)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.