<commit_before><tool id="PcaAndVisualizationInGalaxy" name="PcaAndVisualizationInGalaxy" version="0.01">
<description>performs a principal components analysis(use prcomp) and returns the results as plots</description>

<command interpreter="python">
        PcaAndVisualizationInGalaxy.py --script_path "$runMe" --interpreter "Rscript" 
            --tool_name "PcaAndVisualizationInGalaxy" --input_tab "$input1" --input_int "$input2" --output_dir "$html_file.files_path" --output_tab "$tab_file" --output_tab2 "$tab_file2" --output_html "$html_file" --make_HTML "yes" 
</command>
<inputs>
<param name="input1"  type="data" format="tabular" label="Select a suitable input file from your history"/> 
<param name="input2"  type="text" label="Please input a number of cell-name index in column-name(separated '_')" value="1"/>
<param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="PcaAndVisualizationInGalaxy"/> 

</inputs>
<outputs>
 <data format="tabular" name="tab_file" label="${job_name} on ${on_string}_eigenvectors"/>
 <data format="tabular" name="tab_file2" label="${job_name} on ${on_string}_eigenvalues_and_variances"/>
  <data format="html" name="html_file" label="${job_name} on ${on_string}_output.html"/>
</outputs>
<configfiles>
<configfile name="runMe">
library("matrixStats")
library("stringr")
library("ggplot2")
library("factoextra")
options(rgl.useNULL=TRUE)
library("rgl")

cat("PcaAndVisualizationInGalaxy Started......\n")
cat("\n")

ourargs = commandArgs(TRUE)
inf = ourargs[1]
cell_idx = ourargs[2]
outf = ourargs[3]
outf2 = ourargs[4]
cat("input file name: ");inf
cat("cell name index: ");cell_idx
cell_idx = as.integer(cell_idx)
cat("output file name(1):");outf
cat("output file name(2):");outf2
cat("\n")

outp = read.table(inf, sep="\t", comment.char = "", header=T)
rownames(outp) = outp[,1]
outp = outp[, -1]
outp = outp[, order(names(outp))]
celltype = as.data.frame(str_split(colnames(outp), "_"))
celltype = factor(sort(unname(unlist(celltype[cell_idx,]))))

matrix = data.matrix(outp)
idx = rowVars(matrix) == 0
fmatrix = matrix[!idx,]
fmatrix = log10(fmatrix + 1)
fmatrix = apply(fmatrix,2,function(x){ifelse(is.nan(x), 0, x)})

fdata = data.frame(t(fmatrix))
geneno = nrow(fdata)
nrow(fdata);ncol(fdata)
fdata\$celltype &lt;- celltype

ret_pca = prcomp(t(fmatrix), scale = FALSE, center = TRUE)


screeplot = fviz_screeplot(ret_pca, ncp=nrow(fdata), addlabels=F) + theme_minimal()
ggsave(file="scree_plot.pdf", plot=screeplot, dpi=100, width = 16, height = 4)

# 2D output
fdata2 = fdata[, colnames(fdata) != "celltype"]
max_val = max(c(max(abs(ret_pca\$x[,1])), max(abs(ret_pca\$x[,2])))) + 5
graph_of_ind = fviz_pca_ind(ret_pca, data=fdata2, habillage=fdata\$celltype, addEllipses=TRUE, ellipse.level=0.95) + xlim(-max_val, max_val) + ylim (-max_val, max_val)
ggsave(file="graph_of_ind_2D.pdf", plot=graph_of_ind, dpi=100, width=12, height=12)

# 3D output
fdata\$well = str_split_fixed(rownames(fdata), "_", 2)[,2]
fdata\$type = as.character(fdata\$celltype)
cellinfo = data.frame(type=fdata\$type, well=fdata\$well)
cellinfo = within(cellinfo, sample_name &lt;- paste(type, well, sep="_"))
fdata\$sample_name = cellinfo\$sample_name
plot3d(ret_pca\$x[,1], ret_pca\$x[,2], ret_pca\$x[,3], xlab="Component 1", ylab="Component 2",
       zlab="Component 3", box=FALSE, size=6, col=as.integer(fdata\$celltype))
