Ejemplo n.º 1
0
def test_lipid_check_consistency():
    l = Lipid(LipidClass('Cer'), ResidueList([Residue(16, 2), Residue(18, 1)]))

    # check inconsistent state
    assert l.residueslist[0].modification == None

    l.check_consistency()

    # check consistent state
    assert l.residueslist[0].modification == CLASS_DEFAULT_MODIFICATION['Cer']
Ejemplo n.º 2
0
def some_lipids_plain_list():
    """
    A handful of well formatted lipids, using all annotation elements.

    Return as Python list, not as LipidList Object
    """
    # lists of names to draw from
    lipidclass_names = ['CE', 'Cer', 'TG']
    modifications = ['d', 'O-', None, None]

    lipidlist = []

    for i in range(10):
        lipidclass = LipidClass(random.choice(lipidclass_names))

        num_of_residues = random.choice([1, 2, 3])

        residuelist = ResidueList()

        for i in range(0, num_of_residues):
            residuelist.residues.append(
                Residue(random.randint(6, 50),
                        random.randint(0, 10),
                        modification=ResidueModification(
                            random.choice(modifications))))

        lipidlist.append(Lipid(lipidclass, residuelist))

    return lipidlist
Ejemplo n.º 3
0
def test_lipidlist_append():
    lipidlist = LipidList()

    for i in range(10):
        lipidlist.append(Lipid())

    assert len(lipidlist) == 10
Ejemplo n.º 4
0
def test_lipid_xreflist():
    t = 'DAG 16:0;0_22:4;0'
    lipid = Lipid.parse(t)

    lipid.add_xref(
        Xref('TargetDB', 'targetid')
    )
    assert len(lipid.xreflist) == 1
Ejemplo n.º 5
0
def test_swisslipids_xref():
    lipid = Lipid.parse('CE(20:2)')

    lipid = SwissLipids.get_xrefs(lipid)

    for xref in lipid.xreflist:
        assert xref.target_db == SwissLipids.NAME

    assert any(x.target_id == 'SLM:000500283' for x in lipid.xreflist)
Ejemplo n.º 6
0
    def get_xrefs(cls, lipid: Lipid, summed: bool = False) -> XrefList:
        xreflist = XrefList()

        try:
            search_term = lipid.abbreviation(summed)
        except Exception as e:
            log.debug(
                f"No abbreviation for lipid: {lipid.lipidclass}, {lipid.residueslist}."
            )
            log.error(f"Failed with {e}")
            search_term = lipid.abbreviation()

        search_result = cls.run_search(search_term)
        # search result can be empyt
        if search_result:
            for entity in cls.run_search(lipid.abbreviation(summed)):
                xreflist.append(Xref(cls.NAME, entity['entity_id']))

        return xreflist
Ejemplo n.º 7
0
    def test_parse(self):
        t = 'CE 16:2;0'
        lipid = Lipid.parse(t)
        assert lipid.lipidclass.name == 'CE'
        assert lipid.residueslist[0].carbon_atoms == 16
        assert lipid.residueslist[0].double_bonds == 2
        assert lipid.residueslist[0].oxidation == 0

        t = 'CE(16:2;0)'
        lipid = Lipid.parse(t)
        assert lipid.lipidclass.name == 'CE'
        assert lipid.residueslist[0].carbon_atoms == 16
        assert lipid.residueslist[0].double_bonds == 2
        assert lipid.residueslist[0].oxidation == 0

        t = 'DAG 16:0;0_22:4;0'
        lipid = Lipid.parse(t)
        assert lipid.lipidclass.name == 'DG'
        assert len(lipid.residueslist) == 2
        assert lipid.residueslist[0].carbon_atoms == 16
        assert lipid.residueslist[0].double_bonds == 0
        assert lipid.residueslist[0].oxidation == 0

        t = 'PC(28:5(13Z,16Z,19Z,22Z,25Z)/0:0)'
        lipid = Lipid.parse(t)
        assert lipid.lipidclass.name == 'PC'
        assert len(lipid.residueslist) == 2
        assert lipid.residueslist[0].carbon_atoms == 28
        assert lipid.residueslist[0].double_bonds == 5
        assert lipid.residueslist[0].oxidation == None
        assert len(lipid.residueslist[0].zstatelist) == 5
        assert str(lipid.residueslist[0].zstatelist[1]) == '16Z'

        t = 'chol'
        lipid = Lipid.parse(t)
        assert str(lipid.lipidclass) == 'chol'
Ejemplo n.º 8
0
    def lipid_from_id(cls, swisslipidsid: str) -> Lipid:
        """
        Call API to get details for a SwissLipids ID.

        :param swisslipidsid: The SwissLipids ID.
        :return: Return a Lipid.
        """
        request_url = cls.BASE_URL + f'/entity/{swisslipidsid.strip()}'
        log.debug(f'Call: {request_url}')

        result = requests.get(request_url).json()

        # get abbreviation
        for synonym in result['synonyms']:
            if synonym['type'] == 'abbreviation':
                abbreviation = synonym['name']

                lipid = Lipid.parse(abbreviation)
                lipid.add_xref(Xref(cls.NAME, swisslipidsid))
                return lipid
Ejemplo n.º 9
0
def test_lipid_abbreviation():
    l = Lipid(LipidClass('CE'), ResidueList([Residue(16, 2)]))

    assert l.abbreviation() == 'CE(16:2)'

    l = Lipid(LipidClass('CE'), ResidueList([Residue(16, 2), Residue(18, 1)]))

    assert l.abbreviation() == 'CE(16:2/18:1)'
    assert l.abbreviation(summed=True) == 'CE(34:3)'

    l = Lipid(LipidClass('CE'), ResidueList([Residue(16, 2, modification=ResidueModification('O-')), Residue(18, 1)]))

    assert l.abbreviation() == 'CE(O-16:2/18:1)'
    assert l.abbreviation(summed=True) == 'CE(O-34:3)'

    # no residues, assure that abbreviation/summed fails with AttributeError
    l = Lipid(LipidClass('CE'))
    assert l.abbreviation() == 'CE'

    assert l.abbreviation(summed=True) == 'CE'
Ejemplo n.º 10
0
 def test_errors(self):
     with pytest.raises(TypeError):
         # string not ending with bracket
         Lipid.parse("CE(14:9(9Z)/8:0")