code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
a_chr, a_min, a_max = a
b_chr, b_min, b_max = b
a_min, a_max = sorted((a_min, a_max))
b_min, b_max = sorted((b_min, b_max))
shorter = min((a_max - a_min), (b_max - b_min)) + 1
# must be on the same chromosome
if a_chr != b_chr:
ov = 0
else:
ov = min(shorter, (a_max -... | def range_overlap(a, b, ratio=False) | Returns whether two ranges overlap. Set percentage=True returns overlap
ratio over the shorter range of the two.
>>> range_overlap(("1", 30, 45), ("1", 41, 55))
5
>>> range_overlap(("1", 21, 45), ("1", 41, 75), ratio=True)
0.2
>>> range_overlap(("1", 30, 45), ("1", 15, 55))
16
>>> range... | 2.3335 | 2.51693 | 0.927122 |
assert distmode in ('ss', 'ee')
a_chr, a_min, a_max, a_strand = a
b_chr, b_min, b_max, b_strand = b
# must be on the same chromosome
if a_chr != b_chr:
dist = -1
#elif range_overlap(a[:3], b[:3]):
# dist = 0
else:
# If the two ranges do not overlap, check strande... | def range_distance(a, b, distmode='ss') | Returns the distance between two ranges.
distmode is ss, se, es, ee and sets the place on read one and two to
measure the distance (s = start, e = end)
>>> range_distance(("1", 30, 45, '+'), ("1", 45, 55, '+'))
(26, '++')
>>> range_distance(("1", 30, 45, '-'), ("1", 57, 68, '-'))
(39, '-... | 2.730655 | 2.886739 | 0.945931 |
rmin = min(ranges)[0]
rmax = max(ranges, key=lambda x: x[1])[1]
return rmin, rmax | def range_minmax(ranges) | Returns the span of a collection of ranges where start is the smallest of
all starts, and end is the largest of all ends.
>>> ranges = [(30, 45), (40, 50), (10, 100)]
>>> range_minmax(ranges)
(10, 100) | 2.966094 | 4.827997 | 0.614353 |
from jcvi.utils.orderedcollections import SortedCollection
key = (lambda x: x) if left else (lambda x: (x[0], x[2], x[1]))
rr = SortedCollection(ranges, key=key)
try:
if left:
s = rr.find_le(b)
assert key(s) <= key(b), (s, b)
else:
s = rr.find_ge(... | def range_closest(ranges, b, left=True) | Returns the range that's closest to the given position. Notice that the
behavior is to return ONE closest range to the left end (if left is True).
This is a SLOW method.
>>> ranges = [("1", 30, 40), ("1", 33, 35), ("1", 10, 20)]
>>> b = ("1", 22, 25)
>>> range_closest(ranges, b)
('1', 10, 20)
... | 3.354698 | 3.686493 | 0.909997 |
from jcvi.utils.iter import pairwise
ranges = range_merge(ranges)
interleaved_ranges = []
for ch, cranges in groupby(ranges, key=lambda x: x[0]):
cranges = list(cranges)
size = sizes.get(ch, None)
if size:
ch, astart, aend = cranges[0]
if astart > 1:... | def range_interleave(ranges, sizes={}, empty=False) | Returns the ranges in between the given ranges.
>>> ranges = [("1", 30, 40), ("1", 45, 50), ("1", 10, 30)]
>>> range_interleave(ranges)
[('1', 41, 44)]
>>> ranges = [("1", 30, 40), ("1", 42, 50)]
>>> range_interleave(ranges)
[('1', 41, 41)]
>>> range_interleave(ranges, sizes={"1": 70})
... | 2.020427 | 2.156713 | 0.936809 |
if not ranges:
return []
ranges.sort()
cur_range = list(ranges[0])
merged_ranges = []
for r in ranges[1:]:
# open new range if start > cur_end or seqid != cur_seqid
if r[1] - cur_range[2] > dist or r[0] != cur_range[0]:
merged_ranges.append(tuple(cur_range)... | def range_merge(ranges, dist=0) | Returns merged range. Similar to range_union, except this returns
new ranges.
>>> ranges = [("1", 30, 45), ("1", 40, 50), ("1", 10, 50)]
>>> range_merge(ranges)
[('1', 10, 50)]
>>> ranges = [("1", 30, 40), ("1", 45, 50)]
>>> range_merge(ranges)
[('1', 30, 40), ('1', 45, 50)]
>>> ranges ... | 2.320565 | 2.563124 | 0.905366 |
if not ranges:
return 0
ranges.sort()
total_len = 0
cur_chr, cur_left, cur_right = ranges[0] # left-most range
for r in ranges:
# open new range if left > cur_right or chr != cur_chr
if r[1] > cur_right or r[0] != cur_chr:
total_len += cur_right - cur_left... | def range_union(ranges) | Returns total size of ranges, expect range as (chr, left, right)
>>> ranges = [("1", 30, 45), ("1", 40, 50), ("1", 10, 50)]
>>> range_union(ranges)
41
>>> ranges = [("1", 30, 45), ("2", 40, 50)]
>>> range_union(ranges)
27
>>> ranges = [("1", 30, 45), ("1", 45, 50)]
>>> range_union(range... | 2.370536 | 2.213782 | 1.070808 |
if not ranges:
return 0
ranges.sort()
ans = 0
for seq, lt in groupby(ranges, key=lambda x: x[0]):
lt = list(lt)
ans += max(max(lt)[1:]) - min(min(lt)[1:]) + 1
return ans | def range_span(ranges) | Returns the total span between the left most range to the right most range.
>>> ranges = [("1", 30, 45), ("1", 40, 50), ("1", 10, 50)]
>>> range_span(ranges)
41
>>> ranges = [("1", 30, 45), ("2", 40, 50)]
>>> range_span(ranges)
27
>>> ranges = [("1", 30, 45), ("1", 45, 50)]
>>> range_sp... | 4.167857 | 4.457263 | 0.935071 |
endpoints = _make_endpoints(ranges)
for seqid, ends in groupby(endpoints, lambda x: x[0]):
active = []
depth = 0
for seqid, pos, leftright, i, score in ends:
if leftright == LEFT:
active.append(i)
depth += 1
else:
... | def range_piles(ranges) | Return piles of intervals that overlap. The piles are only interrupted by
regions of zero coverage.
>>> ranges = [Range("2", 0, 1, 3, 0), Range("2", 1, 4, 3, 1), Range("3", 5, 7, 3, 2)]
>>> list(range_piles(ranges))
[[0, 1], [2]] | 5.532663 | 5.969149 | 0.926876 |
overlap = set()
active = set()
endpoints = _make_endpoints(ranges)
for seqid, ends in groupby(endpoints, lambda x: x[0]):
active.clear()
for seqid, pos, leftright, i, score in ends:
if leftright == LEFT:
active.add(i)
else:
ac... | def range_conflict(ranges, depth=1) | Find intervals that are overlapping in 1-dimension.
Return groups of block IDs that are in conflict.
>>> ranges = [Range("2", 0, 1, 3, 0), Range("2", 1, 4, 3, 1), Range("3", 5, 7, 3, 2)]
>>> list(range_conflict(ranges))
[(0, 1)] | 5.797117 | 6.793574 | 0.853324 |
endpoints = _make_endpoints(ranges)
# stores the left end index for quick retrieval
left_index = {}
# dynamic programming, each entry [score, from_index, which_chain]
scores = []
for i, (seqid, pos, leftright, j, score) in enumerate(endpoints):
cur_score = [0, -1, -1] if i == 0 e... | def range_chain(ranges) | Take list of weighted intervals, find non-overlapping set with max weight.
We proceed with each end point (sorted by their relative positions).
The input are a list of ranges of the form (start, stop, score), output is
subset of the non-overlapping ranges that give the highest score, score
>>> ranges ... | 5.016494 | 4.940298 | 1.015423 |
ranges.sort()
for seqid, rrs in groupby(ranges, key=lambda x: x[0]):
rrs = [(a, b) for (s, a, b) in rrs]
size = sizes[seqid]
ds, depthdetails = range_depth(rrs, size, verbose=verbose)
depthdetails = [(seqid, s, e, d) for s, e, d in depthdetails]
yield depthdetails | def ranges_depth(ranges, sizes, verbose=True) | Allow triple (seqid, start, end) rather than just tuple (start, end) | 4.519156 | 3.965022 | 1.139755 |
from jcvi.utils.iter import pairwise
from jcvi.utils.cbook import percentage
# Make endpoints
endpoints = []
for a, b in ranges:
endpoints.append((a, LEFT))
endpoints.append((b, RIGHT))
endpoints.sort()
vstart, vend = min(endpoints)[0], max(endpoints)[0]
assert 0 <... | def range_depth(ranges, size, verbose=True) | Overlay ranges on [start, end], and summarize the ploidy of the intervals. | 3.04568 | 3.042346 | 1.001096 |
formatted = load_csv(header, rows, sep=" ", thousands=thousands)
header, rows = formatted[0], formatted[1:]
return banner(header, rows) | def loadtable(header, rows, major='=', minor='-', thousands=True) | Print a tabular output, with horizontal separators | 7.59774 | 8.557369 | 0.887859 |
pairs = d.keys()
rows, cols = zip(*pairs)
if transpose:
rows, cols = cols, rows
rows = sorted(set(rows))
cols = sorted(set(cols))
header = ["o"] + list(cols)
table = []
for r in rows:
combo = [(r, c) for c in cols]
if transpose:
combo = [(c, r) f... | def tabulate(d, transpose=False, thousands=True, key_fun=None, sep=',', align=True) | d is a dictionary, keyed by tuple(A, B).
Goal is to put A in rows, B in columns, report data in table form.
>>> d = {(1,'a'):3, (1,'b'):4, (2,'a'):5, (2,'b'):0}
>>> print tabulate(d)
===========
o a b
-----------
1 3 4
2 5 0
-----------
>>> print tabulate(d, tr... | 2.751005 | 2.748505 | 1.00091 |
from jcvi.formats.base import must_open
formatted = load_csv(header, contents,
sep=sep, thousands=thousands, align=align)
if comment:
formatted[0] = '#' + formatted[0][1:]
formatted = "\n".join(formatted)
fw = must_open(filename, "w")
print(formatted, file=... | def write_csv(header, contents, sep=",", filename="stdout", thousands=False,
tee=False, align=True, comment=False) | Write csv that are aligned with the column headers.
>>> header = ["x_value", "y_value"]
>>> contents = [(1, 100), (2, 200)]
>>> write_csv(header, contents)
x_value, y_value
1, 100
2, 200 | 3.082751 | 4.132022 | 0.746063 |
from jcvi.formats.base import is_number
from jcvi.formats.blast import best as blast_best, bed as blast_bed
from jcvi.apps.align import blat as blat_align
p = OptionParser(blat.__doc__)
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
maptxt, re... | def blat(args) | %prog blat map1.txt ref.fasta
Make ALLMAPS input csv based on sequences. The tab-delimited txt file
include: name, LG, position, sequence. | 2.875085 | 2.729492 | 1.053341 |
from jcvi.assembly.allmaps import CSVMapLine
from jcvi.formats.sizes import Sizes
from jcvi.utils.natsort import natsorted
from jcvi.graphics.base import shorten
from jcvi.graphics.dotplot import plt, savefig, markup, normalize_axes, \
downsample, plot_breaks_and_labels, tho... | def dotplot(args) | %prog dotplot map.csv ref.fasta
Make dotplot between chromosomes and linkage maps.
The input map is csv formatted, for example:
ScaffoldID,ScaffoldPosition,LinkageGroup,GeneticPosition
scaffold_2707,11508,1,0
scaffold_2707,11525,1,1.2 | 3.418679 | 3.422986 | 0.998742 |
from jcvi.formats.base import DictFile
p = OptionParser(header.__doc__)
p.add_option("--prefix", default="",
help="Prepend text to line number [default: %default]")
p.add_option("--ids", help="Write ids to file [default: %default]")
opts, args = p.parse_args(args)
if len(... | def header(args) | %prog header map conversion_table
Rename lines in the map header. The mapping of old names to new names are
stored in two-column `conversion_table`. | 3.328811 | 3.059796 | 1.087919 |
p = OptionParser(rename.__doc__)
p.set_outfile()
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
mstmap, bedfile = args
markersbed = Bed(bedfile)
markers = markersbed.order
data = MSTMap(mstmap)
header = data.header
header = [header... | def rename(args) | %prog rename map markers.bed > renamed.map
Rename markers according to the new mapping locations. | 3.530998 | 3.243754 | 1.088553 |
from jcvi.formats.blast import bed
p = OptionParser(anchor.__doc__)
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
mapbed, blastfile = args
bedfile = bed([blastfile])
markersbed = Bed(bedfile)
markers = markersbed.order
mapbed = Bed(m... | def anchor(args) | %prog anchor map.bed markers.blast > anchored.bed
Anchor scaffolds based on map. | 3.566977 | 3.295757 | 1.082294 |
p = OptionParser(bed.__doc__)
p.add_option("--switch", default=False, action="store_true",
help="Switch reference and aligned map elements [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
mapout, = args
pf = map... | def bed(args) | %prog fasta map.out
Convert MSTMAP output into bed format. | 3.514513 | 3.138759 | 1.119714 |
from jcvi.formats.sizes import Sizes
p = OptionParser(fasta.__doc__)
p.add_option("--extend", default=1000, 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())
mapout... | def fasta(args) | %prog fasta map.out scaffolds.fasta
Extract marker sequences based on map. | 3.582543 | 3.27566 | 1.093686 |
from jcvi.utils.iter import pairwise
p = OptionParser(breakpoint.__doc__)
p.add_option("--diff", default=.1, type="float",
help="Maximum ratio of differences allowed [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
... | def breakpoint(args) | %prog breakpoint mstmap.input > breakpoints.bed
Find scaffold breakpoints using genetic map. Use variation.vcf.mstmap() to
generate the input for this routine. | 3.209451 | 2.984936 | 1.075216 |
start, end = line.component_beg, line.component_end
size = end - start + 1
leftNs, rightNs = 0, 0
lid, lo = line.component_id, line.orientation
for s in seq:
if s in 'nN':
leftNs += 1
else:
break
for s in seq[::-1]:
if s in 'nN':
r... | def trimNs(seq, line, newagp) | Test if the sequences contain dangling N's on both sides. This component
needs to be adjusted to the 'actual' sequence range. | 2.778 | 2.741169 | 1.013436 |
import csv
from jcvi.formats.sizes import Sizes
p = OptionParser(fromcsv.__doc__)
p.add_option("--evidence", default="map",
help="Linkage evidence to add in AGP")
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(not p.print_help())
contigsfasta, ma... | def fromcsv(args) | %prog fromcsv contigs.fasta map.csv map.agp
Convert csv which contains list of scaffolds/contigs to AGP file. | 4.313989 | 3.578337 | 1.205585 |
p = OptionParser(compress.__doc__)
p.set_outfile()
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
aagpfile, bagpfile = args
# First AGP provides the mapping
store = {}
agp = AGP(aagpfile)
for a in agp:
if a.is_gap:
c... | def compress(args) | %prog compress a.agp b.agp
Convert coordinates based on multiple AGP files. Useful to simplify multiple
liftOvers to compress multiple chain files into a single chain file, in
upgrading locations of genomic features.
Example:
`a.agp` could contain split scaffolds:
scaffold_0.1 1 60030... | 3.090767 | 2.910426 | 1.061964 |
from jcvi.apps.grid import WriteJobs
from jcvi.formats.bed import sort
p = OptionParser(infer.__doc__)
p.set_cpus()
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
scaffoldsf, genomef = args
inferbed = "infer-components.bed"
if need_upd... | def infer(args) | %prog infer scaffolds.fasta genome.fasta
Infer where the components are in the genome. This function is rarely used,
but can be useful when distributor does not ship an AGP file. | 4.288779 | 3.972972 | 1.079489 |
from jcvi.formats.base import DictFile
p = OptionParser(format.__doc__)
p.add_option("--switchcomponent",
help="Switch component id based on")
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
oldagpfile, newagpfile = args
switch... | def format(args) | %prog format oldagpfile newagpfile
Reformat AGP file. --switch will replace the ids in the AGP file. | 2.809294 | 2.462143 | 1.140995 |
p = OptionParser(frombed.__doc__)
p.add_option("--gapsize", default=100, type="int",
help="Insert gaps of size [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
bedfile, = args
gapsize = opts.gapsize
agpfile ... | def frombed(args) | %prog frombed bedfile
Generate AGP file based on bed file. The bed file must have at least 6
columns. With the 4-th column indicating the new object. | 3.124982 | 2.905679 | 1.075474 |
from jcvi.utils.range import range_interleave
p = OptionParser(swap.__doc__)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
agpfile, = args
agp = AGP(agpfile, nogaps=True, validate=False)
agp.sort(key=lambda x: (x.component_id, x.component_be... | def swap(args) | %prog swap agpfile
Swap objects and components. Will add gap lines. This is often used in
conjuction with formats.chain.fromagp() to convert between different
coordinate systems. | 3.370698 | 3.245463 | 1.038588 |
from jcvi.utils.table import tabulate
p = OptionParser(stats.__doc__)
p.add_option("--warn", default=False, action="store_true",
help="Warnings on small component spans [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(p.print_help())
... | def stats(args) | %prog stats agpfile
Print out a report for length of gaps and components. | 2.808308 | 2.570849 | 1.092366 |
p = OptionParser(cut.__doc__)
p.add_option("--sep", default=".", help="Separator for splits")
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
agpfile, bedfile = args
sep = opts.sep
agp = AGP(agpfile)
bed = Bed(bedfile)
simple_agp = agp.... | def cut(args) | %prog cut agpfile bedfile
Cut at the boundaries of the ranges in the bedfile. | 3.342185 | 3.202973 | 1.043463 |
p = OptionParser(reindex.__doc__)
p.add_option("--nogaps", default=False, action="store_true",
help="Remove all gap lines [default: %default]")
p.add_option("--inplace", default=False, action="store_true",
help="Replace input file [default: %default]")
opts, args =... | def reindex(args) | %prog agpfile
assume the component line order is correct, modify coordinates, this is
necessary mostly due to manual edits (insert/delete) that disrupts
the target coordinates. | 2.674221 | 2.511151 | 1.064939 |
from jcvi.utils.table import write_csv
p = OptionParser(summary.__doc__)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(p.print_help())
agpfile, = args
header = "Chromosome #_Distinct #_Components #_Scaffolds " \
"Scaff_N50 Scaff_L50 Length".split()
... | def summary(args) | %prog summary agpfile
print a table of scaffold statistics, number of BACs, no of scaffolds,
scaffold N50, scaffold L50, actual sequence, PSMOL NNNs, PSMOL-length, % of
PSMOL sequenced. | 5.121868 | 3.927873 | 1.30398 |
s = rec.description
chr = re.search(chr_pat, s)
clone = re.search(clone_pat, s)
chr = chr.group(1) if chr else ""
clone = clone.group(1) if clone else ""
return chr, clone | def get_clone(rec) | >>> get_clone("Medicago truncatula chromosome 2 clone mth2-48e18")
('2', 'mth2-48e18') | 3.263369 | 2.829587 | 1.153302 |
p = OptionParser(phase.__doc__)
p.set_outfile()
opts, args = p.parse_args(args)
if len(args) < 1:
sys.exit(not p.print_help())
fw = must_open(opts.outfile, "w")
for gbfile in args:
for rec in SeqIO.parse(gbfile, "gb"):
bac_phase, keywords = get_phase(rec)
... | def phase(args) | %prog phase genbankfiles
Input has to be gb file. Search the `KEYWORDS` section to look for PHASE.
Also look for "chromosome" and "clone" in the definition line. | 3.785066 | 3.016686 | 1.25471 |
p = OptionParser(tpf.__doc__)
p.add_option("--noversion", default=False, action="store_true",
help="Remove trailing accession versions [default: %default]")
p.add_option("--gaps", default=False, action="store_true",
help="Include gaps in the output [default: %default]")
opts... | def tpf(args) | %prog tpf agpfile
Print out a list of ids, one per line. Also known as the Tiling Path.
AC225490.9 chr6
Can optionally output scaffold gaps. | 3.027007 | 2.820009 | 1.073403 |
from jcvi.formats.obo import validate_term
p = OptionParser(bed.__doc__)
p.add_option("--gaps", default=False, action="store_true",
help="Only print bed lines for gaps [default: %default]")
p.add_option("--nogaps", default=False, action="store_true",
help="Do not print bed ... | def bed(args) | %prog bed agpfile
print out the tiling paths in bed/gff3 format | 2.74566 | 2.663605 | 1.030806 |
from jcvi.formats.sizes import Sizes
p = OptionParser(extendbed.__doc__)
p.add_option("--nogaps", default=False, action="store_true",
help="Do not print bed lines for gaps [default: %default]")
p.add_option("--bed12", default=False, action="store_true",
help="Produce bed12 ... | def extendbed(args) | %prog extend agpfile componentfasta
Extend the components to fill the component range. For example, a bed/gff3 file
that was converted from the agp will contain only the BAC sequence intervals
that are 'represented' - sometimes leaving the 5` and 3` out (those that
overlap with adjacent sequences. This... | 2.967428 | 2.862996 | 1.036477 |
from jcvi.graphics.histogram import loghistogram
p = OptionParser(gaps.__doc__)
p.add_option("--merge", dest="merge", default=False, action="store_true",
help="Merge adjacent gaps (to conform to AGP specification)")
p.add_option("--header", default=False, action="store_true",
... | def gaps(args) | %prog gaps agpfile
Print out the distribution of gapsizes. Option --merge allows merging of
adjacent gaps which is used by tidy(). | 3.204218 | 3.064405 | 1.045625 |
p = OptionParser(tidy.__doc__)
p.add_option("--nogaps", default=False, action="store_true",
help="Remove all gap lines [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(p.print_help())
agpfile, componentfasta = args
originalagpfile ... | def tidy(args) | %prog tidy agpfile componentfasta
Given an agp file, run through the following steps:
1. Trim components with dangling N's
2. Merge adjacent gaps
3. Trim gaps at the end of an object
4. Reindex the agp
Final output is in `.tidy.agp`. | 2.768222 | 2.382331 | 1.16198 |
p = OptionParser(build.__doc__)
p.add_option("--newagp", dest="newagp", default=False, action="store_true",
help="Check components to trim dangling N's [default: %default]")
p.add_option("--novalidate", dest="novalidate", default=False,
action="store_true",
help="Don... | def build(args) | %prog build agpfile componentfasta targetfasta
Build targetfasta based on info from agpfile | 2.809321 | 2.346373 | 1.197304 |
p = OptionParser(validate.__doc__)
opts, args = p.parse_args(args)
try:
agpfile, componentfasta, targetfasta = args
except Exception as e:
sys.exit(p.print_help())
agp = AGP(agpfile)
build = Fasta(targetfasta)
bacs = Fasta(componentfasta, index=False)
# go throug... | def validate(args) | %prog validate agpfile componentfasta targetfasta
validate consistency between agpfile and targetfasta | 3.667872 | 3.058733 | 1.199148 |
d = {}
for (i, x) in enumerate(self):
if x.is_gap:
continue
xid = x.component_id
d[xid] = (i, x)
xid = xid.rsplit(".", 1)[0] # Remove Genbank version
if xid not in d:
d[xid] = (i, x)
return d | def order(self) | Returns a dict with component_id => (i, agpline) | 4.569528 | 3.396743 | 1.345268 |
north = self.getAdjacentClone(i, south=False)
south = self.getAdjacentClone(i)
return north, south | def getNorthSouthClone(self, i) | Returns the adjacent clone name from both sides. | 5.888653 | 3.992929 | 1.47477 |
print("\n".join(self.header), file=fw) | def transfer_header(self, fw=sys.stdout) | transfer_header() copies header to a new file.
print_header() creates a new header. | 6.754886 | 5.773347 | 1.170012 |
components = []
total_bp = 0
for line in lines:
if line.is_gap:
seq = 'N' * line.gap_length
if newagp:
print(line, file=newagp)
else:
seq = fasta.sequence(dict(chr=line.component_id,
... | def build_one(self, object, lines, fasta, fw, newagp=None) | Construct molecule using component fasta sequence | 4.039339 | 3.996304 | 1.010769 |
rr = xrange(i + 1, len(self)) if south else xrange(i - 1, -1, -1)
a = self[i]
for ix in rr:
x = self[ix]
if x.object != a.object:
break
return x
return None | def getAdjacentClone(self, i, south=True) | Returns adjacent clone name, either the line before or after the current
line. | 3.642102 | 3.478243 | 1.04711 |
from jcvi.formats.base import SetFile
from jcvi.formats.gff import Gff
p = OptionParser(pasa.__doc__)
p.set_home("pasa")
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
fastafile, gffile = args
transcodergff = fastafile + ".transdecoder.gff... | def pasa(args) | %prog ${pasadb}.assemblies.fasta ${pasadb}.pasa_assemblies.gff3
Wraps `pasa_asmbls_to_training_set.dbi`. | 2.920346 | 2.604823 | 1.12113 |
p = OptionParser(genemark.__doc__)
p.add_option("--junctions", help="Path to `junctions.bed` from Tophat2")
p.set_home("gmes")
p.set_cpus(cpus=32)
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
species, fastafile = args
junctions = opts.jun... | def genemark(args) | %prog genemark species fastafile
Train GENEMARK model given fastafile. GENEMARK self-trains so no trainig
model gff file is needed. | 4.903391 | 4.63233 | 1.058515 |
p = OptionParser(snap.__doc__)
p.set_home("maker")
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(not p.print_help())
species, gffile, fastafile = args
mhome = opts.maker_home
snapdir = "snap"
mkdir(snapdir)
cwd = os.getcwd()
os.chdir(snapdir)
ne... | def snap(args) | %prog snap species gffile fastafile
Train SNAP model given gffile and fastafile. Whole procedure taken from:
<http://gmod.org/wiki/MAKER_Tutorial_2012> | 4.54285 | 4.106202 | 1.106339 |
p = OptionParser(augustus.__doc__)
p.add_option("--autotrain", default=False, action="store_true",
help="Run autoAugTrain.pl to iteratively train AUGUSTUS")
p.set_home("augustus")
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(not p.print_help())
spec... | def augustus(args) | %prog augustus species gffile fastafile
Train AUGUSTUS model given gffile and fastafile. Whole procedure taken from:
<http://www.molecularevolution.org/molevolfiles/exercises/augustus/training.html> | 4.006951 | 3.778232 | 1.060536 |
from collections import defaultdict
p = OptionParser(prune.__doc__)
add_graph_options(p)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
bestedges, = args
G = read_graph(bestedges, maxerr=opts.maxerr)
reads_to_ctgs = parse_ctgs(bestedges, o... | def prune(args) | %prog prune best.edges
Prune overlap graph. | 2.989878 | 2.934553 | 1.018853 |
p = OptionParser(removecontains.__doc__)
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
contains, gkpStore = args
s = set()
fp = open(contains)
for row in fp:
if row[0] == '#':
continue
iid = int(row.split()[0])
... | def removecontains(args) | %prog removecontains 4-unitigger/best.contains asm.gkpStore
Remove contained reads from gkpStore. This will improve assembly contiguity
without sacrificing accuracy, when using bogart unitigger. | 4.311437 | 3.782345 | 1.139885 |
from jcvi.apps.console import green
p = OptionParser(overlap.__doc__)
p.add_option("--maxerr", default=2, type="int", help="Maximum error rate")
p.add_option("--canvas", default=100, type="int", help="Canvas size")
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.... | def overlap(args) | %prog overlap best.contains iid
Visualize overlaps for a given fragment. Must be run in 4-unitigger. All
overlaps for iid were retrieved, excluding the ones matching best.contains. | 3.961695 | 3.751572 | 1.056009 |
p = OptionParser(merger.__doc__)
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(not p.print_help())
layout, gkpstore, contigs = args
fp = open(layout)
pf = "0"
iidfile = pf + ".iids"
for i, row in enumerate(fp):
logging.debug("Read unitig {0}".format(i... | def merger(args) | %prog merger layout gkpStore contigs.fasta
Merge reads into one contig. | 7.591412 | 6.817116 | 1.113581 |
p = OptionParser(unitigs.__doc__)
p.add_option("--maxerr", default=2, type="int", help="Maximum error rate")
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
bestedges, = args
G = read_graph(bestedges, maxerr=opts.maxerr, directed=True)
H = nx.Gr... | def unitigs(args) | %prog unitigs best.edges
Reads Celera Assembler's "best.edges" and extract all unitigs. | 3.054122 | 2.873889 | 1.062714 |
p = OptionParser(graph.__doc__)
p.add_option("--query", default=-1, type="int",
help="Search from node, -1 to select random node, 0 to disable")
p.add_option("--contig", help="Search from contigs, use comma to separate")
p.add_option("--largest", default=0, type="int", help="Only s... | def graph(args) | %prog graph best.edges
Convert Celera Assembler's "best.edges" to a GEXF which can be used to
feed into Gephi to check the topology of the best overlapping graph. Mutual
best edges are represented as thicker edges.
Reference:
https://github.com/PacificBiosciences/Bioinformatics-Training/blob/maste... | 3.300206 | 3.179338 | 1.038017 |
p = OptionParser(astat.__doc__)
p.add_option("--cutoff", default=1000, type="int",
help="Length cutoff [default: %default]")
p.add_option("--genome", default="",
help="Genome name [default: %default]")
p.add_option("--arrDist", default=False, action="store_true",
... | def astat(args) | %prog astat coverage.log
Create coverage-rho scatter plot. | 2.594877 | 2.540494 | 1.021406 |
if fasta:
s = SeqRecord(shredded_seq, id=fragID, description="")
SeqIO.write([s], fw, "fasta")
return
seq = str(shredded_seq)
slen = len(seq)
qvs = qvchar * slen # shredded reads have default low qv
if clr is None:
clr_beg, clr_end = 0, slen
else:
... | def emitFragment(fw, fragID, libID, shredded_seq, clr=None, qvchar='l', fasta=False) | Print out the shredded sequence. | 2.924759 | 2.886835 | 1.013137 |
p = OptionParser(shred.__doc__)
p.set_depth(depth=2)
p.add_option("--readlen", default=1000, type="int",
help="Desired length of the reads [default: %default]")
p.add_option("--minctglen", default=0, type="int",
help="Ignore contig sequence less than [default: %default]")
... | def shred(args) | %prog shred fastafile
Similar to the method of `shredContig` in runCA script. The contigs are
shredded into pseudo-reads with certain length and depth. | 2.748945 | 2.694163 | 1.020334 |
p = OptionParser(tracedb.__doc__)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(p.print_help())
action, = args
assert action in ("xml", "lib", "frg")
CMD = "tracedb-to-frg.pl"
xmls = glob("xml*")
if action == "xml":
for xml in xmls:
cmd... | def tracedb(args) | %prog tracedb <xml|lib|frg>
Run `tracedb-to-frg.pl` within current folder. | 2.972987 | 2.260542 | 1.315165 |
assert op.exists(fastafile)
matefile = fastafile.rsplit(".", 1)[0] + ".mates"
if op.exists(matefile):
logging.debug("matepairs file `{0}` found".format(matefile))
else:
logging.debug("parsing matepairs from `{0}`".format(fastafile))
matefw = open(matefile, "w")
it =... | def make_matepairs(fastafile) | Assumes the mates are adjacent sequence records | 2.475625 | 2.513575 | 0.984902 |
from jcvi.formats.fasta import clean, make_qual
p = OptionParser(fasta.__doc__)
p.add_option("--clean", default=False, action="store_true",
help="Clean up irregular chars in seq")
p.add_option("--matefile", help="Matepairs file")
p.add_option("--maxreadlen", default=262143, ty... | def fasta(args) | %prog fasta fastafile
Convert reads formatted as FASTA file, and convert to CA frg file. If .qual
file is found, then use it, otherwise just make a fake qual file. Mates are
assumed as adjacent sequence records (i.e. /1, /2, /1, /2 ...) unless a
matefile is given. | 3.382193 | 3.294873 | 1.026502 |
p = OptionParser(sff.__doc__)
p.add_option("--prefix", dest="prefix", default=None,
help="Output frg filename prefix")
p.add_option("--nodedup", default=False, action="store_true",
help="Do not remove duplicates [default: %default]")
p.set_size()
opts, args = p.parse_arg... | def sff(args) | %prog sff sffiles
Convert reads formatted as 454 SFF file, and convert to CA frg file.
Turn --nodedup on if another deduplication mechanism is used (e.g.
CD-HIT-454). See assembly.sff.deduplicate(). | 4.257879 | 3.683872 | 1.155816 |
from jcvi.formats.fastq import guessoffset
p = OptionParser(fastq.__doc__)
p.add_option("--outtie", dest="outtie", default=False, action="store_true",
help="Are these outie reads? [default: %default]")
p.set_phred()
p.set_size()
opts, args = p.parse_args(args)
if len(args... | def fastq(args) | %prog fastq fastqfile
Convert reads formatted as FASTQ file, and convert to CA frg file. | 4.039793 | 3.915254 | 1.031808 |
p = OptionParser(clr.__doc__)
opts, args = p.parse_args(args)
if len(args) < 2:
sys.exit(not p.print_help())
blastfile = args[0]
fastafiles = args[1:]
sizes = {}
for fa in fastafiles:
f = Fasta(fa)
sizes.update(f.itersizes())
b = Blast(blastfile)
for ... | def clr(args) | %prog blastfile fastafiles
Calculate the vector clear range file based BLAST to the vectors. | 2.688478 | 2.366682 | 1.135969 |
import re
if rule is None:
return name
k = re.search("(?<=^head)[0-9]{1,2}$", rule)
if k:
k = k.group(0)
tname = name[int(k):]
else:
k = re.search("(?<=^ohead)[0-9]{1,2}$", rule)
if k:
k = k.group(0)
tname = name[:int(k)]
... | def truncate_name(name, rule=None) | shorten taxa names for tree display
Options of rule. This only affects tree display.
- headn (eg. head3 truncates first 3 chars)
- oheadn (eg. ohead3 retains only the first 3 chars)
- tailn (eg. tail3 truncates last 3 chars)
- otailn (eg. otail3 retains only the last 3 chars)
n = 1 ~ 99 | 1.991637 | 1.812523 | 1.09882 |
for barcode in barcodemap:
if barcode in name:
return barcodemap[barcode]
return name | def decode_name(name, barcodemap) | rename seq/taxon name, typically for a tree display,
according to a barcode map given in a dictionary
By definition barcodes should be distinctive. | 3.392759 | 4.137232 | 0.820055 |
a, b = .1, .6 # Correspond to 200mya and 0mya
def cv(x): return b - (x - b) / (maxx - minx) * (b - a)
ax.plot((a, b), (.5, .5), "k-")
tick = .015
for mya in xrange(maxx - 25, 0, -25):
p = cv(mya)
ax.plot((p, p), (.5, .5 - tick), "k-")
ax.text(p, .5 - 2.5 * tick, str(mya... | def draw_geoscale(ax, minx=0, maxx=175) | Draw geological epoch on million year ago (mya) scale. | 4.852648 | 4.508296 | 1.076382 |
p = OptionParser(main.__doc__)
p.add_option("--outgroup", help="Outgroup for rerooting the tree. " +
"Use comma to separate multiple taxa.")
p.add_option("--noreroot", default=False, action="store_true",
help="Don't reroot the input tree [default: %default]")
p.add... | def main(args) | %prog newicktree
Plot Newick formatted tree. The gene structure can be plotted along if
--gffdir is given. The gff file needs to be `genename.gff`. If --sizes is
on, also show the number of amino acids.
With --barcode a mapping file can be provided to convert seq names to
eg. species names, useful... | 2.992423 | 2.849976 | 1.049982 |
cl = TreeFixCommandline(input=input, \
stree_file=stree_file, smap_file=smap_file, a_ext=a_ext, \
o=o_ext, n=n_ext, **kwargs)
outtreefile = input.rsplit(o_ext, 1)[0] + n_ext
print("TreeFix:", cl, file=sys.stderr)
r, e = cl.run()
if e:
print("***TreeFix could not... | def run_treefix(input, stree_file, smap_file, a_ext=".fasta", \
o_ext=".dnd", n_ext = ".treefix.dnd", **kwargs) | get the ML tree closest to the species tree | 3.280392 | 3.277595 | 1.000853 |
cl = GblocksCommandline(aln_file=align_fasta_file, **kwargs)
r, e = cl.run()
print("Gblocks:", cl, file=sys.stderr)
if e:
print("***Gblocks could not run", file=sys.stderr)
return None
else:
print(r, file=sys.stderr)
alignp = re.sub(r'.*Gblocks alignment:.*\(([... | def run_gblocks(align_fasta_file, **kwargs) | remove poorly aligned positions and divergent regions with Gblocks | 5.344467 | 5.155605 | 1.036632 |
cl = FfitchCommandline(datafile=distfile, outtreefile=outtreefile, \
intreefile=intreefile, **kwargs)
r, e = cl.run()
if e:
print("***ffitch could not run", file=sys.stderr)
return None
else:
print("ffitch:", cl, file=sys.stderr)
return outtreefile | def run_ffitch(distfile, outtreefile, intreefile=None, **kwargs) | Infer tree branch lengths using ffitch in EMBOSS PHYLIP | 4.079683 | 4.297816 | 0.949246 |
tree = Tree(treefile, format=format)
leaves = [t.name for t in tree.get_leaves()][::-1]
outgroup = []
for o in must_open(outgroupfile):
o = o.strip()
for leaf in leaves:
if leaf[:len(o)] == o:
outgroup.append(leaf)
if outgroup:
break
... | def smart_reroot(treefile, outgroupfile, outfile, format=0) | simple function to reroot Newick format tree using ete2
Tree reading format options see here:
http://packages.python.org/ete2/tutorial/tutorial_trees.html#reading-newick-trees | 2.805085 | 2.967949 | 0.945126 |
phy_file = op.join(work_dir, "work", "aln.phy")
AlignIO.write(alignment, file(phy_file, "w"), "phylip-relaxed")
phyml_cl = PhymlCommandline(cmd=PHYML_BIN("phyml"), input=phy_file, **kwargs)
logging.debug("Building ML tree using PhyML: %s" % phyml_cl)
stdout, stderr = phyml_cl()
tree_file ... | def build_ml_phyml(alignment, outfile, work_dir=".", **kwargs) | build maximum likelihood tree of DNA seqs with PhyML | 3.842254 | 3.708928 | 1.035947 |
work_dir = op.join(work_dir, "work")
mkdir(work_dir)
phy_file = op.join(work_dir, "aln.phy")
AlignIO.write(alignment, file(phy_file, "w"), "phylip-relaxed")
raxml_work = op.abspath(op.join(op.dirname(phy_file), "raxml_work"))
mkdir(raxml_work)
raxml_cl = RaxmlCommandline(cmd=RAXML_BIN(... | def build_ml_raxml(alignment, outfile, work_dir=".", **kwargs) | build maximum likelihood tree of DNA seqs with RAxML | 3.287886 | 3.248412 | 1.012152 |
assert op.isfile(reftree)
shout = must_open(shout, "a")
raxml_work = op.abspath(op.join(op.dirname(phy_file), "raxml_work"))
mkdir(raxml_work)
raxml_cl = RaxmlCommandline(cmd=RAXML_BIN("raxmlHPC"), \
sequences=phy_file, algorithm="h", model="GTRGAMMA", \
name="SH", starting_tree=reftre... | def SH_raxml(reftree, querytree, phy_file, shout="SH_out.txt") | SH test using RAxML
querytree can be a single tree or a bunch of trees (eg. from bootstrapping) | 4.58297 | 4.599276 | 0.996455 |
aln = AlignIO.read(alnfle, alntype)
alnlen = aln.get_alignment_length()
nseq = len(aln)
subaln = None
subalnfile = alnfle.rsplit(".", 1)[0] + "_{0}.{1}".format(subtype, alntype)
if subtype == "synonymous":
for j in range( 0, alnlen, 3 ):
aa = None
for i in r... | def subalignment(alnfle, subtype, alntype="fasta") | Subset synonymous or fourfold degenerate sites from an alignment
input should be a codon alignment | 2.104942 | 1.96585 | 1.070754 |
fw = must_open(filename+".merged", "w")
rows = file(filename).readlines()
rows = [row.strip().split(colsep) for row in rows]
l = len(rows[0])
for rowi, row in enumerate(rows):
n = len(rows)
i = rowi+1
while i <= min(rowi+local, n-1):
merge = 1
ro... | def merge_rows_local(filename, ignore=".", colsep="\t", local=10, \
fieldcheck=True, fsep=",") | merge overlapping rows within given row count distance | 2.430209 | 2.420234 | 1.004121 |
tandems = [f.strip().split(",") for f in file(tandemfile)]
fw = must_open(mcscanfile+".withtandems", "w")
fp = must_open(mcscanfile)
seen =set()
for i, row in enumerate(fp):
if row[0] == '#':
continue
anchorslist = row.strip().split("\t")
anchors = set([a.spl... | def add_tandems(mcscanfile, tandemfile) | add tandem genes to anchor genes in mcscan file | 3.290733 | 3.216578 | 1.023054 |
from jcvi.graphics.base import discrete_rainbow
p = OptionParser(prepare.__doc__)
p.add_option("--addtandem", help="path to tandemfile [default: %default]")
p.add_option("--writecolors", default=False, action="store_true", \
help="generate a gene_name to color mapping file which will be ta... | def prepare(args) | %prog prepare mcscanfile cdsfile [options]
Pick sequences from cdsfile to form fasta files, according to multiple
alignment in the mcscanfile.
The fasta sequences can then be used to construct phylogenetic tree.
Use --addtandem=tandemfile to collapse tandems of anchors into single row.
The tandemf... | 3.817101 | 3.440197 | 1.109559 |
from jcvi.graphics.tree import draw_tree
if shfile:
SHs = DictFile(shfile, delimiter="\t")
ntrees = len(trees)
n = nrow * ncol
for x in xrange(int(ceil(float(ntrees)/n))):
fig = plt.figure(1, (iopts.w, iopts.h)) if iopts \
else plt.figure(1, (5, 5))
root ... | def _draw_trees(trees, nrow=1, ncol=1, rmargin=.3, iopts=None, outdir=".",
shfile=None, **kwargs) | Draw one or multiple trees on one plot. | 2.801075 | 2.812183 | 0.99605 |
p = OptionParser(enrich.__doc__)
p.add_option("--ghost", default=False, action="store_true",
help="Add ghost homologs already used [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 3:
sys.exit(not p.print_help())
omgfile, groupsfile, ntaxa = args
... | def enrich(args) | %prog enrich omgfile groups ntaxa > enriched.omg
Enrich OMG output by pulling genes misses by OMG. | 3.139113 | 2.95506 | 1.062284 |
from jcvi.formats.base import DictFile
outfile = listfile.rsplit(".", 1)[0] + ".sorted.list"
threadorder = thread.order
fw = open(outfile, "w")
lt = DictFile(listfile, keypos=column, valuepos=None)
threaded = []
imported = set()
for t in thread:
accn = t.accn
if acc... | def sort_layout(thread, listfile, column=0) | Sort the syntelog table according to chromomomal positions. First orient the
contents against threadbed, then for contents not in threadbed, insert to
the nearest neighbor. | 3.601279 | 3.513239 | 1.025059 |
p = OptionParser(layout.__doc__)
p.add_option("--sort",
help="Sort layout file based on bedfile [default: %default]")
opts, args = p.parse_args(args)
if len(args) != 2:
sys.exit(not p.print_help())
omgfile, taxa = args
listfile = omgfile.rsplit(".", 1)[0] + ".list... | def layout(args) | %prog layout omgfile taxa
Build column formatted gene lists after omgparse(). Use species list
separated by comma in place of taxa, e.g. "BR,BO,AN,CN" | 3.366796 | 3.118494 | 1.079622 |
p = OptionParser(omgparse.__doc__)
opts, args = p.parse_args(args)
if len(args) != 1:
sys.exit(not p.print_help())
work, = args
omgfiles = glob(op.join(work, "gf*.out"))
for omgfile in omgfiles:
omg = OMGFile(omgfile)
best = omg.best()
for bb in best:
... | def omgparse(args) | %prog omgparse work
Parse the OMG outputs to get gene lists. | 3.569541 | 2.884035 | 1.23769 |
p = OptionParser(group.__doc__)
p.set_outfile()
opts, args = p.parse_args(args)
if len(args) < 1:
sys.exit(not p.print_help())
anchorfiles = args
groups = Grouper()
for anchorfile in anchorfiles:
ac = AnchorFile(anchorfile)
for a, b, idx in ac.iter_pairs():
... | def group(args) | %prog group anchorfiles
Group the anchors into ortho-groups. Can input multiple anchor files. | 3.398792 | 2.947951 | 1.152933 |
p = OptionParser(omg.__doc__)
opts, args = p.parse_args(args)
if len(args) < 1:
sys.exit(not p.print_help())
weightsfiles = args
groupfile = group(weightsfiles + ["--outfile=groups"])
weights = get_weights(weightsfiles)
info = get_info()
fp = open(groupfile)
work =... | def omg(args) | %prog omg weightsfile
Run Sankoff's OMG algorithm to get orthologs. Download OMG code at:
<http://137.122.149.195/IsbraSoftware/OMGMec.html>
This script only writes the partitions, but not launch OMGMec. You may need to:
$ parallel "java -cp ~/code/OMGMec TestOMGMec {} 4 > {}.out" ::: work/gf?????
... | 4.323682 | 4.224358 | 1.023512 |
from jcvi.formats.blast import cscore
from jcvi.formats.base import DictFile
p = OptionParser(omgprepare.__doc__)
p.add_option("--norbh", action="store_true",
help="Disable RBH hits [default: %default]")
p.add_option("--pctid", default=0, type="int",
help="Per... | def omgprepare(args) | %prog omgprepare ploidy anchorsfile blastfile
Prepare to run Sankoff's OMG algorithm to get orthologs. | 3.229771 | 3.051083 | 1.058566 |
p = OptionParser(tandem.__doc__)
p.add_option("--tandem_Nmax", dest="tandem_Nmax", type="int", default=3,
help="merge tandem genes within distance [default: %default]")
p.add_option("--percent_overlap", type="int", default=50,
help="tandem genes have >=x% aligned sequence,... | def tandem(args) | %prog tandem blast_file cds_file bed_file [options]
Find tandem gene clusters that are separated by N genes, based on filtered
blast_file by enforcing alignments between any two genes at least 50%
(or user specified value) of either gene.
pep_file can also be used in same manner. | 3.614868 | 3.368327 | 1.073194 |
od = DefaultOrderedDict(list) if keep_attr_order else defaultdict(list)
for name, value in parse_qsl(qs, keep_blank_values, strict_parsing):
od[name].append(value)
return od | def parse_qs(qs, keep_blank_values=0, strict_parsing=0, keep_attr_order=True) | Kind of like urlparse.parse_qs, except returns an ordered dict.
Also avoids replicating that function's bad habit of overriding the
built-in 'dict' type.
Taken from below with modification:
<https://bitbucket.org/btubbs/thumpy/raw/8cdece404f15/thumpy.py> | 2.641404 | 2.917453 | 0.90538 |
'Find the position of an item. Raise ValueError if not found.'
k = self._key(item)
i = bisect_left(self._keys, k)
j = bisect_right(self._keys, k)
return self._items[i:j].index(item) + i | def index(self, item) | Find the position of an item. Raise ValueError if not found. | 3.423772 | 2.824538 | 1.212153 |
'Insert a new item. If equal keys are found, add to the left'
k = self._key(item)
i = bisect_left(self._keys, k)
self._keys.insert(i, k)
self._items.insert(i, item) | def insert(self, item) | Insert a new item. If equal keys are found, add to the left | 4.230717 | 2.620456 | 1.614497 |
'Insert a new item. If equal keys are found, add to the right'
k = self._key(item)
i = bisect_right(self._keys, k)
self._keys.insert(i, k)
self._items.insert(i, item) | def insert_right(self, item) | Insert a new item. If equal keys are found, add to the right | 3.95288 | 2.625476 | 1.505586 |
'Remove first occurence of item. Raise ValueError if not found'
i = self.index(item)
del self._keys[i]
del self._items[i] | def remove(self, item) | Remove first occurence of item. Raise ValueError if not found | 4.914875 | 4.028533 | 1.220016 |
'Return first item with a key >= equal to item. Raise ValueError if not found'
k = self._key(item)
i = bisect_left(self._keys, k)
if i != len(self):
return self._items[i]
raise ValueError('No item found with key at or above: %r' % (k,)) | def find_ge(self, item) | Return first item with a key >= equal to item. Raise ValueError if not found | 4.313375 | 3.196421 | 1.349439 |
'Return first item with a key > item. Raise ValueError if not found'
k = self._key(item)
i = bisect_right(self._keys, k)
if i != len(self):
return self._items[i]
raise ValueError('No item found with key above: %r' % (k,)) | def find_gt(self, item) | Return first item with a key > item. Raise ValueError if not found | 4.462658 | 3.284884 | 1.358543 |
from jcvi.apps.grid import MakeManager
p = OptionParser(batch.__doc__)
opts, args = p.parse_args(args)
if len(args) < 2:
sys.exit(not p.print_help())
cdsfile = args[0]
anchors = args[1:]
workdirs = [".".join(op.basename(x).split(".")[:2]) for x in anchors]
for wd in workd... | def batch(args) | %prog batch all.cds *.anchors
Compute Ks values for a set of anchors file. This will generate a bunch of
work directories for each comparisons. The anchorsfile should be in the form
of specie1.species2.anchors. | 3.51845 | 3.138587 | 1.12103 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.