Skip to content

Commit

Permalink
Merge pull request #33 from b-schubert/fix/travis_hotfixes
Browse files Browse the repository at this point in the history
Travis hotfixes

Unfixed Issue: d2s import and problems on Mac OS see Issue #34
  • Loading branch information
b-schubert committed Sep 7, 2015
2 parents 7d9bfc8 + 56353f6 commit 8a872a0
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 131 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ python:
- "2.7"
before_install:
- pip install -U nose-exclude setuptools
- sudo apt-get install glpk-utils
- sudo apt-get update -qq
- sudo apt-get install -qq python-dev libboost-python-dev libboost-serialization-dev
# command to package and install
Expand Down
6 changes: 6 additions & 0 deletions Fred2/Core/Peptide.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def get_all_transcripts(self):
def __eq__(self, other):
return str(self) == str(other)

def __lt__(self, other):
return str(self) <= str(other)

def __ge__(self, other):
return str(self) >= str(other)

def __cmp__(self, other):
return cmp(str(self), str(other))

Expand Down
6 changes: 6 additions & 0 deletions Fred2/Core/Protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def __repr__(self):
def __eq__(self, other):
return str(self) == str(other)

def __lt__(self, other):
return str(self) <= str(other)

def __ge__(self, other):
return str(self) >= str(other)

def __cmp__(self, other):
return cmp(str(self), str(other))

