Cbcb:Pop-Lab:16S-pipeline 16S analysis pipeline (for Gates project)
16S analysis pipeline
Assumptions:
- 16S rRNA sequences are generated with barcoded 454 and are received as either: (i) .sff file; (ii) fasta and quality file; (iii) just fasta file
- each batch is a single 96-well plate and is accompanied by a tab-delimited file containing information about the sample, including the "Sample ID", well on the plate, and additional information regarding the sample quality and DNA concentration
- we have a file that specifies the barcode and sequencing adapter used for each well (these entities do not change).
Directory structure
Gates_SOM/ Main/ samples.csv - information about all the samples available to us 454.csv - information about all 454 runs (essentially concatenation of .csvs from 454 dir) phylochip.csv - information about all Phylochip runs IGS_Barcodes.csv - information about barcodes used to multiplex 454 runs scripts/ - scripts used to process the data 454/ - here's where all 454 sequences live [batch1]/ - ... each batch in a separate directory [batch1].csv - meta-information about the batch [fasta1]- fasta files containing the batch ... [fastan] [batch1].part - partition file describing how the sequences get split by barcode/sample part/ - directory where all the partitioned files live ... [batchn] Phylochip/ - all the CEL files and auxiliary information on the Phylochip runs
Step 0: Get the sequence information
- From .SFF files (assuming these are 454 sequences)
This step uses the sff_extract program from the Staden package (if I'm not mistaken)
for i in *.sff ;do name=`expr $i : '\(.*\)\.sff'` sff_extract -c -s $name.seq -q $name.qual $i done
Step 1: Cleanup meta-information
- Convert the Excel sheet containing the batch information into tab-delimited file (and run dos2unix) making sure the quotes added by Excel/OOffice are removed, adding the date (if not already in the file), and sorting the file by Sample ID. At this stage also check that the header row information is in canonical format.
- Add barcode information using add_barcode.pl
${SCRIPTDIR}/add_barcode.pl [batch].csv ${MAINDIR}IGS_Barcodes.csv > [batch]_barcode.csv
Step 2: Create partition file
First concatenate all the sequence files (if multiple) from a batch into a single file [batch].all.seq.
${SCRIPTDIR}/code2part.pl [batch].csv [batch].all.seq [batch] > [batch].part
The files [batch].BAD.list and [batch].NONE.list contain the names of all sequences that have failed quality checks either because they are too short, or contain Ns (BAD), or because the barcode is not recognized (NONE). The files contain additional information that can be used to troubleshoot the pipeline: sequences that are too short (< 75 454 cycles) are followed by the number of cycles, sequences that either contain Ns or have an unknown barcode are followed by the first 8 characters in the sequence.
Step 3: Break up the fasta file into separate batches by partition
- Create partition directory
mkdir part cd part
- Partition main file into sub-parts
${SCRIPTS}/partitionFasta.pl ../[batch].all.seq ../[batch].part
The result is one fasta file per sub-partition (i.e. individual subject).
- Remove barcodes
(still in the part/ subdirectory)
for i in *.seq; do ${SCRIPTS}/unbarcode.pl $i done
The output files will have the same name as the original file but with the addition of the .nbc suffix. You should remove the .nbc files from the BAD/NONE files in order to prevent their addition to the pipeline downstream.
rm *.BAD.nbc.fa *.NONE.nbc.fa
Step 4: Add file names to sample tables
The following needs to be run from the root of the 454 directory.
${SCRIPTS}/add_file.pl [batch]/[batch]_barcode.csv [batch]/part > [batch]/[batch]_names.csv
As a result, the file [batch]/[batch]_names.csv will associate each Sample ID to a file name and also record the number of sequences in that file. Note that only files ending in .nbc.fa are procesed.
Step 5: Merge all the batch meta-info files into a same file at the top
Note: the addition of file names must be done on a batch by batch basis as multiple files might refer to a same Sample ID - within each batch it can be assumed that the Sample ID -> Filename mapping is unique. In the 454.csv file in the top directory the unique key is the file name.
mv ../454.csv ../454.csv.bak ${SCRIPTS}/merge_csv.pl ../454.csv.bak [batch]/[batch]_names.csv "Sample ID" non-unique > ../454.csv
This should probably be run with the filename as the key but then the tables need to be sorted by filename. Ultimately, this will all work better once the data are in a relational database.
Step 6: Update sample file
From the top directory:
- First add all new samples to the samples.csv file
mv samples.csv samples.csv.bak ${SCRIPTS}/merge_csv.pl samples.csv.bak 454.csv "Sample ID" unique merge > samples.csv
Note: merge means that if record keys conflict, the empty fields will be updated with the new data.
- Update the tag indicating 454 sequences available for this sample
mv samples.csv samples.csv.bak ${SCRIPTS}/update_field_csv.pl samples.csv.bak 454.csv "Sample ID" 454 Y > samples.csv
Step 7: Assign numbers to all filenames
Each file in the 454.csv file will be assigned an integer (if one is not already available). This number will be used to prefix the sequences in the combined file for the project.
mv 454.csv 454.csv.bak ${SCRIPTS}/add_filenum.pl 454.csv.bak > 454.csv
Step 8: Combine all fasta files into a single one
Note: this assumes we're running the pipeline for the first time - a different protocol is necessary for adding new sequences to an already existing analysis
In the new file all sequences will be named <n>_<nn> where <n> is the value in the "File #" field in 454.csv and <nn> is the index of the sequence in the file.
mkdir Analysis/Run[date] ${SCRIPTS}/combinefa.pl -c Analysis/Run[date]/Run[date] -i 454.csv 454
The output will be in Analysis/Run[date]/Run[date].fna
Step 9: Run clustering tool
- First generate clusters
cd Analysis/Run[date]/Run[date].fna /fs/szasmg2/ghodsi/Src/clusterk/clusterk7 -r 2 -i Run[date].fna > Run[date].fna.clusters
Output will be in Run[date].fna.clusters, one cluster per line, cluster center listed as the first identifier.
- Then extract the cluster centers
/fs/szasmg2/ghodsi/Src/clusterk/fastaselect Run[date].fna < Run[date].fna.clusters > Run[date].centers.fna
Step 10: Assign putative taxonomic labels to clusters
/fs/szasmg2/ghodsi/rdp/findtax/findtaxid.sh Run[date].centers.fna > Run[date].centers.taxid
Output is tab-delimited: sequence name <TAB> taxid Note: using "findtax" instead of "findtaxid" will retrieve actual taxonomy names.
Step 11: Build summary tables
Using the output from steps 9 and 10 we construct a collection of tables linking OTUs, taxIDs, taxnames at various taxonomic levels to individual samples. The colums are the samples and the rows are the respective units. The cells are numbers of sequences assigned to the specific group. If looking at taxonomic levels, the sequences without an assignment at that level are assigned to a generic "No Assignment" bin.