<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Table of Contents
Iterative vs fragment-based mapping
Advantages of iterative mapping
Advantages of fragment-based mapping
Mapping
Iterative mapping
Fragment-based mapping
Iterative vs fragment-based mapping
Iterative mapping first proposed by <a name="ref-1"/>(Imakaev et al., 2012), allows to map usually a high number of reads. However other methodologies, less "brute-force" can be used to take into account the chimeric nature of Hi-C reads.
A simple alternative is to allow split mapping, just as with RNA-seq data.
Another way consists in pre-truncating <a name="ref-1"/>(Ay and Noble, 2015) reads that contain a ligation site and map only the longest part of the read <a name="ref-2"/>(Wingett et al., 2015).
Finally, an intermediate approach, fragment-based, consists in mapping full length reads first, and than splitting unmapped reads at the ligation sites <a name="ref-1"/>(Serra, Ba`{u, Filion and Marti-Renom, 2016).
Advantages of iterative mapping
It's the only solution when no restriction enzyme has been used (i.e. micro-C)
Can be faster when few windows (2 or 3) are used
Advantages of fragment-based mapping
Generally faster
Safer
Step1:  The full mapping function can be used to perform either iterative or fragment-based mapping, or a combination of both.
Iterative mapping
Here an example of use as iterative mapping
Step2:  And for the second side of the read
Step3:  Fragment-based mapping
With fragment based mapping it would be
<ASSISTANT_TASK:>
Python Code:
from pytadbit.mapping.full_mapper import full_mapping
Explanation: Table of Contents
Iterative vs fragment-based mapping
Advantages of iterative mapping
Advantages of fragment-based mapping
Mapping
Iterative mapping
Fragment-based mapping
Iterative vs fragment-based mapping
Iterative mapping first proposed by <a name="ref-1"/>(Imakaev et al., 2012), allows to map usually a high number of reads. However other methodologies, less "brute-force" can be used to take into account the chimeric nature of Hi-C reads.
A simple alternative is to allow split mapping, just as with RNA-seq data.
Another way consists in pre-truncating <a name="ref-1"/>(Ay and Noble, 2015) reads that contain a ligation site and map only the longest part of the read <a name="ref-2"/>(Wingett et al., 2015).
Finally, an intermediate approach, fragment-based, consists in mapping full length reads first, and than splitting unmapped reads at the ligation sites <a name="ref-1"/>(Serra, Ba`{u, Filion and Marti-Renom, 2016).
Advantages of iterative mapping
It's the only solution when no restriction enzyme has been used (i.e. micro-C)
Can be faster when few windows (2 or 3) are used
Advantages of fragment-based mapping
Generally faster
Safer: mapped reads are generally larger than 25-30 nm (the largest window used in iterative mapping). Less reads are mapped, but the difference is usually canceled or reversed when looking for "valid-pairs".
 Note:  We use GEM <a name="ref-1"/>(Marco-Sola, Sammeth, Guig\'{o and Ribeca, 2012), performance are very similar to Bowtie2, perhaps a bit better. 
For now TADbit is only compatible with GEM.
Mapping
End of explanation
r_enz = 'MboI'
! mkdir -p results/iterativ/$r_enz
! mkdir -p results/iterativ/$r_enz/01_mapping
# for the first side of the reads
full_mapping(gem_index_path='/media/storage/db/reference_genome/Homo_sapiens/hg38/hg38.gem',
             out_map_dir='results/iterativ/{0}/01_mapping/mapped_{0}_r1/'.format(r_enz),
             fastq_path='/media/storage/FASTQs/K562_%s_1.fastq' % (r_enz),
             r_enz='hindIII', frag_map=False, clean=True, nthreads=20,
             windows=((1,25),(1,30),(1,35),(1,40),(1,45),(1,50),(1,55),(1,60),(1,65),(1,70),(1,75)), 
             temp_dir='results/iterativ/{0}/01_mapping/mapped_{0}_r1_tmp/'.format(r_enz))
Explanation: The full mapping function can be used to perform either iterative or fragment-based mapping, or a combination of both.
Iterative mapping
Here an example of use as iterative mapping:
End of explanation
# for the second side of the reads
full_mapping(gem_index_path='/media/storage/db/reference_genome/Homo_sapiens/hg38/hg38.gem',
             out_map_dir='results/iterativ/{0}/01_mapping/mapped_{0}_r2/'.format(r_enz),
             fastq_path='/media/storage/FASTQs/K562_%s_2.fastq' % (r_enz),
             r_enz=r_enz, frag_map=False,  clean=True, nthreads=20,
             windows=((1,25),(1,30),(1,35),(1,40),(1,45),(1,50),(1,55),(1,60),(1,65),(1,70),(1,75)),
             temp_dir='results/iterativ/{0}/01_mapping/mapped_{0}_r2_tmp/'.format(r_enz))
Explanation: And for the second side of the read:
End of explanation
! mkdir -p results/fragment/$r_enz
! mkdir -p results/fragment/$r_enz/01_mapping
# for the first side of the reads 
full_mapping(gem_index_path='/media/storage/db/reference_genome/Homo_sapiens/hg38/hg38.gem',
             out_map_dir='results/fragment/{0}/01_mapping/mapped_{0}_r1/'.format(r_enz),
             fastq_path='/media/storage/FASTQs/K562_%s_1.fastq' % (r_enz),
             r_enz=r_enz, frag_map=True, clean=True, nthreads=20, 
             temp_dir='results/fragment/{0}/01_mapping/mapped_{0}_r1_tmp/'.format(r_enz))
# for the second side of the reads
full_mapping(gem_index_path='/media/storage/db/reference_genome/Homo_sapiens/hg38/hg38.gem',
             out_map_dir='results/fragment/{0}/01_mapping/mapped_{0}_r2/'.format(r_enz),
             fastq_path='/media/storage/FASTQs/K562_%s_2.fastq' % (r_enz),
             r_enz=r_enz, frag_map=True, clean=True, nthreads=20, 
             temp_dir='results/fragment/{0}/01_mapping/mapped_{0}_r2_tmp/'.format(r_enz))
Explanation: Fragment-based mapping
With fragment based mapping it would be:
End of explanation
<END_TASK>