**This is an old revision of the document!**
Getting Structure Output
The user Federica Lucati (flucati, responsible Marc Ventura) uses Structure with R with the library ParallelStructure. She needs the output of Structure (not the normal output that we usually receive because we only can see the R output).
After a long work searching how to save the outputs of the programs executed as R, Miguel downloades the source code of the ParallelStructure library.
Descomprimo el paquete
- snippet.bash
# tar zxvf ParallelStructure_1.0.tar.gz
el archivo que busco está en ParallelStructure/R/parallelstructure.R
Esta función en algún punto debería llamar a Structure. Voilà:
code=r
217 # wait before running the job (let time to re-new seed between jobs)
218 Sys.sleep(job$wait)
219 instr=paste(structure_path,'structure -m ',param_nam,sep='')
220 system(instr,ignore.stdout=T)
La primera opción que se me ocurrió fue esta:
R
217 # wait before running the job (let time to re-new seed between jobs)
218 Sys.sleep(job$wait)
219 instr=paste(structure_path,'structure -m ',param_nam, ' > structure_output.txt',sep='') # IMPORTANTE retocado el output
220 system(instr) #ignore.stdout=T) # omito ignore.stdout=T
Lo vuelvo a comprimir y lo paso a la máquina de pruebas (node16 en cc196, esto es un kilombo que no pondré aquí)
# tar zcvf ParallelStructure_1.0.tar.gz ParallelStructure
Y lo instalo en R, atención al comando, que no es el de siempre:
/home/soft/R-3.4.3/bin/R >install.packages("/home/soft/sources/ParallelStructure_1.0.tar.gz", repos = NULL, type="source")
Tenía serias dudas de que fuera a instalarse tan fácilmente, pero se instala. Paso también todos los archivos que necesito para ejecutar Structure y descargo el programa de Structure que no está en node16 (en /home/soft/console/)
Retoco los paths de structure.R, structure.sh, genero los joblists (todo esto está explicado aquí: http://www2.ceab.csic.es/cblabdoc/doku.php?id=structure_with_r)
chmod +x structure.sh ./structure.sh
pero me encuentro que sobreescribe el archivo cada vez y necesito guardar uno por cada resultado generado. Después de pensarlo con Xavi vuelvo de nuevo al código fuente. Fijándome en unas líneas más arriba, modifico de nuevo la línea que me interesa:
R
206 # generate parameted file for structure
207 param_nam=paste('parameter_job_',as.character(id),sep='')
219 instr=paste(structure_path,'structure -m ',param_nam,' > structure_output',as.character(id),'.txt', sep='')
Después tengo que repetir todo el proceso (comprimir el paquete, desinstalar el paquete en R e instalar el nuevo) Por si acaso vuelvo a generar los joblists, borro la carpeta de resultados (structure_results)
Y esta vez sí, ahora tenemos todos lo archivos generados.
Ahora solo queda replicarlo en el cluster. Instalaré el paquete en el R-3.4.3.