Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.
Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts

Friday, November 21, 2014

Convert 2 by 2 Contingency Table to Data Frame in R

Contingency tables are useful short hand ways of inputting and visualizing data. I have yet to find an easy way to convert between contingency tables and data frames in R. Below is a short script in which I input a contingency table, create a function to convert the 2 by 2 table to a data frame, and convert the data frame back to a table. These operations are useful for running some statistical operations that either only work on tables or only work on data frames. Hope the below example is useful.

Monday, August 25, 2014

Python List Comprehension

Python list comprehension enables for easy manipulation of a list variable.  For example, list comprehension can be used to convert from a string to an integer or float as well as do some common operation on a list.  Below is an example script that shows the syntax for list comprehension and how to utilize the code in Python.  Hope its helpful.

Friday, August 22, 2014

Create Multiple Y Axes for an R Plot

R base graphics is a powerful tool for plotting data.  Sometimes it is convenient to visualize combinations of variables on the same plot.  Often different variables require different scales.  This can be facilitated by using different Y axes, such as a plot with a Y 2 axis on the right hand side.  In R adding a Y axis is very easy to do.  Here are two simple example scripts you can use to build off of.  The first two examples are two different ways of showing different scales for the same variable (i.e. temperature in Farenheit and Celsus).  The third example is two different variables overlaid on the same R plot with two Y axes used to show the scales of each variable.


Wednesday, March 26, 2014

Convert Word Document Field Codes into Formatted Text

Reference management software such as EndNote, Mendeley, etc. are great time savers when inserting citations in a manuscript typed in Microsoft Word.  Sometimes it is necessary to modify or remove the field codes these programs place in a document.  Situations include the need to edit some of the fields or submit a text-only article to a journal.  In these instances, these fields need to be removed and replaced with the appropriately formatted text.  How is this done?  Its incredibly easy...as long as you know the keyboard shortcut.  Here are the two simple steps:

(1) Select the text you want to remove the field codes from.  This can be done by highlighting a section of interest or pressing Ctrl + A if you want to replace the field codes in the entire document.

(2) Press Ctrl + Shift + F9.  This is the actual step that converts field codes into formatted text.

That's it.  You're done!  All your MS Word field codes in your .doc file should now be removed and the appropriate formatted text should be inserted in their place.  Hope this works for you as easily as it did for me.  If you find this post particularly helpful, please help me out by clicking the +1 link on the bottom of the post.

Friday, November 22, 2013

Install liftOver Locally on UNIX

Many of the UCSC genome tools are available for download for use locally on your UNIX system.  liftOver is an example of one such tool.  To download, go to their apps download page, select your operating system, and then click on the liftOver link.  Here are links for liftOver_linux.x86_64 and liftOver_linux.x86_64.v287.  For some reason, I could only get the linux.x86_64.v287 version to work on my system.  Once downloaded, make it executable.

The next step is to get the required chain files needed to convert from one genome build to another.  All UCSC genome builds are listed here and you can select the desired "LiftOver files" link under the genome build that you want to convert from.  This will take you to a downloads page with links to the chain files.  Chain files are appropriately named so you know what builds you are converting to and from.  For example,  hg19ToHg18.over.chain.gz is the chain file needed to convert from hg19 to hg18.  Once downloaded, unzip the file for use.

To run liftOver, the useage is:
liftOver oldFile map.chain newFile unMapped

where:
oldFile is the file you want to convert from
map.chain is the chain file used to convert from one build to another
newFile is the converted file you want to create
unMapped is a file that contains all the unmapped positions

For more details on usage, just type liftOver in the command line.

Wednesday, July 24, 2013

Converting Genotype Files to EIGENSTRAT format

Need to convert your genotyping files into EIGENSTRAT format?  Here is a quick primer to do so.  If you haven't already, download the EIGENSTRAT package and extract the contents.  We will be using the convertf tool to convert your genotypes to EIGENSTRAT format.  The convertf tool can convert to/from ANCESTRYMAP, EIGENSTRAT, PED, PACKEDPED, and PACKEDANCESTRYMAP files.

First, check to see if your convertf program is working out of the box by going to the /bin directory and typing in ./convertf.  Mine was not working (Error message:./convertf: /lib64/libc.so.6: version `GLIBC_2.7' not found (required by ./convertf)).  My quick fix was to try to recompile things based on the included C code, but going to the src directory and typing make convertf did not seem to do the trick.  Skimming through the README file I saw that you can remake the entire package by again going to the src directory and typing make clobber and then make convertf (the recommended make install produced errors on my system).  Typing ./convertf finally returned the "parameter p compulsory" output indicating the program is now working.  (Note: make clobber will remake the entire package and likely require you to remake other packages you need to use, ex: make mergeit, make eigenstrat, etc.).  I am not a UNIX guru, so if you know of a better way to get convertf running, please let me know in the comments.

Now that we have a running version of convertf, we can begin making a parameter file (ie: the par.PED.EIGENSTRAT file) for converting from one file format to another.  The included README file in the CONVERTF directory is instrumental for doing this.  Since .ped and .map files are ubiquitous, I will use this as an example to convert to EIGENSTRAT format.  Below is a parameter file to do so, but again converting to/from other formats is possible as well.


Finally, save this file as par.PED.EIGENSTRAT and run it by simply going into the directory with your working convertf program (mine was in the /EIG5.0/src directory) and put in the command ./convertf -p dir/par.PED.EIGENSTRAT, where dir is the directory your par.PED.EIGENSTRAT file is saved in.  You can essentially call the par.PED.EIGENSTRAT file any name, but this name meshes nicely with that in the samples that come with EIGENSTRAT.  Hope this is helpful, feel free to comment with questions.

Tuesday, July 16, 2013

Convert .PED and .MAP to and from .LDAT File Format

To run GLU, your data needs to be in the .ldat format.  Luckily, GLU makes it easy to convert from .ped and .map files to .ldat format with the transform command.  Here is how to carry out the transformation.

From .ped/.map → .ldat:

And likewise from .ldat → .ped/.map:

More details on the transform command can be found here.

Convert .GEN and .SAMPLE to and from .PED and .MAP File Format

A program called GTOOL can easily convert .gen and .sample files into .ped and .map files (as well as .ped and .map file format to .gen and .sample format).  The usage is quite simple.

For .gen/.sample → .ped/.map:

For .ped/.map → .gen/.sample: