本文整理汇总了Python中neurosynth.base.dataset.Dataset.get_mappables方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.get_mappables方法的具体用法?Python Dataset.get_mappables怎么用?Python Dataset.get_mappables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neurosynth.base.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.get_mappables方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from neurosynth.base.dataset import Dataset [as 别名]
# 或者: from neurosynth.base.dataset.Dataset import get_mappables [as 别名]
class NeuroSynth:
"""Initialize Neurosynth Database"""
def __init__(self, dbsize):
print "Initializing Neurosynth database..."
self.db = Dataset("data/" + str(dbsize) + "terms/database.txt")
self.db.add_features("data/" + str(dbsize) + "terms/features.txt")
self.ids = self.getIDs()
self.decoder = None
# self.masker = mask.Mask("data/X.nii.gz")
"""Do contrast analysis between two sets of """
def neurosynthContrast(self, papers1, papers2, fdr, outdir=None, outprefix=None, image_list=None):
# Do a meta analysis to contrast the two
ma = meta.MetaAnalysis(self.db, papers1, papers2, q=float(fdr))
if outdir:
print "Saving results to %s" % (outdir)
ma.save_results(outdir, prefix=outprefix, prefix_sep="_", image_list=image_list)
return ma.images
"""Conduct meta analysis with particular set of ids"""
def neurosynthMeta(self, papers, fdr, outdir=None, outprefix=None, image_list=None):
# Get valid ids from user list
valid_ids = self.get_valid_ids(papers)
if len(valid_ids) > 0:
# Do meta analysis
ma = meta.MetaAnalysis(self.db, valid_ids, q=float(fdr))
if outdir:
print "Saving results to output directory %s" % (outdir)
ma.save_results(outdir, prefix=outprefix, prefix_sep="_", image_list=image_list)
return ma.images
else:
print "No studies found in database for ids in question!"
"""Return list of valid ids from user input"""
def get_valid_ids(self, papers):
# Input is DOI with list of papers
valid_ids = [x for x in papers if int(x.strip(" ")) in self.ids]
print "Found %s valid ids." % (str(len(valid_ids)))
return valid_ids
"""Decode an image, return 100 results"""
def decode(self, images, outfile, mrs=None, round=4):
if not self.decoder:
self.decoder = decode.Decoder(self.db)
# If mrs is not specified, do decoding against neurosynth database
if not mrs:
result = self.decoder.decode(images, save=outfile)
# If mrs is specified, do decoding against custom set of images
else:
# This is akin to traditional neurosynth method - pearson's r correlation
imgs_to_compare = imageutils.load_imgs(mrs, self.masker)
imgs_to_decode = imageutils.load_imgs(images, self.masker)
x, y = imgs_to_compare.astype(float), imgs_to_decode.astype(float)
x, y = x - x.mean(0), y - y.mean(0)
x, y = x / np.sqrt((x ** 2).sum(0)), y / np.sqrt((y ** 2).sum(0))
result = np.around(x.T.dot(y).T, round)
features = [os.path.basename(m) for m in mrs]
rownames = [os.path.basename(m) for m in images]
df = pd.DataFrame(result, columns=features)
df.index = rownames
df.to_csv(outfile, sep="\t")
return result
"""Return features in neurosynth database"""
def getFeatures(self, dataset):
return dataset.get_feature_names()
"""Extract pubmed IDs or dois from Neurosynth Database"""
def getIDs(self):
# Get all IDs in neuroSynth
return self.db.image_table.ids
"""Extract author names for a given pmid or doi"""
def getAuthor(self, db, id):
article = self.db.get_mappables(id)
meta = article[0].__dict__
tmp = meta["data"]["authors"]
tmp = tmp.split(",")
authors = [x.strip("^ ") for x in tmp]
return authors
"""Extract all author names in database"""
def getAuthors(self, db):
articles = db.mappables
uniqueAuthors = []
for a in articles:
#.........这里部分代码省略.........