TITLE: Gapclosing metagenomic islands
AUTHORS: Chris Bellas

[DESCRIPTION]
<div class = "text-blocks"><div class = "text-block">This protocol allows gapclosing of metagenomic islands which occur when mapping metagenomic reads to a phage reference genome. These gaps arise because multiple gene variants co-exist for specific points on the genome, these variants fluctuate in dominance over space and time. This means mapping metagenomic reads from one location onto a phage reference genome from another will often result in multiple metagenomic islands. These gaps can be closed with the following protocol, allowing the other gene variants present in a phage pan-genome to be detected. </div><div class = "text-block">The protocol relies on detection of the same phages in similar ecosystems and relies on the phage being sequenced to sufficient depth in each sample to allow metagenomic assembly of large contigs (>10 X coverage). </div><div class = "text-block">Prerequisites:</div><div class = "text-block"><span style = "font-style:italic;">Bowtie2</span></div><div class = "text-block"><span style = "font-style:italic;">Geneious software package</span></div><div class = "text-block"><span style = "font-style:italic;">SPAdes assembler </span></div><div class = "text-block"><span style = "font-style:italic;">Blast+ tools </span></div></div>

[STEPS]
?. 1) Map metagenomic reads to virus reference contigStarting with an assembled phage contig  (phage_reference_contig.fasta).  i) Map trimmed, unassembled reads from a different metagenome (Query metagenome) to this reference using Bowtie2Bowtie2 -I 0 -X 800 --no-unal --very-sensitive -1 Query_metagenome_R1.fastq -2 Querymetagenome_R2.fastq -S samfile.sam( -I 0 and -X 800 refer to the min and max size of the paired end reads+insert before they are flagged as discordant. --no-unal keeps the files small and discards all reads that do not map to the contig. -1 and -2 are the forward [R1] and reverse [R2] reads from the metagenome)1b) Import samfile into Geneiousi) File> Import> From file Metagenomic islands should be visible as gaps in the read mapping where reads possess ii) Generate a majority consensus sequence Right click on the filename > Generate consensus sequenceSettings: 0% Majority (this selects the most frequently occurring base at a specific genome position)If no coverage call: Ref (the calls the reference genome through the MGI gaps)Do not trim the sequence.  file will be generated for this metagenome. MGI gaps will be plugged with the reference genome temporarily.iii) Export the consensus as a fasta file File > Export > Selected Documents is the exported fasta file.
?. Assemble the query metagenome Using SPAdes, CLC or another favorite assembler:i) Assemble the metagenomic reads into contigs. (This should allow large sections of the target genome to be assembled in the query metagenome. Many of these contigs should cross and include the MGI regions shown in Fig. 2. We next need to find them).Output:  (Fasta contigs from the metagenomic assembly)
?. Locate assembled contigs that belong the target virus genomeUsing blast we will find virus contigs which might belong to the target virus from Fig. 2. i) Blast all metagenomic contigs against the virus consensus and pick matching reads.We will only pick matching reads over 150bp. The following shell script can be copied and pasted into a file Phising.shUse the command ./Phising.sh Consensus.fasta Assembled_query.fasta (replaces with your filenames)Use the following to make it executable: chmod +x Phising.sh ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#Phising.sh#Blasts denovo assembly (Assembled_query.fasta) against virus genome (Consensus.fasta) then picks all results >150bp as fasta files (E-value cut off 10-5).#Usage ./Phishing.sh  makeblastdb -dbtype nucl -in $1blastn -query $2 -db  $1  -evalue 0.00001 -num_threads 4 -outfmt 6 -out  $2_blastn_$1#Generate results list for matchesawk ' $4>=150  {print $1"@"}' $2_blastn_$1 >$2_blastn_$1_phishing_list#Pick matching fasta entires from Assembled_query.fastatr '\n' '@' /\n>/g'| grep -f $2_blastn_$1_phishing_list| tr '@' '\n' >$2_blastn_$1_phishes#Remove ambigous bases (N's) from matching contigs as they hinder future alignment tr -d "N" $2_blastn_$1_phishes_NoN.fasta#*phishes_NoN.fasta is file of matching fasta records
?. Align assmbled contigs onto the virus reference genomei) Import *phishes_NoN.fasta> into Geneious. File > Import > From fileii) In Geneious, select both Consensus.fasta and *phishes_NoN.fasta then click "Map to Reference" and ensure Consensus.fasta is set as reference. Settings:Set Sensitivity to Custom SensitivityFine Tuning: None (fast / read mapping)In the Advanced settings set: Allow gaps, Maximum Per Read: 50 %, Word Length: 10Maximum Mismatches Per Read: 50%Accurately map reads with errors to repeat regions: Map multiple best matches: RandomlyMaximum Gap Size: 4000Index Word Length: 10Maximum Ambiguity: 16
?. Generate majority consensus from resulting mapping filei) Geneious: Right click on alignment > General consensus Settings:0% Majority (Calls majority base for each position)If no coverage call: Reference (calls reference genome if still no coverage)Do not trim sequenceThis will generate the majority consensus (most frequently occurring base for each location in the genome) and cell the original reference if there is still no coverage.  Output
?. Iteratively map unassembled reads back to working_virus_consensus.fasta to close any leftover gapsi ) Import unassembled forward and reverse reads into Geneious File > Import > Query_metagenome_R1.fastqFile > Import > Query_metagenome_R2.fastqii) Link the paired reads in GeneiousSequence > Set paired readsSelect the imported paired metagenomic reads and working_virus_consensus.fasta then:Align/Assemble > Map to referenceSettings:Reference: working_virus_consensus.fastaSensitivity: Medium-Low Sensitivity / FastFine Tuning: Iterate up to 25 times (or more until gaps are closed)This will map all metagenomic reads to the contig, extending any ambiguous regions, then iterate the process.
?. Extract reads and reassemble the contig de novoi ) View the read mapping file in Geneious and click in the mapped reads to highlight one. Press Ctrl A  to select all readsii) Right click (on the read mappings) > Extract RegionsConfirm you want to extract them as a list of sequences. This generates a file with all mapped reads, paired and unpaired, and two consensus genomes. iii) Delete the consensus and reference genomes to leave only the unassembled readsii) De novo assemble the contigs agian (Either in Geneious or export the reads to a favorite assembler)Align/Assemble > De novo Assemble: Settings:Assembler: GeneiousSensitivity: High SensitivityThe virus genome should be reassembled into 1 or more large contigs which should read accross the MGI regions and allow the new gene variants to be detected.
?. Align whole genomes using Mauve/MUSCLE to compare MGI regions. Or extract MGI regions manually and align.