Expand Down
6 changes: 6 additions & 0 deletions Fred2/Core/Transcript.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def translate(self, table='Standard', stop_symbol='*', to_stop=False,
def __eq__(self, other):
return str(self) == str(other)

def __lt__(self, other):
return str(self) <= str(other)

def __ge__(self, other):
return str(self) >= str(other)

def __cmp__(self, other):
return cmp(str(self), str(other))

Expand Down
5 changes: 3 additions & 2 deletions Fred2/test/TestCleavagePrediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ def setUp(self):

def test_peptide_cleavage_prediction_mixed_input(self):
for m in CleavageSitePredictorFactory.available_methods():
if m != "NetChop":
if m.lower() != "netchop":
print m
mo = CleavageSitePredictorFactory(m)
mo.predict(self.seqs)

def test_peptide_cleavage_prediction_single_input(self):
for m in CleavageSitePredictorFactory.available_methods():
if m != "NetChop":
if m.lower() != "netchop":
mo = CleavageSitePredictorFactory(m)
mo.predict(self.seqs[0])
mo.predict(self.seqs[1])
Expand Down
2 changes: 1 addition & 1 deletion Fred2/test/TestEpitopeAssembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def test_simple_assembly(self):
:return:
"""
pred = CleavageSitePredictorFactory("PCM")
assembler = EpitopeAssembly(self.peptides, pred, solver="cplex", verbosity=1)
assembler = EpitopeAssembly(self.peptides, pred, solver="glpk", verbosity=1)
r = assembler.solve()
self.assertEqual(r, [Peptide("YLYDHLAPM"), Peptide("ALYDVVSTL"), Peptide("KLLPRLPGV")])
44 changes: 21 additions & 23 deletions Fred2/test/TestEpitopePrediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@


import unittest
import pandas as pd
import numpy as np

# Variants and Generator
import pandas
from Fred2.Core.Allele import Allele
from Fred2.Core.Peptide import Peptide
from Fred2.Core import Allele
from Fred2.Core import Peptide

#Preidctions
from Fred2.EpitopePrediction import EpitopePredictorFactory
from Fred2.EpitopePrediction.PSSM import APSSMEpitopePrediction
from Fred2.EpitopePrediction.SVM import ASVMEpitopePrediction
from Fred2.EpitopePrediction import EpitopePredictorFactory, AExternalEpitopePrediction


class TestCaseEpitopePrediction(unittest.TestCase):
Expand All @@ -28,31 +23,34 @@ def setUp(self):
self.mhcI = [Allele("HLA-B*15:01"), Allele("HLA-A*02:01")]
self.mhcII = [Allele("HLA-DRB1*07:01"), Allele("HLA-DRB1*15:01")]

def test_syf(self):
print EpitopePredictorFactory("Syfpeithi").predict(self.peptides_mhcI, self.mhcI)

def est_multiple_peptide_input_mhcI(self):

def test_multiple_peptide_input_mhcI(self):
for m in EpitopePredictorFactory.available_methods():

model = EpitopePredictorFactory(m)
if all(a.name in model.supportedAlleles for a in self.mhcI):
res = model.predict(self.peptides_mhcI, alleles=self.mhcI)
if not isinstance(model, AExternalEpitopePrediction):
if all(a.name in model.supportedAlleles for a in self.mhcI):
res = model.predict(self.peptides_mhcI, alleles=self.mhcI)

def est_single_peptide_input_mhcI(self):
def test_single_peptide_input_mhcI(self):
for m in EpitopePredictorFactory.available_methods():
model = EpitopePredictorFactory(m)
if not isinstance(model, AExternalEpitopePrediction):
if all(a.name in model.supportedAlleles for a in self.mhcI):
res = model.predict(self.peptides_mhcI[0], alleles=self.mhcI[0])

def test_multiple_peptide_input_mhcII(self):
for m in EpitopePredictorFactory.available_methods():
model = EpitopePredictorFactory(m)
if all(a.name in model.supportedAlleles for a in self.mhcI):
res = model.predict(self.peptides_mhcI[0], alleles=self.mhcI[0])
if not isinstance(model, AExternalEpitopePrediction):
if all(a.name in model.supportedAlleles for a in self.mhcII) and m != "MHCIIMulti":
res = model.predict(self.peptides_mhcII, alleles=self.mhcII)

def est_multiple_peptide_input_mhcII(self):

def test_single_peptide_input_mhcII(self):
for m in EpitopePredictorFactory.available_methods():
model = EpitopePredictorFactory(m)
if all(a.name in model.supportedAlleles for a in self.mhcII) and m != "MHCIIMulti":
res = model.predict(self.peptides_mhcII, alleles=self.mhcII)

if not isinstance(model, AExternalEpitopePrediction):
if all(a.name in model.supportedAlleles for a in self.mhcII):
res = model.predict(self.peptides_mhcII[0], alleles=self.mhcII[1])



Expand Down
165 changes: 77 additions & 88 deletions Fred2/test/TestGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,111 +38,101 @@ def setUp(self):
self.db_adapter = MartsAdapter()

def test__update_var_offset(self):
tmp1, tmp2 = var_1, var_2
tmp1 = var_1
tmp1.offsets["tsc_1"] = 3
tmp2.offsets["tsc_1"] = 0
Generator._update_var_offset([tmp2], "tsc_1", "tsc_666")
self.assertEqual(tmp1.offsets, tmp2.offsets)
Generator._update_var_offset([tmp1], "tsc_1", "tsc_666")
self.assertEqual(tmp1.offsets, {"tsc_1":3, "tsc_666":3})

def test__incorp_snp(self):
ts = list("TESTSEQUENCE")
self.assertEqual(Generator._incorp_snp(ts, var_2, "tsc_1", 6), (list("TESTSEQUENTE"), 6))
print self.assertEqual(Generator._incorp_snp(ts, var_2, "tsc_1", 6), (list("TESTSEQUENTE"), 6))

def test__incorp_insertion(self):
ts = list("TESTSEQUENCE")
self.assertEqual(Generator._incorp_insertion(ts, var_3, "tsc_1", 0), (list("TESTSEQTTUENCE"), 2))
#TODO _incorp_insertion undocumented (and unwanted) sideeffect is it is altering the input! this goes for all _incorp. either assign and return or no return and doc - https://docs.python.org/2.4/lib/typesseq-mutable.html
self.assertEqual(Generator._incorp_insertion(ts, var_5, "tsc_1", 0), (list("TESTSEQUENCE"), 3))
##TODO _incorp_insertion undocumented (and unwanted) sideeffect is it is altering the input! this goes for all _incorp. either assign and return or no return and doc - https://docs.python.org/2.4/lib/typesseq-mutable.html
#self.assertEqual(Generator._incorp_insertion(ts, var_5, "tsc_1", 0), (list("TESTSEQUENCE"), 3))

def test__incorp_deletion(self):
ts = list("TESTSEQUEASDFGNCES")
#TODO incorp_deletion just deletes something @ pos
##TODO incorp_deletion just deletes something @ pos <- that is what it supposed to do!
self.assertEqual(Generator._incorp_deletion(ts, var_4, "tsc_1", 0), (list("TESTSEQUENCES"), -5))
self.assertEqual(Generator._incorp_deletion(ts, var_6, "tsc_1", 0), (list("TESTSEQUENS"), -2))

def test__check_for_problematic_variants(self):
self.assertTrue(Generator._check_for_problematic_variants([var_1,var_2]))
self.assertFalse(Generator._check_for_problematic_variants([var_5,var_6]))

def test_generate_transcripts_from_variants(self):
# tested in :
# test_non_syn_hetero_snp_trans_number
# test_heterozygous_variants
# test_simple_incorporation
# test_offset_single
pass

# def test_non_syn_hetero_snp_trans_number(self):
# """
# tests if the number of generated transcripts for a heterozygous
# transcript is correct
#
# 1 hetero vars = 2 transcripts
# :return:
# """
# vars_ = \
# [self.non_syn_hetero_snp, self.non_frame_shift_del,self.syn_homo_snp]
#
# trans = \
# [t for t in generate_transcripts_from_variants(vars_, self.db_adapter)]
# # print trans
#
# self.assertTrue(len(trans) == 2**sum(not v.isHomozygous for v in vars_))
#
# def test_simple_incorporation(self):
# """
# test simple variant incorporation. only 1 variant in 1 transcript.
# input reference transcript: AAAAACCCCCGGGGG
#
# variant 3: insert TT after pos 7
#
# variant 1: SNP C -> T at pos 2
#
# variant 4: del CCCCC after pos 9
# """
# dummy_db = DummyAdapter()
#
# # INSERTIONS:
# dummy_vars = [ var_3]
# trans = generate_transcripts_from_variants(dummy_vars, dummy_db).next()
#
# self.assertEqual(str(trans), "AAAAACCTTCCCGGGGG")
#
# # SNPs:
# dummy_vars = [ var_1]
# trans = generate_transcripts_from_variants(dummy_vars, dummy_db).next()
# self.assertEqual(str(trans), "ATAAACCCCCGGGGG")
#
#
# # DELETIONS:
# dummy_vars = [ var_4]
# trans = generate_transcripts_from_variants(dummy_vars, dummy_db).next()
# self.assertEqual(str(trans), "AAAAACCCCG")
#
#
#
# def test_offset_single(self):
# """
# tests if offset is correctly handled when several variants for one
# transcript occur. still only one transcript with one transcript variant.
# reference transcript: AAAAACCCCCGGGGG
#
# Each variant so that it is clearly down stream of
# it's predecessor
#
# """
# dummy_db = DummyAdapter()
#
# # 1) INS, SNP, DEL
# dummy_vars = [ var_3, var_7, var_6]
# trans = generate_transcripts_from_variants(dummy_vars, dummy_db).next()
#
# self.assertEqual(str(trans), "AAAAACCTTCTCGGG")
#
# # 2.) INS, DEL, INS
# dummy_vars = [ var_9, var_4, var_8]
# trans = generate_transcripts_from_variants(dummy_vars, dummy_db).next()
# self.assertEqual(str(trans), "AATTAAACCCCGTTT")
def test_non_syn_hetero_snp_trans_number(self):
"""
tests if the number of generated transcripts for a heterozygous
transcript is correct
1 hetero vars = 2 transcripts
:return:
"""
vars_ = \
[self.non_syn_hetero_snp, self.non_frame_shift_del,self.syn_homo_snp]

trans = \
[t for t in Generator.generate_transcripts_from_variants(vars_, self.db_adapter)]

self.assertTrue(len(trans) == 2**sum(not v.isHomozygous for v in vars_))

def test_simple_incorporation(self):
"""
test simple variant incorporation. only 1 variant in 1 transcript.
input reference transcript: AAAAACCCCCGGGGG
variant 3: insert TT after pos 7
variant 1: SNP C -> T at pos 2
variant 4: del CCCCC after pos 9
"""
dummy_db = DummyAdapter()

# INSERTIONS:
dummy_vars = [ var_3]
trans = Generator.generate_transcripts_from_variants(dummy_vars, dummy_db).next()

self.assertEqual(str(trans), "AAAAACCTTCCCGGGGG")

# SNPs:
dummy_vars = [ var_1]
trans = Generator.generate_transcripts_from_variants(dummy_vars, dummy_db).next()
self.assertEqual(str(trans), "ATAAACCCCCGGGGG")


# DELETIONS:
dummy_vars = [ var_4]
trans = Generator.generate_transcripts_from_variants(dummy_vars, dummy_db).next()
self.assertEqual(str(trans), "AAAAACCCCG")



def test_offset_single(self):
"""
tests if offset is correctly handled when several variants for one
transcript occur. still only one transcript with one transcript variant.
reference transcript: AAAAACCCCCGGGGG
Each variant so that it is clearly down stream of
it's predecessor
"""
dummy_db = DummyAdapter()

# 1) INS, SNP, DEL
dummy_vars = [ var_3, var_7, var_6]
trans = Generator.generate_transcripts_from_variants(dummy_vars, dummy_db).next()

self.assertEqual(str(trans), "AAAAACCTTCTCGGG")

# 2.) INS, DEL, INS
dummy_vars = [ var_9, var_4, var_8]
trans = Generator.generate_transcripts_from_variants(dummy_vars, dummy_db).next()
self.assertEqual(str(trans), "AATTAAACCCCGTTT")

def test_heterozygous_variants(self):
"""
Expand Down Expand Up @@ -199,4 +189,3 @@ def test_heterozygous_variants(self):
# for v in vars:
# for trans_id in v.coding.iterkeys():
# transToVar.setdefault(trans_id, []).append(v)

3 changes: 2 additions & 1 deletion Fred2/test/TestOptiTope.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from Fred2.EpitopePrediction import EpitopePredictorFactory
from Fred2.EpitopeSelection.OptiTope import OptiTope


class OptiTopeTestCase(unittest.TestCase):
"""
Unittest for OptiTope
Expand Down Expand Up @@ -41,7 +42,7 @@ def setUp(self):
VTYSLTGLW
YFVIFFVAA""".split()]
self.result= EpitopePredictorFactory("BIMAS").predict(self.peptides, self.alleles)
self.thresh = {"A*01:01":100,"B*07:02":100,"C*03:01":100}
self.thresh = {"A*01:01":10,"B*07:02":10,"C*03:01":10}

def test_selection_without_constraints(self):
"""
Expand Down
14 changes: 13 additions & 1 deletion Fred2/test/TestPredictionVersioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
from Fred2.Core.Peptide import Peptide

#Preidctions
from Fred2.EpitopePrediction import EpitopePredictorFactory
from Fred2.EpitopePrediction import EpitopePredictorFactory,BIMAS, AEpitopePrediction
from Fred2.TAPPrediction import TAPPredictorFactory
from Fred2.CleavagePrediction import CleavageFragmentPredictorFactory, CleavageSitePredictorFactory


class BIMAS2(BIMAS):
__version = "2.0"

@property
def version(self):
return self.__version


class TestCaseEpitopePrediction(unittest.TestCase):

def setUp(self):
Expand All @@ -32,6 +40,10 @@ def test_epitope_prediction_no_version(self):
def test_epitope_prediction_available_methods(self):
print EpitopePredictorFactory.available_methods()

def test_multiple_predictors_names_different_version(self):
self.assertTrue(EpitopePredictorFactory("BIMAS", version="1.0").version == "1.0")
self.assertTrue(EpitopePredictorFactory("BIMAS", version="2.0").version == "2.0")

@unittest.expectedFailure
def test_epitope_prediction_unsupported_version(self):
print EpitopePredictorFactory("BIMAS", version="4.0").predict(self.peptides_mhcI, self.mhcI)
Expand Down
Loading

0 comments on commit 8a872a0

Please sign in to comment.