Example #1
0
 def test_create_feature_vectors(self):
     create_positive_and_negative_dataset(1, 10)
     pssms_file = "/tmp/pssms.txt"
     conservation = True
     pssmData = feature.parse_pssms_file(pssms_file)
     pssm = pssmData.get_PSSMRecord(pssmData.get_uniprotURIs()[0])
     feature_vectors = feature.create_feature_vectors(pssm, 1, conservation=True)
     self.assertEqual(66, len(feature_vectors[0]))
     self.assertEqual(0, feature_vectors[0][-3])
     self.assertEqual(0, feature_vectors[9][-1])
Example #2
0
def write_to_output_file(prediction_output_file, user_defined_header, results):
    with open(prediction_output_file, 'a') as fp:
        idx = 0
        for predicted_label, decision_value in zip(results['label'],
                                                   results['decision_value']):
            fp.write("{} {} {} {}\n".format(user_defined_header, idx,
                                            predicted_label, decision_value))
            idx += 1


if __name__ == "__main__":
    arguments = docopt(__doc__)
    best_chromosome_file = arguments['<best_chromosome_file>']
    pssms_file = arguments['<pssms_file>']
    pickled_model_file = arguments['<pickled_model_file>']
    prediction_output_file = arguments['<prediction_output_file>']
    method_genes_decision_value = common.get_method_genes_decision_value(
        best_chromosome_file)
    method, window_size, my_decision_value = method_genes_decision_value[
        0], int(method_genes_decision_value[3]), float(
            method_genes_decision_value[4])
    pssmData = feature.parse_pssms_file(pssms_file)
    for user_defined_header in pssmData.get_uniprotURIs():
        pssm = pssmData.get_PSSMRecord(user_defined_header)
        test_dataset = feature.create_feature_vectors(pssm, window_size)
        results = predict(method, pickled_model_file, my_decision_value,
                          test_dataset)
        write_to_output_file(prediction_output_file, user_defined_header,
                             results)
Example #3
0
        return predict_with_NN_classifier(clf_or_net, my_decision_value, test_dataset)
    elif method == "randomForest":
        return predict_with_RF_classifier(clf_or_net, my_decision_value, test_dataset)
    elif method == "SVM":
        return predict_with_SVM_classifier(clf_or_net, my_decision_value, test_dataset)
    else:
        raise ValueError("method must be neuralNetwork or randomForest or SVM [{}]".format(method))


def write_to_output_file(prediction_output_file, user_defined_header, results):
    with open(prediction_output_file, 'a') as fp:
        idx = 0
        for predicted_label, decision_value in zip(results['label'], results['decision_value']):
            fp.write("{} {} {} {}\n".format(user_defined_header, idx, predicted_label, decision_value))
            idx += 1

if __name__ == "__main__":
    arguments = docopt(__doc__)
    best_chromosome_file = arguments['<best_chromosome_file>']
    pssms_file = arguments['<pssms_file>']
    pickled_model_file = arguments['<pickled_model_file>']
    prediction_output_file = arguments['<prediction_output_file>']
    method_genes_decision_value = common.get_method_genes_decision_value(best_chromosome_file)
    method, window_size, my_decision_value = method_genes_decision_value[0], int(method_genes_decision_value[3]), float(method_genes_decision_value[4])
    pssmData = feature.parse_pssms_file(pssms_file)
    for user_defined_header in pssmData.get_uniprotURIs():
        pssm = pssmData.get_PSSMRecord(user_defined_header)
        test_dataset = feature.create_feature_vectors(pssm, window_size)
        results = predict(method, pickled_model_file, my_decision_value, test_dataset)
        write_to_output_file(prediction_output_file, user_defined_header, results)