text3d(ret_pca\$x[,1], ret_pca\$x[,2], ret_pca\$x[,3], as.vector(fdata\$sample_name), cex=1.0, adj=1, scale=0.1)
writeWebGL(dir=getwd(), width=600, height=600)

# Eigenvectors
eigv = ret_pca\$rotation
write.table(eigv, outf, quote=FALSE, sep="\t")

# Eigenvalues
eig = (ret_pca\$sdev)^2
# Variances in percentage
variance = eig*100/sum(eig)
# Cumulative variances
cumvar = cumsum(variance)
length(eig)
eig_dataf = data.frame(row.names=sprintf("PC%d", 1:length(eig)),
                        eigenvalues=eig, variance=round(variance,digits=3), cumvariance = cumvar)
write.table(eig_dataf, outf2, quote=FALSE, sep="\t")


</configfile>
</configfiles>


        <tests>
        <test>
        <param name="input1" value="PcaAndVisualizationInGalaxy_test1_input.xls" ftype="tabular"/>
        <param name="job_name" value="test1"/>
        <param name="runMe" value="$runMe"/>
        <output name="tab_file" file="PcaAndVisualizationInGalaxy_test1_output.xls" ftype="tabular"/>
        </test>
        </tests>
        

<help>

This tool performs a principal components analysis(use prcomp) and returns the results as plots.

**Attribution**
This Galaxy tool was created by <EMAIL> at 03/06/2015 11:30:14
using the Galaxy Tool Factory.

See https://bitbucket.org/fubar/galaxytoolfactory for details of that project
Please cite: Creating re-usable tools from scripts: The Galaxy Tool Factory. <NAME>; <NAME>; <NAME>; The Galaxy Team. 
Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573


</help>
<citations>
    
    <citation type="doi">10.1093/bioinformatics/bts573</citation>
</citations>
</tool>
<commit_msg>modefied PCA-tool output<commit_after><tool id="PcaAndVisualizationInGalaxy" name="PcaAndVisualizationInGalaxy" version="0.01">
<description>performs a principal components analysis(use prcomp) and returns the results as plots</description>

<command interpreter="python">
        PcaAndVisualizationInGalaxy.py --script_path "$runMe" --interpreter "Rscript" 
            --tool_name "PcaAndVisualizationInGalaxy" --input_tab "$input1" --input_int "$input2" --output_dir "$html_file.files_path" --output_tab "$tab_file" --output_tab2 "$tab_file2" --output_html "$html_file" --make_HTML "yes" 
</command>
<inputs>
<param name="input1"  type="data" format="tabular" label="Select a suitable input file from your history"/> 
<param name="input2"  type="text" label="Please input a number of cell-name index in column-name(separated '_')" value="1"/>
<param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="PcaAndVisualizationInGalaxy"/> 

</inputs>
<outputs>
 <data format="tabular" name="tab_file" label="${job_name} on ${on_string}_eigenvectors"/>
 <data format="tabular" name="tab_file2" label="${job_name} on ${on_string}_eigenvalues_and_variances"/>
  <data format="html" name="html_file" label="${job_name} on ${on_string}_output.html"/>
</outputs>
<configfiles>
<configfile name="runMe">
library("matrixStats")
library("stringr")
library("ggplot2")
library("factoextra")
options(rgl.useNULL=TRUE)
library("rgl")

cat("PcaAndVisualizationInGalaxy Started......\n")
cat("\n")

ourargs = commandArgs(TRUE)
inf = ourargs[1]
cell_idx = ourargs[2]
outf = ourargs[3]
outf2 = ourargs[4]
cat("input file name: ");inf
cat("cell name index: ");cell_idx
cell_idx = as.integer(cell_idx)
cat("output file name(1):");outf
cat("output file name(2):");outf2
cat("\n")

outp = read.table(inf, sep="\t", comment.char = "", header=T)
rownames(outp) = outp[,1]
outp = outp[, -1]
outp = outp[, order(names(outp))]
celltype = as.data.frame(str_split(colnames(outp), "_"))
celltype = factor(sort(unname(unlist(celltype[cell_idx,]))))

