Showing posts with label Bioinformatics. Show all posts
Showing posts with label Bioinformatics. Show all posts

September 20, 2024

How to get MD5 checksums to detect data corruption (for bioinformatics data curation)

What are MD5 checksums? Checksums are nonsense text strings used to "summarize" a file version. No matter the size of the file (1 kb or 30 GB), the checksum algorithm gives you a conveniently short nonsense string of letters and numbers. The exact same file will give you the exact same checksum every time. If you change a single character or pixel, you will get a different checksum.

MD5 is a specific popular algorithm to get checksums.

Why use checksums? The purpose of checksums is to notice data corruption, especially when downloading files from or uploading files to a server. Every time you transfer files between computers, there is risk of data corruption. For small files, the risk is small and you'll most likely notice, for example if your email attachment download fails due to an internet interruption. 

For large files such as raw sequencing data files, it's a bigger issue and you might not notice right away (or ever) if the last few RNA-seq reads of a >30 million reads file are missing. Therefore, the best practice when downloading new sequencing is to create MD5 checksums yourself and compare them with the MD5 checksum created by the originating computer (the sequencing core's server). They should be the same. If not, something went wrong during file transfer! Try re-downloading the data.

Similarly, when you upload sequencing data to a public repository (e.g. NCBI GEO), you provide MD5 checksums so that the receivers (NCBI's data curators) can confirm the upload was successful.

How to get an MD5 checksum for an individual file? See example below using the Linux terminal. I created a text file containing only the phrase "hello pretend this is sequencing data". The checksum for that file is "b088d8d4d1d831af2d8d16147389aa7d". If I change the first letter to uppercase, the checksum completely changes.

 

March 29, 2023

How to pick random samples from a list with Excel

Scenario: You have a list of 50 samples per group that meet criteria for your RNA-seq study, but you only want to sequence 20 per group. How do you randomly pick 20 per group? Also, how do you randomly order them for sequencing?

Random selection with Excel:

  1. In your spreadsheet with all eligible samples, have a column for each sample's group (e.g. IVF, NIFT, Spontaneous; Female, Male; Overweight, Normal, Underweight; et cetera). It needs to be a categorical variable, not discrete or continuous numbers.
  2. Add a new column and label it "RandomNum"
  3. Fill the "RandomNum" column with =RAND() and press enter to generate random numbers
  4. Copy the "RandomNum" column and re-paste as values to remove the formula, otherwise it re-calculates each time you open the spreadsheet
  5. Sort by the random number, then the group, and pick 20 from each group that way
  6. Make a new column "Include" and fill in yes/no

Make the final selection:

  1. Check criteria demographics of your randomly selected groups. Swap out Include=yes and Include=no samples if needed to fix any obvious imbalances or remove obvious outliers. For example, when comparing fetal sex, we try to also balance fetal race. Another example: if the maternal age range is 30-40 in one group, and similar in the other group except for one outlier age 23, we may swap that outlier for a different subject.
  2. Don't balance demographics that might be related to your study variable (and keep in mind you don't always know which are related). For example, for our study of infertility looking at IVF and non-IVF treatment subgroups, the non-IVF treatment group had a higher BMI than both the IVF and the no treatment control group. We did not balance for BMI because anything metabolic can be related to fertility. 
  3. Don't balance outcome demographics. For example, for our study of first trimester placenta gene expression, we tried to balance fetal sex and gestational age at first trimester sampling time, but we did not balance birth weight because that is a study outcome (appears after our first trimester sampling timepoint). In fact, males tend to be heavier than females at birth. 

Random order with Excel:

  1. Sort the spreadsheet by the random number again and then sort by column "Include" so you have all the Include=yes samples together
  2. Make a new column "Order" and fill in with 1,2,3,4,5,...,38,39,40 (example assuming two groups of 20) to randomize the order of the samples for sequencing

November 22, 2022

Advice: Raw data storage for bioinformatics (terabytes of data)

Good habits and advice

  • Download sequencing data from the sequencing core or company within 30 days of receiving it. They won't store it forever! 
  • Keep multiple copies of your important data.
  • Don't open your original results spreadsheet files with Excel - make copies specifically to open with Excel to avoid autosaving corrupted or filtered data. Beware the Excel calendar issue with gene names.
  • Always eject or unmount data drives to prevent data corruption. Do this before you unplug them physically.
  • Check MD5 checksums. This helps you detect data corruption during downloads, storage, uploads, etc. If you find a mismatch, you can re-download or re-upload to correct it.

Drive formatting

January 5, 2021

DNA methylation: Illumina methylation array annotation sources

Here I list of available resources and annotation files for Illumina methylation arrays to measure cytosine nucleotide DNA methylation.

There are three different probeType column values: "cg", "ch", "rs"

  • "cg" - CpG sites, the most common DNA methylation sites
  • "ch" - CpH sites (where the C base is followed by something other than a G base, H=A,T,C). Rare methylation sites. They are slightly more common in stem cells, but still not as common as CpG sites.
  • "rs" - methylation sites that overlap single nucleotide polymorphisms (SNPs). These should be excluded from most analysis.
  • If you don't have the probeType column in your data, you can identify these sites by searching the probeID prefixes, for example: grepl("^cg", df$probeID) is a regular expression for R programming that will return a column of TRUE/FALSE depending on the text values in column df$probeID. The caret symbol (^) in "^cg" means that the text match needs to be at the beginning to be TRUE. An example probeID that would return TRUE is "cg07881041". 

Official Illumina manifest files for methylation arrays

A "manifest" is a list of all items (sometimes samples, in this case methylation probes) and information about them. Illumina provides manifests for each of their methylation arrays with information such as probeID, probe type, probe chemistry details, chromosome position, and associated genes.  

Infinium MethylationEPIC BeadChip (>860k sites)
  • Annotation files (Infinium MethylationEPIC Product Files, get the "manifest" files)
  • Infinium MethylationEPIC v1.0 B5 Manifest File (CSV Format), Mar 13, 2020
  • GRCh36, GRCh37, and GRCh38 human reference genomes
  • See annotation website for pdf explaining each annotation column

  • Annotation files (Infinium HumanMethylation450K v1.2 Product Files, get the "manifest" files)
  • HumanMethylation450K v1.2 Manifest File (CSV Format), May 23, 2013
  • GRCh36 and GRCh37 human reference genomes

September 14, 2020

How to download FASTA files from NCBI

FASTA format

FASTA files are text files used to store sequence information. The format is 2 lines of text:

>title line starting with a greater-than sign

sequence with no double line breaks or special characters


FASTA file extensions are usually .fasta or .fa but can also be .txt because, either way, they are just text files. Open them as text files with Notepad. For large sequences, Notepad++ works better (more memory allocation). Word or any other text file reader will work as well.

September 13, 2020

How to BLAST a gene of interest (starting from the gene symbol)

 This is assuming you are starting from a gene symbol and don't have the sequence or accession ID yet. 


Step 1: search for your gene in NCBI's databases

Start with either NCBI Nucleotide or NCBI Gene. 

Search results for noncoding gene "XIST" in NCBI Gene, then clicking the "+" to expand the "RefSeq Sequences" section:


Luckily, there is only 1 reference transcript for XIST. For genes with several transcripts, either continue with all or pick some based on another criteria (e.g. which one is longest, which ones code for protein, which one is suggested as "RefSeq Select" or "canonical").

R programming lesson #2: merging pdf files

Use R package "pdftools" to merge separate pdf into one pdf file. You will never need to use sketchy websites or pay for software ...