code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
if not HAVE_MPL: # pragma: no cover raise RuntimeError('matplotlib not available.') cmap = LinearSegmentedColormap.from_list(self.name, self.mpl_colors, **kwargs) return cmap
def get_mpl_colormap(self, **kwargs)
A color map that can be used in matplotlib plots. Requires matplotlib to be importable. Keyword arguments are passed to `matplotlib.colors.LinearSegmentedColormap.from_list`.
4.205011
4.08694
1.02889
from ipythonblocks import BlockGrid grid = BlockGrid(self.number, 1, block_size=block_size) for block, color in zip(grid, self.colors): block.rgb = color grid.show()
def show_as_blocks(self, block_size=100)
Show colors in the IPython Notebook using ipythonblocks. Parameters ---------- block_size : int, optional Size of displayed blocks.
6.412446
6.653701
0.963741
url = 'http://colorbrewer2.org/index.html?type={0}&scheme={1}&n={2}' return url.format(self.type.lower(), self.name, self.number)
def colorbrewer2_url(self)
URL that can be used to view the color map at colorbrewer2.org.
2.987949
2.848918
1.048802
from jcvi.formats.fasta import summary as fsummary from jcvi.utils.cbook import percentage, human_size p = OptionParser(summary.__doc__) opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.print_help()) chainfile, oldfasta, newfasta = args chain = Chain(chainfil...
def summary(args)
%prog summary old.new.chain old.fasta new.fasta Provide stats of the chain file.
2.761256
2.488626
1.109551
from jcvi.formats.agp import AGP from jcvi.formats.sizes import Sizes p = OptionParser(fromagp.__doc__) p.add_option("--novalidate", default=False, action="store_true", help="Do not validate AGP") opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.p...
def fromagp(args)
%prog fromagp agpfile componentfasta objectfasta Generate chain file from AGP format. The components represent the old genome (target) and the objects represent new genome (query).
2.717917
2.485977
1.093299
p = OptionParser(blat.__doc__) p.add_option("--minscore", default=100, type="int", help="Matches minus mismatches gap penalty [default: %default]") p.add_option("--minid", default=98, type="int", help="Minimum sequence identity [default: %default]") p.set_cpus() ...
def blat(args)
%prog blat old.fasta new.fasta Generate psl file using blat.
3.308975
3.131968
1.056516
from jcvi.formats.sizes import Sizes p = OptionParser(frompsl.__doc__) opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.print_help()) pslfile, oldfasta, newfasta = args pf = oldfasta.split(".")[0] # Chain together alignments from using axtChain chainfile...
def frompsl(args)
%prog frompsl old.new.psl old.fasta new.fasta Generate chain file from psl file. The pipeline is describe in: <http://genomewiki.ucsc.edu/index.php/Minimal_Steps_For_LiftOver>
2.937448
2.777003
1.057776
atoms = row.strip().split("\t") name1, name2, coverage, identity, nmismatch, ngap, \ start1, end1, strand1, start2, end2, strand2, score = atoms identity = identity.replace("%", "") hitlen = coverage.split("/")[1] score = float(score) same_strand = (strand1 == strand2) if no...
def lastz_to_blast(row)
Convert the lastz tabular to the blast tabular, see headers above Obsolete after LASTZ version 1.02.40
3.589094
3.519085
1.019894
bfasta_fn, afasta_fn, outfile, lastz_bin, extra, mask, format = t ref_tags = [Darkspace] qry_tags = [Darkspace] ref_tags, qry_tags = add_mask(ref_tags, qry_tags, mask=mask) lastz_cmd = Lastz_template.format(lastz_bin, bfasta_fn, ref_tags, \ afa...
def lastz_2bit(t)
Used for formats other than BLAST, i.e. lav, maf, etc. which requires the database file to contain a single FASTA record.
4.34037
4.445572
0.976336
p = OptionParser(main.__doc__) supported_formats = tuple(x.strip() for x in \ "lav, lav+text, axt, axt+, maf, maf+, maf-, sam, softsam, "\ "sam-, softsam-, cigar, BLASTN, BLASTN-, differences, rdotplot, text".split(',')) p.add_option("--format", default="BLASTN-", choices=supported_fo...
def main()
%prog database.fa query.fa [options] Run LASTZ similar to the BLAST interface, and generates -m8 tabular format
4.698961
4.608009
1.019738
p = OptionParser(augustus.__doc__) p.add_option("--species", default="maize", help="Use species model for prediction") p.add_option("--hintsfile", help="Hint-guided AUGUSTUS") p.add_option("--nogff3", default=False, action="store_true", help="Turn --gff3=off") ...
def augustus(args)
%prog augustus fastafile Run parallel AUGUSTUS. Final results can be reformatted using annotation.reformat.augustus().
3.82969
3.634778
1.053624
p = OptionParser(star.__doc__) p.add_option("--single", default=False, action="store_true", help="Single end mapping") p.set_fastq_names() p.set_cpus() opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) folder, reference = args ...
def star(args)
%prog star folder reference Run star on a folder with reads.
3.29791
3.177873
1.037773
p = OptionParser(cufflinks.__doc__) p.add_option("--gtf", help="Reference annotation [default: %default]") p.set_cpus() opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) folder, reference = args cpus = opts.cpus gtf = opts.gtf transcripts ...
def cufflinks(args)
%prog cufflinks folder reference Run cufflinks on a folder containing tophat results.
2.506116
2.454472
1.021041
from jcvi.apps.bowtie import check_index from jcvi.formats.fastq import guessoffset p = OptionParser(tophat.__doc__) p.add_option("--gtf", help="Reference annotation [default: %default]") p.add_option("--single", default=False, action="store_true", help="Single end mapping") ...
def tophat(args)
%prog tophat folder reference Run tophat on a folder of reads.
2.595776
2.542535
1.02094
from scipy.stats import hmean return int(round(hmean(np.clip(a, a_min, a_max))))
def hmean_int(a, a_min=5778, a_max=1149851)
Harmonic mean of an array, returns the closest int
3.125829
2.778952
1.124823
counts = np.zeros(BB, dtype=int) for x in a: c = int(round(math.log(x, phi))) if c < lb: c = lb if c > ub: c = ub counts[c - lb] += 1 return counts
def golden_array(a, phi=1.61803398875, lb=LB, ub=UB)
Given list of ints, we aggregate similar values so that it becomes an array of multiples of phi, where phi is the golden ratio. phi ^ 14 = 843 phi ^ 33 = 7881196 So the array of counts go between 843 to 788196. One triva is that the exponents of phi gets closer to integers as N grows. See interest...
3.142025
3.56808
0.880593
from .chic import score_evaluate_M t, stour, tour_score, active_sizes, M = arg stour_score, = score_evaluate_M(stour, active_sizes, M) delta_score = tour_score - stour_score log10d = np.log10(delta_score) if delta_score > 1e-9 else -9 return t, log10d
def prune_tour_worker(arg)
Worker thread for CLMFile.prune_tour()
8.218111
8.308777
0.989088
p = OptionParser(heatmap.__doc__) p.add_option("--resolution", default=500000, type="int", help="Resolution when counting the links") p.add_option("--chr", help="Plot this contig/chr only") p.add_option("--nobreaks", default=False, action="store_true", help="Do not...
def heatmap(args)
%prog heatmap input.npy genome.json Plot heatmap based on .npy data file. The .npy stores a square matrix with bins of genome, and cells inside the matrix represent number of links between bin i and bin j. The `genome.json` contains the offsets of each contig/chr so that we know where to draw boundary ...
3.945331
3.710479
1.063294
p = OptionParser(mergemat.__doc__) p.set_outfile(outfile="out") opts, args = p.parse_args(args) if len(args) < 1: sys.exit(not p.print_help()) npyfiles = args A = np.load(npyfiles[0]) logging.debug("Load `{}`: matrix of shape {}:; sum={}" .format(npyfiles[0],...
def mergemat(args)
%prog mergemat *.npy Combine counts from multiple .npy data files.
3.029465
2.747011
1.102822
import pysam bamfile = pysam.AlignmentFile(bamfile, "rb") seqsize = {} for kv in bamfile.header["SQ"]: if kv["LN"] < 10 * N: continue seqsize[kv["SN"]] = kv["LN"] / N + 1 allseqs = natsorted(seqsize.keys()) allseqsizes = np.array([seqsize[x] for x in allseqs]) ...
def get_seqstarts(bamfile, N)
Go through the SQ headers and pull out all sequences with size greater than the resolution settings, i.e. contains at least a few cells
2.790582
2.814774
0.991405
b = np.ones(bins, dtype="float64") b[0] = 100 for i in range(1, bins): b[i] = b[i - 1] * ratio bins = np.around(b).astype(dtype="int") binsizes = np.diff(bins) return bins, binsizes
def get_distbins(start=100, bins=2500, ratio=1.01)
Get exponentially sized
3.037666
3.003142
1.011496
p = OptionParser(simulate.__doc__) p.add_option("--genomesize", default=10000000, type="int", help="Genome size") p.add_option("--genes", default=1000, type="int", help="Number of genes") p.add_option("--contigs", default=100, type="int", help="Num...
def simulate(args)
%prog simulate test Simulate CLM and IDS files with given names. The simulator assumes several distributions: - Links are distributed uniformly across genome - Log10(link_size) are distributed normally - Genes are distributed uniformly
3.020748
3.017743
1.000996
qbedfile = pf + "tigs.bed" sbedfile = pf + "chr.bed" lastfile = "{}tigs.{}chr.last".format(pf, pf) qbedfw = open(qbedfile, "w") sbedfw = open(sbedfile, "w") lastfw = open(lastfile, "w") GeneContigs = np.searchsorted(ContigStarts, GenePositions) - 1 for i, (c, gstart) in enumerate(z...
def write_last_and_beds(pf, GenePositions, ContigStarts)
Write LAST file, query and subject BED files.
2.779079
2.666475
1.04223
clm = defaultdict(list) for start, end, linkstart, linkend in \ zip(ICLinkStartContigs, ICLinkEndContigs, ICLinkStarts, ICLinkEnds): start_a = ContigStarts[start] start_b = start_a + ContigSizes[start] end_a = ContigStarts[end] end_b = end_a + Con...
def write_clm(pf, ICLinkStartContigs, ICLinkEndContigs, ICLinkStarts, ICLinkEnds, ContigStarts, ContigSizes)
Write CLM file from simulated data.
1.920403
1.944493
0.987611
p = OptionParser(density.__doc__) p.add_option("--save", default=False, action="store_true", help="Write log densitites of contigs to file") p.set_cpus() opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) clmfile, = args clm = CLMF...
def density(args)
%prog density test.clm Estimate link density of contigs.
3.549939
3.359465
1.056698
p = OptionParser(optimize.__doc__) p.add_option("--skiprecover", default=False, action="store_true", help="Do not import 'recover' contigs") p.add_option("--startover", default=False, action="store_true", help="Do not resume from existing tour file") p.add_option("...
def optimize(args)
%prog optimize test.clm Optimize the contig order and orientation, based on CLM file.
4.116782
3.832673
1.074128
from .chic import score_evaluate_M # Prepare input files tour_contigs = clm.active_contigs tour_sizes = clm.active_sizes tour_M = clm.M tour = clm.tour signs = clm.signs oo = clm.oo def callback(tour, gen, phase, oo): fitness = tour.fitness if hasattr(tour, "fitness") ...
def optimize_ordering(fwtour, clm, phase, cpus)
Optimize the ordering of contigs by Genetic Algorithm (GA).
5.00914
4.835193
1.035975
# Prepare input files tour_contigs = clm.active_contigs tour = clm.tour oo = clm.oo print_tour(fwtour, tour, "FLIPALL{}".format(phase), tour_contigs, oo, signs=clm.signs) tag1 = clm.flip_whole(tour) print_tour(fwtour, tour, "FLIPWHOLE{}".format(phase), tou...
def optimize_orientations(fwtour, clm, phase, cpus)
Optimize the orientations of contigs by using heuristic flipping.
3.747446
3.658745
1.024243
qbedfile, sbedfile = get_bed_filenames(lastfile, p, opts) qbedfile = op.abspath(qbedfile) sbedfile = op.abspath(sbedfile) qbed = Bed(qbedfile, sorted=False) contig_to_beds = dict(qbed.sub_beds()) # Create a separate directory for the subplots and movie mkdir(odir, overwrite=True) ...
def prepare_synteny(tourfile, lastfile, odir, p, opts)
Prepare synteny plots for movie().
4.52211
4.314257
1.048178
tour = [] tour_o = [] for contig in row.split(): if contig[-1] in ('+', '-', '?'): tour.append(contig[:-1]) tour_o.append(contig[-1]) else: # Unoriented tour.append(contig) tour_o.append('?') return tour, tour_o
def separate_tour_and_o(row)
The tour line typically contains contig list like: tig00044568+ tig00045748- tig00071055- tig00015093- tig00030900- This function separates the names from the orientations.
3.267538
2.90459
1.124957
row = open(tourfile).readlines()[-1] _tour, _tour_o = separate_tour_and_o(row) tour = [] tour_o = [] for tc, to in zip(_tour, _tour_o): if tc not in clm.contigs: logging.debug("Contig `{}` in file `{}` not found in `{}`" .format(tc, tourfile, clm.id...
def iter_last_tour(tourfile, clm)
Extract last tour from tourfile. The clm instance is also passed in to see if any contig is covered in the clm.
3.557264
3.32237
1.070701
fp = open(tourfile) i = 0 for row in fp: if row[0] == '>': label = row[1:].strip() if label.startswith("GA"): pf, j, score = label.split("-", 2) j = int(j) else: j = 0 i += 1 else: ...
def iter_tours(tourfile, frames=1)
Extract tours from tourfile. Tourfile contains a set of contig configurations, generated at each iteration of the genetic algorithm. Each configuration has two rows, first row contains iteration id and score, second row contains list of contigs, separated by comma.
4.213403
4.18301
1.007266
p = OptionParser(movie.__doc__) p.add_option("--frames", default=500, type="int", help="Only plot every N frames") p.add_option("--engine", default="ffmpeg", choices=("ffmpeg", "gifsicle"), help="Movie engine, output MP4 or GIF") p.set_beds() opts, args, iopts ...
def movie(args)
%prog movie test.tour test.clm ref.contigs.last Plot optimization history.
4.673956
4.335537
1.078057
p = OptionParser(score.__doc__) p.set_cpus() opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.print_help()) mdir, cdir, contigsfasta = args orderingfiles = natsorted(iglob(mdir, "*.ordering")) sizes = Sizes(contigsfasta) contig_names = list(sizes.iter_name...
def score(args)
%prog score main_results/ cached_data/ contigsfasta Score the current LACHESIS CLM.
4.536965
4.356666
1.041385
tour = range(len(oo)) tour_sizes = np.array([sizes.sizes[x] for x in oo]) tour_M = M[oo, :][:, oo] return tour, tour_sizes, tour_M
def prepare_ec(oo, sizes, M)
This prepares EC and converts from contig_id to an index.
3.866329
3.507558
1.102285
sizes_oo = np.array([tour_sizes[x] for x in tour]) sizes_cum = np.cumsum(sizes_oo) - sizes_oo / 2 s = 0 size = len(tour) for ia in xrange(size): a = tour[ia] for ib in xrange(ia + 1, size): b = tour[ib] links = tour_M[a, b] dist = sizes_cum[ib...
def score_evaluate(tour, tour_sizes=None, tour_M=None)
SLOW python version of the evaluation function. For benchmarking purposes only. Do not use in production.
3.3235
3.348678
0.992481
p = OptionParser(movieframe.__doc__) p.add_option("--label", help="Figure title") p.set_beds() p.set_outfile(outfile=None) opts, args, iopts = p.set_image_options(args, figsize="16x8", style="white", cmap="coolwarm", ...
def movieframe(args)
%prog movieframe tour test.clm contigs.ref.anchors Draw heatmap and synteny in the same plot.
4.014009
3.490465
1.149993
p = OptionParser(agp.__doc__) p.set_outfile() opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) odir, contigsfasta = args fwagp = must_open(opts.outfile, 'w') orderingfiles = natsorted(iglob(odir, "*.ordering")) sizes = Sizes(contigsfasta).map...
def agp(args)
%prog agp main_results/ contigs.fasta Generate AGP file based on LACHESIS output.
4.272899
3.965281
1.077578
'''Converts the ContigOrdering file into AGP format ''' contigorder = [(x.contig_name, x.strand) for x in self] order_to_agp(obj, contigorder, sizes, fw, gapsize=gapsize, gaptype=gaptype, evidence=evidence)
def write_agp(self, obj, sizes, fw=sys.stdout, gapsize=100, gaptype="contig", evidence="map")
Converts the ContigOrdering file into AGP format
6.359537
4.213562
1.509302
'''IDS file has a list of contigs that need to be ordered. 'recover', keyword, if available in the third column, is less confident. tig00015093 46912 tig00035238 46779 recover tig00030900 119291 ''' idsfile = self.idsfile logging.debug("Pars...
def parse_ids(self, skiprecover)
IDS file has a list of contigs that need to be ordered. 'recover', keyword, if available in the third column, is less confident. tig00015093 46912 tig00035238 46779 recover tig00030900 119291
5.742777
2.573421
2.231573
active = self.active densities = defaultdict(int) for (at, bt), links in self.contacts.items(): if not (at in active and bt in active): continue densities[at] += links densities[bt] += links logdensities = {} for x, d ...
def calculate_densities(self)
Calculate the density of inter-contig links per base. Strong contigs considered to have high level of inter-contig links in the current partition.
4.135475
3.668313
1.127351
if tourfile and (not op.exists(tourfile)): logging.debug("Tourfile `{}` not found".format(tourfile)) tourfile = None if tourfile: logging.debug("Importing tourfile `{}`".format(tourfile)) tour, tour_o = iter_last_tour(tourfile, self) ...
def activate(self, tourfile=None, minsize=10000, backuptour=True)
Select contigs in the current partition. This is the setup phase of the algorithm, and supports two modes: - "de novo": This is useful at the start of a new run where no tours available. We select the strong contigs that have significant number of links to other contigs in the parti...
4.47128
4.32212
1.034511
from .chic import score_evaluate_M return score_evaluate_M(tour, self.active_sizes, self.M)
def evaluate_tour_M(self, tour)
Use Cythonized version to evaluate the score of a current tour
17.293421
14.16977
1.220445
from .chic import score_evaluate_P return score_evaluate_P(tour, self.active_sizes, self.P)
def evaluate_tour_P(self, tour)
Use Cythonized version to evaluate the score of a current tour, with better precision on the distance of the contigs.
18.051754
12.620217
1.430384
from .chic import score_evaluate_Q return score_evaluate_Q(tour, self.active_sizes, self.Q)
def evaluate_tour_Q(self, tour)
Use Cythonized version to evaluate the score of a current tour, taking orientation into consideration. This may be the most accurate evaluation under the right condition.
18.32765
13.546539
1.35294
if self.signs is None: # First run score = 0 else: old_signs = self.signs[:self.N] score, = self.evaluate_tour_Q(tour) # Remember we cannot have ambiguous orientation code (0 or '?') here self.signs = get_signs(self.O, validate=False, ambigu...
def flip_all(self, tour)
Initialize the orientations based on pairwise O matrix.
7.615099
7.002648
1.08746
score, = self.evaluate_tour_Q(tour) self.signs = -self.signs score_flipped, = self.evaluate_tour_Q(tour) if score_flipped > score: tag = ACCEPT else: self.signs = -self.signs tag = REJECT self.flip_log("FLIPWHOLE", score, score...
def flip_whole(self, tour)
Test flipping all contigs at the same time to see if score improves.
4.928718
4.935844
0.998556
n_accepts = n_rejects = 0 any_tag_ACCEPT = False for i, t in enumerate(tour): if i == 0: score, = self.evaluate_tour_Q(tour) self.signs[t] = -self.signs[t] score_flipped, = self.evaluate_tour_Q(tour) if score_flipped > scor...
def flip_one(self, tour)
Test flipping every single contig sequentially to see if score improves.
3.282876
3.237176
1.014117
while True: tour_score, = self.evaluate_tour_M(tour) logging.debug("Starting score: {}".format(tour_score)) active_sizes = self.active_sizes M = self.M args = [] for i, t in enumerate(tour): stour = tour[:i] + tour[...
def prune_tour(self, tour, cpus)
Test deleting each contig and check the delta_score; tour here must be an array of ints.
4.75538
4.558024
1.043299
N = self.N tig_to_idx = self.tig_to_idx M = np.zeros((N, N), dtype=int) for (at, bt), links in self.contacts.items(): if not (at in tig_to_idx and bt in tig_to_idx): continue ai = tig_to_idx[at] bi = tig_to_idx[bt] ...
def M(self)
Contact frequency matrix. Each cell contains how many inter-contig links between i-th and j-th contigs.
2.853749
2.476113
1.152511
N = self.N tig_to_idx = self.tig_to_idx O = np.zeros((N, N), dtype=int) for (at, bt), (strandedness, md, mh) in self.orientations.items(): if not (at in tig_to_idx and bt in tig_to_idx): continue ai = tig_to_idx[at] bi = tig_to...
def O(self)
Pairwise strandedness matrix. Each cell contains whether i-th and j-th contig are the same orientation +1, or opposite orientation -1.
3.519616
3.082044
1.141975
N = self.N tig_to_idx = self.tig_to_idx P = np.zeros((N, N, 2), dtype=int) for (at, bt), (strandedness, md, mh) in self.orientations.items(): if not (at in tig_to_idx and bt in tig_to_idx): continue ai = tig_to_idx[at] bi = tig...
def P(self)
Contact frequency matrix with better precision on distance between contigs. In the matrix M, the distance is assumed to be the distance between mid-points of two contigs. In matrix Q, however, we compute harmonic mean of the links for the orientation configuration that is shortest. This ...
2.902641
2.689924
1.079079
N = self.N tig_to_idx = self.tig_to_idx signs = self.signs Q = np.ones((N, N, BB), dtype=int) * -1 # Use -1 as the sentinel for (at, bt), k in self.contacts_oriented.items(): if not (at in tig_to_idx and bt in tig_to_idx): continue ...
def Q(self)
Contact frequency matrix when contigs are already oriented. This is s a similar matrix as M, but rather than having the number of links in the cell, it points to an array that has the actual distances.
4.355255
3.980851
1.094051
p = OptionParser(insertionpairs.__doc__) p.add_option("--extend", default=10, type="int", help="Allow insertion sites to match up within distance") p.set_outfile() opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) bedfile, = args ...
def insertionpairs(args)
%prog insertionpairs endpoints.bed Pair up the candidate endpoints. A candidate exision point would contain both left-end (LE) and right-end (RE) within a given distance. -----------| |------------ -------| |-------- ---------| |---------- (RE) (LE)
3.120748
2.965388
1.052391
p = OptionParser(insertion.__doc__) p.add_option("--mindepth", default=6, type="int", help="Minimum depth to call an insertion") p.set_outfile() opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) bedfile, = args mindepth = opts.min...
def insertion(args)
%prog insertion mic.mac.bed Find IES based on mapping MIC reads to MAC genome. Output a bedfile with 'lesions' (stack of broken reads) in the MAC genome.
2.395556
2.308559
1.037685
p.add_option("--distance", default=500, type="int", help="Outer distance between the two ends [default: %default]") p.add_option("--readlen", default=150, type="int", help="Length of the read") p.set_depth(depth=10) p.set_outfile(outfile=None)
def add_sim_options(p)
Add options shared by eagle or wgsim.
4.156691
3.976133
1.04541
p = OptionParser(wgsim.__doc__) p.add_option("--erate", default=.01, type="float", help="Base error rate of the read [default: %default]") p.add_option("--noerrors", default=False, action="store_true", help="Simulate reads with no errors [default: %default]") p.add...
def wgsim(args)
%prog wgsim fastafile Run dwgsim on fastafile.
2.83584
2.746142
1.032663
p = OptionParser(cov.__doc__) p.add_option("--order", default="swede,kale,h165,yudal,aviso,abu,bristol,bzh", help="The order to plot the tracks, comma-separated") p.add_option("--reverse", default=False, action="store_true", help="Plot the order in revers...
def cov(args)
%prog cov chrA01 chrC01 chr.sizes data AN.CN.1x1.lifted.anchors.simple Plot coverage graphs between homeologs, the middle panel show the homeologous gene pairs. Allow multiple chromosomes to multiple chromosomes.
3.554698
3.369807
1.054867
p = OptionParser(fig4.__doc__) p.add_option("--gauge_step", default=200000, type="int", help="Step size for the base scale") opts, args, iopts = p.set_image_options(args, figsize="9x7") if len(args) != 2: sys.exit(not p.print_help()) layout, datadir = args layout =...
def fig4(args)
%prog fig4 layout data Napus Figure 4A displays an example deleted region for quartet chromosomes, showing read alignments from high GL and low GL lines.
5.101378
4.908676
1.039258
import math from jcvi.formats.bed import Bed from jcvi.graphics.chromosome import HorizontalChromosome from jcvi.graphics.base import kb_formatter p = OptionParser(deletion.__doc__) opts, args, iopts = p.set_image_options(args) if len(args) != 3: sys.exit(not p.print_help()) ...
def deletion(args)
%prog deletion [deletion-genes|deletion-bases] C2-deletions boleracea.bed Plot histogram for napus deletions. Can plot deletion-genes or deletion-bases. The three largest segmental deletions will be highlighted along with a drawing of the C2 chromosome.
3.395955
3.262703
1.040841
p = OptionParser(ploidy.__doc__) opts, args, iopts = p.set_image_options(args, figsize="8x7") if len(args) != 2: sys.exit(not p.print_help()) seqidsfile, klayout = args fig = plt.figure(1, (iopts.w, iopts.h)) root = fig.add_axes([0, 0, 1, 1]) Karyotype(fig, root, seqidsfile,...
def ploidy(args)
%prog ploidy seqids layout Build a figure that calls graphics.karyotype to illustrate the high ploidy of B. napus genome.
3.013797
2.797278
1.077403
from jcvi.graphics.base import red_purple as default_cm p = OptionParser(expr.__doc__) opts, args, iopts = p.set_image_options(args, figsize="8x5") if len(args) != 4: sys.exit(not p.print_help()) block, exp, layout, napusbed = args fig = plt.figure(1, (iopts.w, iopts.h)) roo...
def expr(args)
%prog expr block exp layout napus.bed Plot a composite figure showing synteny and the expression level between homeologs in two tissues - total 4 lists of values. block file contains the gene pairs between AN and CN.
3.059624
2.86284
1.068737
p = OptionParser(pasteprepare.__doc__) p.add_option("--flank", default=5000, type="int", help="Get the seq of size on two ends [default: %default]") opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) goodfasta, = args flank = opts.flan...
def pasteprepare(args)
%prog pasteprepare bacs.fasta Prepare sequences for paste.
3.35168
3.230469
1.037521
from jcvi.formats.bed import uniq p = OptionParser(paste.__doc__) p.add_option("--maxsize", default=300000, type="int", help="Maximum size of patchers to be replaced [default: %default]") p.add_option("--prefix", help="Prefix of the new object [default: %default]") p.set_rclip(rcli...
def paste(args)
%prog paste flanks.bed flanks_vs_assembly.blast backbone.fasta Paste in good sequences in the final assembly.
4.693723
4.387397
1.06982
p = OptionParser(eject.__doc__) opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) candidates, chrfasta = args sizesfile = Sizes(chrfasta).filename cbedfile = complementBed(candidates, sizesfile) cbed = Bed(cbedfile) for b in cbed: b.a...
def eject(args)
%prog eject candidates.bed chr.fasta Eject scaffolds from assembly, using the range identified by closest().
4.983202
3.701315
1.346333
p = OptionParser(closest.__doc__) p.add_option("--om", default=False, action="store_true", help="The bedfile is OM blocks [default: %default]") opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.print_help()) candidates, gapsbed, fastafile = args si...
def closest(args)
%prog closest candidates.bed gaps.bed fastafile Identify the nearest gaps flanking suggested regions.
3.188433
2.867258
1.112015
from jcvi.formats.agp import mask, bed from jcvi.formats.sizes import agp p = OptionParser(insert.__doc__) opts, args = p.parse_args(args) if len(args) != 4: sys.exit(not p.print_help()) candidates, gapsbed, chrfasta, unplacedfasta = args refinedbed = refine([candidates, gaps...
def insert(args)
%prog insert candidates.bed gaps.bed chrs.fasta unplaced.fasta Insert scaffolds into assembly.
3.53912
3.216763
1.100212
from jcvi.formats.bed import uniq from jcvi.utils.iter import pairwise p = OptionParser(gaps.__doc__) opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) ombed, fastafile = args ombed = uniq([ombed]) bed = Bed(ombed) for a, b in pairwise(b...
def gaps(args)
%prog gaps OM.bed fastafile Create patches around OM gaps.
2.601868
2.39769
1.085156
p = OptionParser(tips.__doc__) opts, args = p.parse_args(args) if len(args) != 4: sys.exit(not p.print_help()) pbedfile, cbedfile, sizesfile, bbfasta = args pbed = Bed(pbedfile, sorted=False) cbed = Bed(cbedfile, sorted=False) complements = dict() for object, beds in gro...
def tips(args)
%prog tips patchers.bed complements.bed original.fasta backbone.fasta Append telomeric sequences based on patchers and complements.
2.672838
2.517512
1.061698
p = OptionParser(fill.__doc__) p.add_option("--extend", default=2000, type="int", help="Extend seq flanking the gaps [default: %default]") opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) gapsbed, badfasta = args Ext = opts.extend ...
def fill(args)
%prog fill gaps.bed bad.fasta Perform gap filling of one assembly (bad) using sequences from another.
3.836496
3.389397
1.131911
from jcvi.apps.align import blast from jcvi.formats.fasta import SeqIO p = OptionParser(install.__doc__) p.set_rclip(rclip=1) p.add_option("--maxsize", default=300000, type="int", help="Maximum size of patchers to be replaced [default: %default]") p.add_option("--prefix", help=...
def install(args)
%prog install patchers.bed patchers.fasta backbone.fasta alt.fasta Install patches into backbone, using sequences from alternative assembly. The patches sequences are generated via jcvi.assembly.patch.fill(). The output is a bedfile that can be converted to AGP using jcvi.formats.agp.frombed().
3.602128
3.380269
1.065634
p = OptionParser(refine.__doc__) p.add_option("--closest", default=False, action="store_true", help="In case of no gaps, use closest [default: %default]") opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) breakpointsbed, gapsbed = args ...
def refine(args)
%prog refine breakpoints.bed gaps.bed Find gaps within or near breakpoint region. For breakpoint regions with no gaps, there are two options: - Break in the middle of the region - Break at the closest gap (--closest)
2.534267
2.411638
1.050849
from jcvi.formats.bed import uniq p = OptionParser(patcher.__doc__) p.add_option("--backbone", default="OM", help="Prefix of the backbone assembly [default: %default]") p.add_option("--object", default="object", help="New object name [default: %default]") opts...
def patcher(args)
%prog patcher backbone.bed other.bed Given optical map alignment, prepare the patchers. Use --backbone to suggest which assembly is the major one, and the patchers will be extracted from another assembly.
4.08193
3.826408
1.066779
p = OptionParser(treds.__doc__) p.add_option("--csv", default=False, action="store_true", help="Also write `meta.csv`") opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) tredresults, = args df = pd.read_csv(tredresults, sep="\t") ...
def treds(args)
%prog treds hli.tred.tsv Compile allele_frequency for TREDs results. Write data.tsv, meta.tsv and mask.tsv in one go.
2.926023
2.679715
1.091916
p = OptionParser(stutter.__doc__) opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) vcf, = args pf = op.basename(vcf).split(".")[0] execid, sampleid = pf.split("_") C = "vcftools --remove-filtered-all --min-meanDP 10" C += " --gzvcf {} --out ...
def stutter(args)
%prog stutter a.vcf.gz Extract info from lobSTR vcf file. Generates a file that has the following fields: CHR, POS, MOTIF, RL, ALLREADS, Q
3.926034
3.676463
1.067884
p = OptionParser(filtervcf.__doc__) p.set_home("lobstr", default="/mnt/software/lobSTR") p.set_aws_opts(store="hli-mv-data-science/htang/str") p.set_cpus() opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) samples, = args lhome = opts.lobstr_h...
def filtervcf(args)
%prog filtervcf NA12878.hg38.vcf.gz Filter lobSTR VCF using script shipped in lobSTR. Input file can be a list of vcf files.
4.495221
4.091889
1.098568
p = OptionParser(meta.__doc__) p.add_option("--cutoff", default=.5, type="float", help="Percent observed required (chrY half cutoff)") p.set_cpus() opts, args = p.parse_args(args) if len(args) != 4: sys.exit(not p.print_help()) binfile, sampleids, strids, wobed = ...
def meta(args)
%prog meta data.bin samples STR.ids STR-exons.wo.bed Compute allele frequencies and prune sites based on missingness. Filter subset of loci that satisfy: 1. no redundancy (unique chr:pos) 2. variable (n_alleles > 1) 3. low level of missing data (>= 50% autosomal + X, > 25% for Y) Write meta f...
4.435167
4.193947
1.057516
p = OptionParser(bin.__doc__) p.add_option("--dtype", choices=("float32", "int32"), help="dtype of the matrix") opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) tsvfile, = args dtype = opts.dtype if dtype is None: # Guess ...
def bin(args)
%prog bin data.tsv Conver tsv to binary format.
2.408303
2.31014
1.042493
p = OptionParser(data.__doc__) p.add_option("--notsv", default=False, action="store_true", help="Do not write data.tsv") opts, args = p.parse_args(args) if len(args) != 4: sys.exit(not p.print_help()) databin, sampleids, strids, metafile = args final_columns, perc...
def data(args)
%prog data data.bin samples.ids STR.ids meta.tsv Make data.tsv based on meta.tsv.
4.363021
3.894823
1.12021
p = OptionParser(mask.__doc__) opts, args = p.parse_args(args) if len(args) not in (2, 4): sys.exit(not p.print_help()) if len(args) == 4: databin, sampleids, strids, metafile = args df, m, samples, loci = read_binfile(databin, sampleids, strids) mode = "STRs" ...
def mask(args)
%prog mask data.bin samples.ids STR.ids meta.tsv OR %prog mask data.tsv meta.tsv Compute P-values based on meta and data. The `data.bin` should be the matrix containing filtered loci and the output mask.tsv will have the same dimension.
4.154766
3.779213
1.099373
p = OptionParser(mergecsv.__doc__) opts, args = p.parse_args(args) if len(args) < 1: sys.exit(not p.print_help()) csvfiles = args arrays = [] samplekeys = [] for csvfile in csvfiles: samplekey = op.basename(csvfile).split(".")[0] a = np.fromfile(csvfile, sep=",...
def mergecsv(args)
%prog mergecsv *.csv Combine CSV into binary array.
2.543311
2.357541
1.078798
p = OptionParser(compilevcf.__doc__) p.add_option("--db", default="hg38", help="Use these lobSTR db") p.add_option("--nofilter", default=False, action="store_true", help="Do not filter the variants") p.set_home("lobstr") p.set_cpus() p.set_aws_opts(store="hli-mv-data-scienc...
def compilevcf(args)
%prog compilevcf samples.csv Compile vcf results into master spreadsheet.
3.991339
3.927225
1.016326
from jcvi.utils.table import write_csv p = OptionParser(ystr.__doc__) p.set_home("lobstr") opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) vcffile, = args si = STRFile(opts.lobstr_home, db="hg38-named") register = si.register header = ...
def ystr(args)
%prog ystr chrY.vcf Print out Y-STR info given VCF. Marker name extracted from tabfile.
4.134412
4.023084
1.027672
p = OptionParser(liftover.__doc__) p.add_option("--checkvalid", default=False, action="store_true", help="Check minscore, period and length") opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) refbed, fastafile = args genome = pyfasta.F...
def liftover(args)
%prog liftover lobstr_v3.0.2_hg38_ref.bed hg38.upper.fa LiftOver CODIS/Y-STR markers.
3.216331
3.057996
1.051777
from jcvi.apps.base import iglob cparams = "1 1 2 80 5 200 2000" p = OptionParser(trf.__doc__) p.add_option("--mismatch", default=31, type="int", help="Mismatch and gap penalty") p.add_option("--minscore", default=MINSCORE, type="int", help="Minimum score to r...
def trf(args)
%prog trf outdir Run TRF on FASTA files.
3.095117
3.032254
1.020732
p = OptionParser(batchlobstr.__doc__) p.add_option("--sep", default=",", help="Separator for building commandline") p.set_home("lobstr", default="s3://hli-mv-data-science/htang/str-build/lobSTR/") p.set_aws_opts(store="hli-mv-data-science/htang/str-data") opts, args = p.parse_args(args) if...
def batchlobstr(args)
%prog batchlobstr samples.csv Run lobSTR sequentially on list of samples. Each line contains: sample-name,s3-location
5.047091
4.937597
1.022175
from jcvi.formats.sam import get_minibam # See `Format-lobSTR-database.ipynb` for a list of TREDs for validation INCLUDE = ["HD", "SBMA", "SCA1", "SCA2", "SCA8", "SCA17", "DM1", "DM2", "FXTAS"] db_choices = ("hg38", "hg19") p = OptionParser(locus.__doc__) p.add_option("--tre...
def locus(args)
%prog locus bamfile Extract selected locus from a list of TREDs for validation, and run lobSTR.
4.847856
4.490833
1.0795
p = OptionParser(lobstrindex.__doc__) p.add_option("--notreds", default=False, action="store_true", help="Remove TREDs from the bed file") p.set_home("lobstr") opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) trfbed, fastafile = args...
def lobstrindex(args)
%prog lobstrindex hg38.trf.bed hg38.upper.fa Make lobSTR index. Make sure the FASTA contain only upper case (so use fasta.format --upper to convert from UCSC fasta). The bed file is generated by str().
3.122686
2.972037
1.050689
p = OptionParser(close.__doc__) p.set_home("gapfiller") p.set_cpus() opts, args = p.parse_args(args) if len(args) < 1: sys.exit(not p.print_help()) scaffolds = args[0] libtxt = write_libraries(args[1:], aligner="bwa") cmd = "perl " + op.join(opts.gapfiller_home, "GapFille...
def close(args)
%prog close scaffolds.fasta PE*.fastq Run GapFiller to fill gaps.
4.01501
3.195921
1.256292
p = OptionParser(scaffold.__doc__) p.set_aligner(aligner="bwa") p.set_home("sspace") p.set_cpus() opts, args = p.parse_args(args) if len(args) < 1: sys.exit(not p.print_help()) contigs = args[0] libtxt = write_libraries(args[1:], aligner=opts.aligner) # Requires getopt...
def scaffold(args)
%prog scaffold contigs.fasta MP*.fastq Run SSPACE scaffolding.
6.395324
5.470994
1.168951
p = OptionParser(agp.__doc__) opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) evidencefile, contigs = args ef = EvidenceFile(evidencefile, contigs) agpfile = evidencefile.replace(".evidence", ".agp") ef.write_agp(agpfile)
def agp(args)
%prog agp evidencefile contigs.fasta Convert SSPACE scaffold structure to AGP format.
2.814865
2.048578
1.374058
p = OptionParser(embed.__doc__) p.set_mingap(default=10) p.add_option("--min_length", default=200, type="int", help="Minimum length to consider [default: %default]") opts, args = p.parse_args(args) if len(args) != 3: sys.exit(not p.print_help()) evidencefile, scaf...
def embed(args)
%prog embed evidencefile scaffolds.fasta contigs.fasta Use SSPACE evidencefile to scaffold contigs into existing scaffold structure, as in `scaffolds.fasta`. Contigs.fasta were used by SSPACE directly to scaffold. Rules: 1. Only update existing structure by embedding contigs small enough to fit. ...
4.541344
4.336781
1.047169
align_choices = ("left", "center", "right") p = OptionParser(gff.__doc__) p.add_option("--align", default="left", choices=align_choices, help="Horizontal alignment [default: %default]") p.add_option("--noUTR", default=False, action="store_true", help="Do not plot U...
def gff(args)
%prog gff *.gff Draw exons for genes based on gff files. Each gff file should contain only one gene, and only the "mRNA" and "CDS" feature will be drawn on the canvas.
2.936266
2.829475
1.037742
from jcvi.formats.fastq import readlen p = OptionParser(spades.__doc__) opts, args = p.parse_args(args) if len(args) == 0: sys.exit(not p.print_help()) folder, = args for p, pf in iter_project(folder): rl = readlen([p[0], "--silent"]) # <http://spades.bioinf.spba...
def spades(args)
%prog spades folder Run automated SPADES.
3.733759
3.551172
1.051416
from jcvi.apps.bowtie import align p = OptionParser(contamination.__doc__) p.add_option("--mapped", default=False, action="store_true", help="Retain contaminated reads instead [default: %default]") p.set_cutoff(cutoff=800) p.set_mateorientation(mateorientation="+-") opts, ...
def contamination(args)
%prog contamination folder Ecoli.fasta Remove contaminated reads. The FASTQ files in the folder will automatically pair and filtered against Ecoli.fasta to remove contaminants using BOWTIE2.
4.053464
3.699788
1.095594
p = OptionParser(pairs.__doc__) p.set_firstN() p.set_mates() p.set_aligner() opts, args = p.parse_args(args) if len(args) != 2: sys.exit(not p.print_help()) cwd = os.getcwd() aligner = opts.aligner work = "-".join(("pairs", aligner)) mkdir(work) from jcvi.form...
def pairs(args)
%prog pairs folder reference.fasta Estimate insert size distribution. Compatible with a variety of aligners, including BOWTIE and BWA.
4.608087
4.383369
1.051266
p = OptionParser(allpaths.__doc__) p.add_option("--ploidy", default="1", choices=("1", "2"), help="Ploidy [default: %default]") opts, args = p.parse_args(args) if len(args) == 0: sys.exit(not p.print_help()) folders = args for pf in folders: if not op.isdi...
def allpaths(args)
%prog allpaths folder1 folder2 ... Run automated ALLPATHS on list of dirs.
3.380087
3.398392
0.994614
p = OptionParser(prepare.__doc__) p.add_option("--first", default=0, type="int", help="Use only first N reads [default: %default]") opts, args = p.parse_args(args) if len(args) != 1: sys.exit(not p.print_help()) jfile, = args metafile = jfile + ".meta" if nee...
def prepare(args)
%prog prepare jira.txt Parse JIRA report and prepare input. Look for all FASTQ files in the report and get the prefix. Assign fastq to a folder and a new file name indicating the library type (e.g. PE-500, MP-5000, etc.). Note that JIRA report can also be a list of FASTQ files.
3.649271
3.411234
1.06978
slink(p, pf, tag) assemble_dir(pf, target)
def assemble_pairs(p, pf, tag, target=["final.contigs.fasta"])
Take one pair of reads and assemble to contigs.fasta.
15.76053
16.326332
0.965344
from jcvi.assembly.preprocess import correct as cr logging.debug("Work on {0} ({1})".format(pf, ','.join(p))) itag = tag[0] cm = ".".join((pf, itag)) targets = (cm + ".1.corr.fastq", cm + ".2.corr.fastq", \ pf + ".PE-0.corr.fastq") if not need_update(p, targets): lo...
def correct_pairs(p, pf, tag)
Take one pair of reads and correct to generate *.corr.fastq.
4.920497
4.621193
1.064768