matrix = data.matrix(outp)
idx = rowVars(matrix) == 0
fmatrix = matrix[!idx,]
fmatrix = log10(fmatrix + 1)
fmatrix = apply(fmatrix,2,function(x){ifelse(is.nan(x), 0, x)})

fdata = data.frame(t(fmatrix))
geneno = nrow(fdata)
nrow(fdata);ncol(fdata)
fdata\$celltype &lt;- celltype

ret_pca = prcomp(t(fmatrix), scale = FALSE, center = TRUE)


screeplot = fviz_screeplot(ret_pca, ncp=nrow(fdata), addlabels=F) + theme_minimal()
ggsave(file="scree_plot.pdf", plot=screeplot, dpi=100, width = 16, height = 4)

# 2D output
fdata2 = fdata[, colnames(fdata) != "celltype"]
max_val = max(c(max(abs(ret_pca\$x[,1])), max(abs(ret_pca\$x[,2])))) + 5
graph_of_ind = fviz_pca_ind(ret_pca, data=fdata2, habillage=fdata\$celltype, addEllipses=TRUE, ellipse.level=0.95) + xlim(-max_val, max_val) + ylim (-max_val, max_val)
ggsave(file="graph_of_ind_2D.pdf", plot=graph_of_ind, dpi=100, width=12, height=12)

# 3D output
fdata\$well = str_split_fixed(rownames(fdata), "_", 2)[,2]
fdata\$type = as.character(fdata\$celltype)
cellinfo = data.frame(type=fdata\$type, well=fdata\$well)
cellinfo = within(cellinfo, sample_name &lt;- paste(type, well, sep="_"))
fdata\$sample_name = cellinfo\$sample_name
plot3d(ret_pca\$x[,1], ret_pca\$x[,2], ret_pca\$x[,3], xlab="Component 1", ylab="Component 2",
       zlab="Component 3", box=FALSE, size=6, col=as.integer(fdata\$celltype))
text3d(ret_pca\$x[,1], ret_pca\$x[,2], ret_pca\$x[,3], as.vector(fdata\$sample_name), cex=1.0, adj=1, scale=0.1)
writeWebGL(dir=getwd(), width=600, height=600)

# Eigenvectors
# eigv = ret_pca\$rotation
# PC loading
write.table(ret_pca\$x, outf, quote=FALSE, sep="\t")

# Eigenvalues
eig = (ret_pca\$sdev)^2
# Variances in percentage
variance = eig*100/sum(eig)
# Cumulative variances
cumvar = cumsum(variance)
length(eig)
eig_dataf = data.frame(row.names=sprintf("PC%d", 1:length(eig)),
                        eigenvalues=eig, variance=round(variance,digits=3), cumvariance = cumvar)
write.table(eig_dataf, outf2, quote=FALSE, sep="\t")


</configfile>
</configfiles>


        <tests>
        <test>
        <param name="input1" value="PcaAndVisualizationInGalaxy_test1_input.xls" ftype="tabular"/>
        <param name="job_name" value="test1"/>
        <param name="runMe" value="$runMe"/>
        <output name="tab_file" file="PcaAndVisualizationInGalaxy_test1_output.xls" ftype="tabular"/>
        </test>
        </tests>
        

<help>

This tool performs a principal components analysis(use prcomp) and returns the results as plots.

**Attribution**
This Galaxy tool was created by <EMAIL> at 03/06/2015 11:30:14
using the Galaxy Tool Factory.

See https://bitbucket.org/fubar/galaxytoolfactory for details of that project
Please cite: Creating re-usable tools from scripts: The Galaxy Tool Factory. Ross Lazarus; <NAME>; <NAME>ann; The Galaxy Team. 
Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573


</help>
<citations>
    
    <citation type="doi">10.1093/bioinformatics/bts573</citation>
</citations>
</tool>

{'fraction_non_alphanumeric': 0.1684367245657568, 'fraction_numerical': 0.024615384615384615, 'mean_word_length': 5.789757412398922, 'pattern_counts': {'":': 0, '<': 78, '<?xml version=': 0, '>': 78, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '12570', 'n_tokens_mistral': 3951, 'n_tokens_neox': 3688, 'n_words': 769}