Пример #1
0
if __name__ == "__main__":
	pt = ProgramTimer()
	parser = OptionParser(version="%prog 0.8")
	parser.add_option("-s","--samples_filename",help="Read samples from FILE",metavar="FILE")
	parser.add_option("-m","--model_filename",help="Read rules from FILE",metavar="FILE")
	parser.add_option("-t","--target_sample",help="Set the target SAMPLE for selecting",metavar="SAMPLE")
	parser.add_option("-f","--target_samples_filename",help="Read target samples from filename, one per line")
	parser.add_option("-o","--output_filename",help="Write selected rules to FILE",metavar="FILE")
	parser.add_option("-g","--output_genomes",action="store_true",default=False,help="Output genomes that satisfy rules instead")
	
	(options, args) = parser.parse_args()

	
	pt.start()
	fileio = FileIO()
	samples = fileio.load_samples(options.samples_filename)
	target_samples = []
	if options.target_sample:
		for sample in samples:
			if (sample.id == options.target_sample):
				target_samples.append(sample)
	elif options.target_samples_filename:
		target_sample_ids = [x.strip() for x in open(options.target_samples_filename).readlines()]
		for target_sample_id in target_sample_ids:
			for sample in samples:
				if (sample.id == target_sample_id):
					target_samples.append(sample)
	else:
		print "You must specify a target sample"
		sys.exit(1)
	
Пример #2
0
		errorCount += 1
	if not options.input_classes_filename:
		error("Please provide a phenotype class file with -c /path/to/phenotype.file")
		errorCount += 1
	if not options.target_class:
		error("Please provide the phenotype target to be predicted with -t \"TRAITNAME\"")
		errorCount += 1
	if not options.output_filename:
		error("Please specify a file for the output with -o /path/to/result.file")
		errorCount += 1
	if errorCount > 0:
		error("For help on usage, try calling:\n\tpython %s -h" % os.path.basename(sys.argv[0]))
		exit(1)
		
	fileio = FileIO()
	samples = fileio.load_samples(options.input_samples_filename)
	if options.feature_select:
		print "Selecting top %d features from %s, ordered by %s"%(options.feature_select_top_n,options.feature_select,options.feature_select_score)
		from pica.AssociationRule import load_rules,AssociationRuleSet
		selected_rules = AssociationRuleSet()
		rules = load_rules(options.feature_select)
		rules.set_target_accuracy(options.feature_select_score)
		selected_rules.extend(rules[:options.feature_select_top_n])
		samples = samples.feature_select(selected_rules)
	classes = fileio.load_classes(options.input_classes_filename)
	samples.load_class_labels(classes)
	print "Sample set has %d features."%(samples.get_number_of_features())
	samples.set_current_class(options.target_class)
	print "Parameters from %s"%(options.parameters)
	print "Compressing features...",
	samples = samples.compress_features()
Пример #3
0

samples_filename = sys.argv[1]
class_labels_filename = sys.argv[2]
metadata_filename = sys.argv[3]
output_filename = sys.argv[4]

from pica.Sample import SampleSet, ClassLabelSet
from pica.io.FileIO import FileIO
from pica.IntegerMapping import IntegerMapping
from pica.trainers.cwmi.CWMILibrary import CWMILibrary

fileio = FileIO()
cwmilibrary = CWMILibrary()
metadata = fileio.load_metadata(metadata_filename)
samples = fileio.load_samples(samples_filename)
classes = fileio.load_classes(class_labels_filename)
samples.load_class_labels(classes)
confounders = metadata.get_key_list()[1:]

outlines = []
header_line = ["phenotype"]

header_line.extend(confounders)
header_line.append("total")
outlines.append("\t".join(header_line))

for class_name in classes.get_classes():
	"generate phenotype map"
	
	samples.set_current_class(class_name)
Пример #4
0
	if not options.input_samples_filename:
		error("Please provide a genotype sample file with -s /path/to/genotype.file")
		errorCount += 1
	if not options.model_filename:
		error("Please provide a model file for this phenotype with -m /path/to/model.file")
		errorCount += 1
	if not options.target_class:
		error("Please provide the phenotype target to be predicted with -t \"TRAITNAME\"")
		errorCount += 1
	if errorCount > 0:
		error("For help on usage, try calling:\n\tpython %s -h" % os.path.basename(sys.argv[0]))
		exit(1)
	
	fileio = FileIO()
	if options.algorithm == "libsvm.libSVMClassifier": # RVF: part of SVM fix (feature-index map)
		samples = fileio.load_samples(options.input_samples_filename, indexToAttribute=options.model_filename)
	else: #original code
		samples = fileio.load_samples(options.input_samples_filename)
	if options.input_classes_filename:
		classes = fileio.load_classes(options.input_classes_filename)
	else:
		classes = fileio.init_null_classes(options.input_samples_filename, options.target_class)
	
	#RVF
	"""rules = load_rules(options.model_filename) #original code"""
	if options.algorithm == "libsvm.libSVMClassifier":
		m = svm_model(options.model_filename)
		with open(options.model_filename+".classlabelmap", 'rb') as handle:
			clm = pickle.loads(handle.read())
		with open(options.model_filename+".classlabelmapindex", 'rb') as handle:
			clmi= pickle.loads(handle.read())
Пример #5
0
import sys

samples_filename = sys.argv[1]
class_labels_filename = sys.argv[2]
metadata_filename = sys.argv[3]
output_filename = sys.argv[4]

from pica.Sample import SampleSet, ClassLabelSet
from pica.io.FileIO import FileIO
from pica.IntegerMapping import IntegerMapping
from pica.trainers.cwmi.CWMILibrary import CWMILibrary

fileio = FileIO()
cwmilibrary = CWMILibrary()
metadata = fileio.load_metadata(metadata_filename)
samples = fileio.load_samples(samples_filename)
classes = fileio.load_classes(class_labels_filename)
samples.load_class_labels(classes)
confounders = metadata.get_key_list()[1:]

outlines = []
header_line = ["phenotype"]

header_line.extend(confounders)
header_line.append("total")
outlines.append("\t".join(header_line))

for class_name in classes.get_classes():
    "generate phenotype map"

    samples.set_current_class(class_name)
Пример #6
0
            "Please provide a model file for this phenotype with -m /path/to/model.file"
        )
        errorCount += 1
    if not options.target_class:
        error(
            "Please provide the phenotype target to be predicted with -t \"TRAITNAME\""
        )
        errorCount += 1
    if errorCount > 0:
        error("For help on usage, try calling:\n\tpython %s -h" %
              os.path.basename(sys.argv[0]))
        exit(1)

    fileio = FileIO()
    if options.algorithm == "libsvm.libSVMClassifier":  # RVF: part of SVM fix (feature-index map)
        samples = fileio.load_samples(options.input_samples_filename,
                                      indexToAttribute=options.model_filename)
    else:  #original code
        samples = fileio.load_samples(options.input_samples_filename)
    if options.input_classes_filename:
        classes = fileio.load_classes(options.input_classes_filename)
    else:
        classes = fileio.init_null_classes(options.input_samples_filename,
                                           options.target_class)

    #RVF
    """rules = load_rules(options.model_filename) #original code"""
    if options.algorithm == "libsvm.libSVMClassifier":
        m = svm_model(options.model_filename)
        with open(options.model_filename + ".classlabelmap", 'rb') as handle:
            clm = pickle.loads(handle.read())
        with open(options.model_filename + ".classlabelmapindex",