本文整理汇总了Python中natsort.natsorted函数的典型用法代码示例。如果您正苦于以下问题:Python natsorted函数的具体用法?Python natsorted怎么用?Python natsorted使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了natsorted函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_exonerate
def main_exonerate(ref_fa,refseq_pr,exonerate_path,thread,exon2align_gff,index_s=0,index_e=0):
'''
* refseq_pr: all protein seqeunces of the organism
* path: path to store splited protein sequences.
'''
if not os.path.exists(exonerate_path): os.mkdir(exonerate_path)
# 1) split file
os.chdir(exonerate_path)
if os.listdir(path) != []:
split_fa(refseq_pr,100,exonerate_path)
# 2) run exonerate for each file
faFiles = natsorted(glob.glob('file*.fa'))
if index_e == 0:
faFiles = faFiles[index_s:]
else:
faFiles = faFiles[index_s:index_e]
pool = mp.Pool(processes=int(thread))
for f in faFiles:
out = f[:-2]+'gff'
pool.apply_async(exonerate,args=(ref_fa,f,out))
pool.close()
pool.join()
# 3) merge the gff files
exonerate_gff = 'exonerate.gff'
if not os.path.exists(exonerate_gff):
gff_fns = natsorted(glob.glob('file*.gff'))
exonerate2gff(gff_fns,exonerate_gff)
示例2: find_idle_busy_slaves
def find_idle_busy_slaves(parser, args, show_idle):
parser.add_option(
'-b', '--builder', dest='builders', action='append', default=[],
help='Builders to filter on')
parser.add_option(
'-s', '--slave', dest='slaves', action='append', default=[],
help='Slaves to filter on')
options, args, buildbot = parser.parse_args(args)
if args:
parser.error('Unrecognized parameters: %s' % ' '.join(args))
if not options.builders:
options.builders = buildbot.builders.keys
for builder in options.builders:
builder = buildbot.builders[builder]
if options.slaves:
# Only the subset of slaves connected to the builder.
slaves = list(set(options.slaves).intersection(set(builder.slaves.names)))
if not slaves:
continue
else:
slaves = builder.slaves.names
busy_slaves = [build.slave.name for build in builder.current_builds]
if show_idle:
slaves = natsorted(set(slaves) - set(busy_slaves))
else:
slaves = natsorted(set(slaves) & set(busy_slaves))
if options.quiet:
for slave in slaves:
print slave
else:
if slaves:
print 'Builder %s: %s' % (builder.name, ', '.join(slaves))
return 0
示例3: _get_list_of_files
def _get_list_of_files(self,path):
"""
Go through each subdirectory of `path`, and choose one file from each to use in our hash.
Continue to increase self.iter, so we use a different 'slot' of randomness each time.
"""
chosen_files = []
# Get a list of all subdirectories
directories = []
for root, dirs, files in natsort.natsorted(os.walk(path, topdown=False)):
for name in dirs:
if name[:1] is not '.':
directories.append(os.path.join(root, name))
directories = natsort.natsorted(directories)
# Go through each directory in the list, and choose one file from each.
# Add this file to our master list of robotparts.
for directory in directories:
files_in_dir = []
for imagefile in natsort.natsorted(os.listdir(directory)):
files_in_dir.append(os.path.join(directory,imagefile))
files_in_dir = natsort.natsorted(files_in_dir)
# Use some of our hash bits to choose which file
element_in_list = self.hasharray[self.iter] % len(files_in_dir)
chosen_files.append(files_in_dir[element_in_list])
self.iter += 1
return chosen_files
示例4: scenarios_comms
def scenarios_comms(paths):
subdirs = natsorted(map_paths(paths))
for i, subdir in enumerate(natsorted(subdirs)):
title = os.path.basename(subdir)
sources = npz_in_dir(subdir)
log.info("{0:%}:{1}:{2}/{3}".format(float(i) / float(len(subdirs)), title, memory(), swapsize()))
yield (subdir, generate_sources(sources, comms_only=True))
示例5: write_excel_data
def write_excel_data(dev_data, norm_to_ctrl, norm_to_mean):
"""Write data into a file"""
# Define excel directory
xls_dir = "./excel"
# Change directory to EXPROOTPATH
os.chdir(EXPROOTPATH)
# Check to see if excel directory exists and if it doesn't make it
try:
os.makedirs(xls_dir)
except OSError:
if not os.path.isdir(xls_dir):
raise
# Reorder
dev_data = dev_data.reorder_levels(['device', 'interval', 'well'])
norm_to_ctrl = norm_to_ctrl.stack().unstack(-4).reorder_levels(['device', 'interval', 2]) #.sort_index(0)
norm_to_mean = norm_to_mean.stack().unstack(-4).reorder_levels(['device', 'interval', 2])
# Sort
dev_data = dev_data.reindex(index=natsorted(dev_data.index))
norm_to_ctrl = norm_to_ctrl.reindex(index=natsorted(norm_to_ctrl.index))
norm_to_mean = norm_to_mean.reindex(index=natsorted(norm_to_mean.index))
# Create the Excel Workbook
writer = pd.ExcelWriter(xls_dir+"/"+'data.xlsx', engine='xlsxwriter')
# Write the data to the Excel Workbook
dev_data.to_excel(writer, sheet_name='Raw_Device_Data')
norm_to_ctrl.to_excel(writer, sheet_name='Ratio_to_Control')
norm_to_mean.to_excel(writer, sheet_name='Ratio_to_Control_2')
示例6: get_metadata
def get_metadata(path, band_name, git_root):
try:
with open(os.path.join(path, 'description'), 'r') as desc:
description = desc.read()
except Exception:
description = ''
metadata = {'name': band_name,
'description': description,
'albums': [],
'git_root': git_root}
album_paths = natsort.natsorted(os.listdir(path))
for album_name in filter(lambda a: filter_album_names(path, a), album_paths):
album_path = os.path.join(path, album_name)
try:
with open(os.path.join(album_path, 'description'), 'r') as desc:
album_description = desc.read()
except Exception:
album_description = 'Shorts are comfy and easy to wear!'
tracks = []
track_number = 1
track_paths = natsort.natsorted(os.listdir(album_path))
for track in filter(filter_tracks, track_paths):
track_name = clean_track_name(track)
tracks.append({'number': track_number,
'name': track_name,
'path': os.path.join(album_path, track)})
track_number += 1
metadata['albums'].append({'name': album_name,
'path': album_path,
'tracks': tracks,
'description': album_description})
return metadata
示例7: listFiles
def listFiles():
""" Lists all available Charmm topologies and parameter files
Examples
--------
>>> from htmd.builder import charmm
>>> charmm.listFiles() # doctest: +ELLIPSIS
---- Topologies files list...
"""
from natsort import natsorted
charmmdir = path.join(home(), 'builder', 'charmmfiles', '') # maybe just lookup current module?
topos = natsorted(glob(path.join(charmmdir, 'top', '*.rtf')))
params = natsorted(glob(path.join(charmmdir, 'par', '*.prm')))
streams = natsorted(glob(path.join(charmmdir, 'str', '*', '*.str')))
print('---- Topologies files list: ' + path.join(charmmdir, 'top', '') + ' ----')
for t in topos:
t = t.replace(charmmdir, '')
print(t)
print('---- Parameters files list: ' + path.join(charmmdir, 'par', '') + ' ----')
for p in params:
p = p.replace(charmmdir, '')
print(p)
print('---- Stream files list: ' + path.join(charmmdir, 'str', '') + ' ----')
for s in streams:
s = s.replace(charmmdir, '')
print(s)
示例8: test_natsorted_with_LOCALE_and_mixed_input_returns_sorted_results_without_error
def test_natsorted_with_LOCALE_and_mixed_input_returns_sorted_results_without_error():
load_locale('en_US')
a = ['0', 'Á', '2', 'Z']
assert natsorted(a) == ['0', '2', 'Z', 'Á']
a = ['2', 'ä', 'b', 1.5, 3]
assert natsorted(a, alg=ns.LOCALE) == [1.5, '2', 3, 'ä', 'b']
locale.setlocale(locale.LC_ALL, str(''))
示例9: test_natsorted_returns_sorted_list_with_mixed_type_input_and_does_not_raise_TypeError_on_Python3
def test_natsorted_returns_sorted_list_with_mixed_type_input_and_does_not_raise_TypeError_on_Python3():
# You can mix types with natsorted. This can get around the new
# 'unorderable types' issue with Python 3.
a = [6, 4.5, '7', '2.5', 'a']
assert natsorted(a) == ['2.5', 4.5, 6, '7', 'a']
a = [46, '5a5b2', 'af5', '5a5-4']
assert natsorted(a) == ['5a5-4', '5a5b2', 46, 'af5']
示例10: render_listing
def render_listing(in_name, out_name, folders=[], files=[]):
if in_name:
with open(in_name, 'r') as fd:
try:
lexer = get_lexer_for_filename(in_name)
except:
lexer = TextLexer()
code = highlight(fd.read(), lexer,
HtmlFormatter(cssclass='code',
linenos="table", nowrap=False,
lineanchors=utils.slugify(in_name),
anchorlinenos=True))
title = os.path.basename(in_name)
else:
code = ''
title = ''
crumbs = utils.get_crumbs(os.path.relpath(out_name,
kw['output_folder']),
is_file=True)
context = {
'code': code,
'title': title,
'crumbs': crumbs,
'lang': kw['default_lang'],
'folders': natsort.natsorted(folders),
'files': natsort.natsorted(files),
'description': title,
}
self.site.render_template('listing.tmpl', out_name,
context)
示例11: metadata_stats_from_sample_and_prep_templates
def metadata_stats_from_sample_and_prep_templates(st, pt):
"""Print out summary statistics for the sample and prep templates
Parameters
----------
st : SampleTemplate
Initialized SampleTemplate to use for the metadat stats.
pt : PrepTemplate
Initialized PrepTemplate to use for the metadat stats.
Returns
-------
dict
Dictionary object where the keys are the names of the metadata
categories and the keys are tuples where the first element is the name
of a metadata value in category and the second element is the number of
times that value was seen.
"""
df = metadata_map_from_sample_and_prep_templates(st, pt)
out = {}
for column in natsorted(df.columns):
counts = df[column].value_counts()
# get a pandas series of the value-count pairs
out[column] = [(key, counts[key]) for key in natsorted(counts.index)]
return out
示例12: __GetOBSDatasetName
def __GetOBSDatasetName(self, band):
self.refBand = dict()
self.emisBand = dict()
self.refBandname = dict()
self.emisBandname = dict()
for band in self.OrbitInfo.BandsType:
if self.OrbitInfo.BandsType[band] == 'REF':
self.refBand[band] = self.OrbitInfo.BandsType[band]
else:
self.emisBand[band] = self.OrbitInfo.BandsType[band]
self.refBand = natsorted(self.refBand, alg=ns.IGNORECASE)
self.emisBand = natsorted(self.emisBand, alg=ns.IGNORECASE)
refNum = 0
for refband in self.refBand:
self.refBandname[refband] = refNum
refNum = refNum + 1
emisNum = 0
for emisband in self.emisBand:
self.emisBandname[emisband] = emisNum
emisNum = emisNum + 1
return self.refBandname, self.emisBandname
示例13: get_cover
def get_cover (filepath):
path = root + '/' + filepath
if os.path.isdir(path):
files = quick(os.listdir(path))
image = path + '/' + cover_cleaner(files)
with open(image, 'rb') as file_:
cover = file_.read()
return cover
elif os.path.isfile(path):
filetype = path.split('.')[-1]
if filetype == 'zip':
with ZipFile(path) as archive:
files = natsorted(archive.namelist())
image = cover_cleaner(files)
with archive.open(image) as file_:
cover = file_.read()
return cover
elif filetype == 'rar':
with rarfile.RarFile(path) as archive:
files = natsorted(archive.namelist())
image = cover_cleaner(files)
with archive.open(image) as file_:
cover = file_.read()
return cover
示例14: fpkm_from_htseq
def fpkm_from_htseq(bam_path,ruv_path,exn_file):
"""
This function calculates fpkm from the htseq-count results.
* bam_path: pathway that has bam files. Used to get total mapped reads.
* ruv_path: pathway that has ruvseq corrected count data.
* exn_file: 6 columns. including ['chr','start','end','geneid','traccess','strand'].
output file that ends with .fpkm.
"""
os.chdir(bam_path)
bams = [f for f in os.listdir(bam_path) if f.endswith('.bam')]
bams = natsorted(bams)
# 1. get total count
totalCount = []
for b in bams:
bamHandle = pysam.AlignmentFile(b,'rb')
totalCount.append(bamHandle.mapped)
# 2. get rna_obj
rna_df = pd.read_csv(exn_file,sep='\t',header=0,low_memory=False)
rna_obj = trpr(rna_df)
# 3. get length for each gene
os.chdir(ruv_path)
norm_count_files = [f for f in os.listdir(ruv_path) if f.endswith('.txt')]
norm_count_files = natsorted(norm_count_files)
for fn,total in zip(norm_count_files,totalCount):
df = pd.read_csv(fn,sep=' ',header=None,names=['geneid','count'],index_col=0,low_memory=False)
df['len'] = df.index.map(lambda x: rna_obj.get_gene_trpr_len(x,multi_chrom='Y'))
df['fpkm'] = df['count']/float(total)/df['len']*10**9
df['fpkm'].ix[:-20].to_csv(fn[:-3]+'fpkm.txt',sep='\t')
示例15: get_page
def get_page (filepath, pagenum):
path = root + '/' + filepath
if os.path.isdir(path):
files = natsorted(os.listdir(path))
files = pages_cleaner(files)
image = path + '/' + files[pagenum - 1]
with open(image, 'rb') as file_:
page = file_.read()
return page
elif os.path.isfile(path):
filetype = path.split('.')[-1]
if filetype == 'zip':
with ZipFile(path) as archive:
files = natsorted(archive.namelist())
files = pages_cleaner(files)
image = files[pagenum - 1]
with archive.open(image) as file_:
page = file_.read()
return page
elif filetype == 'rar':
with rarfile.RarFile(path) as archive:
files = natsorted(archive.namelist())
files = pages_cleaner(files)
image = files[pagenum - 1]
with archive.open(image) as file_:
page = file_.read()
return page