Description:

  • This notebook goes through the plotting of CRISPR loci

Before running this notebook:

User-defined variables


In [1]:
# directory where you want the spacer blasting to be done
## CHANGE THIS!
workDir = "/home/nyoungb2/t/CLdb_Methanosarcina/loci_plots/"

Init


In [2]:
import os
from IPython.display import Image

In [3]:
if not os.path.isdir(workDir):
    os.makedirs(workDir)

In [4]:
# checking that CLdb is in $PATH & ~/.CLdb config file is set up
!CLdb --config-params


#-- Config params --#
DATABASE = /home/nyoungb2/t/CLdb_Methanosarcina/CLdb.sqlite

Plotting loci

  • As with arrayBlast, plotLoci has subcommands of it's own

In [5]:
!CLdb -- plotLoci -h


Usage:
    plotLoci [options] subcommand -- [subcommand_options]

  Options:
    --list
        List all subcommands.

    --perldoc
        Get perldoc of subcommand.

    -v Verbose output
    -h This help message

  For more information:
    CLdb --perldoc -- plotLoci


In [6]:
!CLdb -- plotLoci --list


format_dna_segs_colors
make_comparison
make_dna_segs
make_xlims
order_by_tree
prune_tree
rotate_tree
run

Basics on how a plot is made

  • Note: some steps are optional (like mapping loci plots to a tree)
  1. Make a table of spacer/DR sequence locations & other info.
    • A 'dna_segs' table
  2. [optional] order the table by a tree file
  3. [optional] add color info to the table
  4. Make a table of the range limits for each locus.
    • ie., the start & stop positions of each plot
    • An 'xlims' table
  5. [optional] order the table by a tree file.
  6. Make a comparison file to compare sequence similarity among loci.
    • A 'compare' table
  7. Feed all of the tables into an R script for making the figure.

Making the plot

dna_segs table


In [15]:
# making table
!cd $workDir; \
    CLdb -- plotLoci -- make_dna_segs > dna_segs.txt
    
# checking output
!cd $workDir; \
    echo; \
    head -n 5 dna_segs.txt


WARNING: no ITEP db provided! All genes will have col value of '1'!
WARNING: no matching entries in leaders table! Leaders not added to dna_segs table!
...Found multiple loci for 1 or more taxa. Adding loci_ids to names in dna_segs table!
...Found multiple subtypes. Adding subtype to names in dna_segs table!

name	start	end	strand	col	lty	lwd	pch	cex	gene_type	taxon_name	locus_id	feat	feat_id	subtype	dna_segs_id
9	800384	800419	1	759	1	0.5	8	1	blocks	Methanosarcina_mazei_LYC	14	spacer	9	NA	Methanosarcina_mazei_LYC__14__NA
32	802055	802092	1	225	1	0.5	8	1	blocks	Methanosarcina_mazei_LYC	14	spacer	32	NA	Methanosarcina_mazei_LYC__14__NA
25	801549	801585	1	608	1	0.5	8	1	blocks	Methanosarcina_mazei_LYC	14	spacer	25	NA	Methanosarcina_mazei_LYC__14__NA
14	800751	800788	1	318	1	0.5	8	1	blocks	Methanosarcina_mazei_LYC	14	spacer	14	NA	Methanosarcina_mazei_LYC__14__NA

Ordering dna_segs by tree


In [17]:
# making table
!cd $workDir; \
    CLdb -- plotLoci -- order_by_tree \
        -tree Methanosarcina.nwk \
        < dna_segs.txt \
        > dna_segs_ord.txt
    
# checking output
!cd $workDir; \
    echo; \
    head -n 3 dna_segs_ord.txt


Editted tree written: Methanosarcina_edit.nwk

name	start	end	strand	col	lty	lwd	pch	cex	gene_type	taxon_name	locus_id	feat	feat_id	subtype	dna_segs_id
64	894719	894754	1	727	1	0.5	8	1	blocks	Methanosarcina_mazei_C16	9	spacer	64	I-B	Methanosarcina_mazei_C16__9__I-B
31	892324	892358	1	950	1	0.5	8	1	blocks	Methanosarcina_mazei_C16	9	spacer	31	I-B	Methanosarcina_mazei_C16__9__I-B

Adding coloring info


In [18]:
# making table
!cd $workDir; \
    CLdb -- plotLoci -- format_dna_segs_colors \
    < dna_segs_ord.txt \
    > dna_segs_ord_col.txt
    
# checking output
!cd $workDir; \
    echo; \
    head -n 3 dna_segs_ord_col.txt


name	start	end	strand	col	lty	lwd	pch	cex	gene_type	taxon_name	locus_id	feat	feat_id	subtype	dna_segs_id
8	890620	890657	1	#000000	1	0.1	8	1	blocks	Methanosarcina_mazei_C16	9	directrepeat	8	I-B	Methanosarcina_mazei_C16__9__I-B
28	892069	892106	1	#000000	1	0.1	8	1	blocks	Methanosarcina_mazei_C16	9	directrepeat	28	I-B	Methanosarcina_mazei_C16__9__I-B

xlims table


In [19]:
# making table
!cd $workDir; \
    CLdb -- plotLoci -- make_xlims > xlims.txt
    
# checking output
!cd $workDir; \
    echo; \
    head -n 5 xlims.txt


...Found multiple loci for 1 or more taxa. Adding leaves to the tree! Adding loci_ids to leaves & xlims table!
...Found multiple subtypes. Adding subtype to names in tree & xlims table!

start	end	taxon_name	locus_id	subtype	dna_segs_id
890817	903201	Methanosarcina_mazei_WWM610	20	I-B	Methanosarcina_mazei_WWM610__20__I-B
1610239	1627817	Methanosarcina_mazei_WWM610	19	III-B	Methanosarcina_mazei_WWM610__19__III-B
889926	906212	Methanosarcina_mazei_S_6	15	I-D	Methanosarcina_mazei_S_6__15__I-D
1620118	1634344	Methanosarcina_mazei_S_6	16	III-C	Methanosarcina_mazei_S_6__16__III-C

Ordering by tree


In [20]:
# making table
!cd $workDir; \
    CLdb -- plotLoci -- order_by_tree \
        -tree Methanosarcina.nwk \
        < xlims.txt \
        > xlims_ord.txt
    
# checking output
!cd $workDir; \
    echo; \
    head -n 3 xlims_ord.txt


Editted tree written: Methanosarcina_edit.nwk

start	end	taxon_name	locus_id	subtype	dna_segs_id
3296823	3309235	Methanosarcina_mazei_C16	10	III-B	Methanosarcina_mazei_C16__10__III-B
880835	895591	Methanosarcina_mazei_C16	9	I-B	Methanosarcina_mazei_C16__9__I-B

Comparisons table


In [21]:
# making table
!cd $workDir; \
    CLdb -- plotLoci -- make_comparison < dna_segs_ord_col.txt


...WARNING: no ITEP db provided ('-i')! No blastp information will be included!
### Getting spacer clusters ###
start1	end1	start2	end2	col	dna_segs_id1	dna_segs_id2	feat	feat_id	sfeat_id

making figure


In [24]:
!cd $workDir; \
    CLdb -- plotLoci -- run \
    -d dna_segs_ord_col.txt \
    -x xlims_ord.txt \
    -t Methanosarcina_edit.nwk \
    -f png \
    -o all_loci


Read 1 item
Loci plot written: "all_loci"
null device 
          1 

In [25]:
pngFile = os.path.join(workDir, 'all_loci.png')
Image(filename=pngFile)


Out[25]: