示例#1
0
    def test_factory_for_default(self):
        # make sure FACTORY works for the global default
        A = namedlist('A', 'x y', default=FACTORY(list))
        a = A()
        self.assertEqual(a.x, [])
        self.assertEqual(a.y, [])

        a.x.append(4)
        self.assertEqual(a.x, [4])
        a.y.append(4)
        self.assertEqual(a.y, [4])

        b = A()
        self.assertEqual(b.x, [])
        self.assertEqual(b.y, [])

        # mix and match FACTORY and a non-callable mutable default
        A = namedlist('A', [('x', []), 'y'], default=FACTORY(list))
        a = A()
        self.assertEqual(a.x, [])
        self.assertEqual(a.y, [])

        a.x.append(4)
        self.assertEqual(a.x, [4])
        a.y.append(4)
        self.assertEqual(a.y, [4])

        b = A()
        self.assertEqual(b.x, [4])
        self.assertEqual(b.y, [])
示例#2
0
    def test_simple(self):
        Point = namedlist('Point', 'x y')
        p = Point(10, 20)
        self.assertEqual((p.x, p.y), (10, 20))
        self.assertEqual(p._asdict(), {'x':10, 'y':20})

        Point = namedlist('Point', 'x,y')
        p = Point(10, 20)
        self.assertEqual((p.x, p.y), (10, 20))
        self.assertEqual(p._asdict(), {'x':10, 'y':20})

        Point = namedlist('Point', 'x, y')
        p = Point(10, 20)
        self.assertEqual((p.x, p.y), (10, 20))
        self.assertEqual(p._asdict(), {'x':10, 'y':20})

        Point = namedlist('Point', ['x', 'y'])
        p = Point(10, 20)
        self.assertEqual((p.x, p.y), (10, 20))
        self.assertEqual(p._asdict(), {'x':10, 'y':20})

        self.assertEqual(Point(10, 11), Point(10, 11))
        self.assertNotEqual(Point(10, 11), Point(10, 12))

        self.assertEqual(vars(p), p._asdict())                              # verify that vars() works
示例#3
0
    def test_identity_of_defaults(self):
        default = object()
        Point = namedlist('Point', [('x', default)])
        # in 2.7 this should become assertIs
        self.assertTrue(Point().x is default)

        Point = namedlist('Point', 'x', default)
        # in 2.7 this should become assertIs
        self.assertTrue(Point().x is default)
示例#4
0
    def test_slots(self):
        Point = namedlist('Point', '')
        p = Point()
        # p.x = 3 raises AttributeError because of slots
        self.assertRaises(AttributeError, setattr, p, 'x', 3)

        Point = namedlist('Point', '', use_slots=True)
        p = Point()
        # p.x = 3 raises AttributeError because of slots
        self.assertRaises(AttributeError, setattr, p, 'x', 3)
示例#5
0
    def test_list(self):
        Point = namedlist('Point', ['x', 'y'])
        p = Point(10, 20)
        self.assertEqual((p.x, p.y), (10, 20))
        self.assertEqual(p._asdict(), {'x':10, 'y':20})

        Point = namedlist('Point', ('x', 'y'))
        p = Point(10, 20)
        self.assertEqual((p.x, p.y), (10, 20))
        self.assertEqual(p._asdict(), {'x':10, 'y':20})
示例#6
0
    def test_default_and_specified_default(self):
        Point = namedlist('Point', ['x', ('y', 10), ('z', 20)], 100)
        self.assertEqual(Point(), Point(100, 10, 20))
        self.assertEqual(Point(0), Point(0, 10, 20))
        self.assertEqual(Point(0, 1), Point(0, 1, 20))
        self.assertEqual(Point(0, 1, 2), Point(0, 1, 2))

        # default doesn't just have to apply to the last field
        Point = namedlist('Point', [('x', 0), 'y', ('z', 20)], 100)
        self.assertEqual(Point(), Point(0, 100, 20))
示例#7
0
    def test_docstring(self):
        Point = namedlist('Point', '')
        self.assertEqual(Point.__doc__, 'Point()')

        Point = namedlist('Point', 'dx')
        self.assertEqual(Point.__doc__, 'Point(dx)')

        Point = namedlist('Point', 'x')
        self.assertEqual(Point.__doc__, 'Point(x)')

        Point = namedlist('Point', 'dx dy, dz')
        self.assertEqual(Point.__doc__, 'Point(dx, dy, dz)')

        Point = namedlist('Point', 'dx dy dz', default=10)
        self.assertEqual(Point.__doc__, 'Point(dx=10, dy=10, dz=10)')

        Point = namedlist('Point', 'dx, dy, dz', default=FACTORY(10))
        self.assertEqual(Point.__doc__, 'Point(dx=FACTORY(10), dy=FACTORY(10), dz=FACTORY(10))')

        Point = namedlist('Point', ['dx', 'dy', ('dz', 11.0)], default=10)
        self.assertEqual(Point.__doc__, 'Point(dx=10, dy=10, dz=11.0)')

        Point = namedlist('Point', ['dx', 'dy', ('dz', 11.0)], default=FACTORY(list))
        if _PY2:
            list_repr = "<type 'list'>"
        else:
            list_repr = "<class 'list'>"
        self.assertEqual(Point.__doc__, "Point(dx=FACTORY({0}), dy=FACTORY({0}), dz=11.0)".format(list_repr))

        Point = namedlist('Point', ['dx', 'dy', ('dz', FACTORY(11.0))], default=[])
        self.assertEqual(Point.__doc__, 'Point(dx=[], dy=[], dz=FACTORY(11.0))')
示例#8
0
    def test_complex_defaults(self):
        Point = namedlist('Point', ['x', ('y', 10), ('z', 20)],
                          [1, 2, 3])
        p = Point()
        self.assertEqual((p.x, p.y, p.z), ([1, 2, 3], 10, 20))

        Point = namedlist('Point', [('x', [4, 5, 6]),
                                    ('y', 10),
                                    ('z', 20)])
        p = Point()
        self.assertEqual((p.x, p.y, p.z), ([4, 5, 6], 10, 20))
示例#9
0
    def test_fields(self):
        Point = namedlist('Point', 'x y z')
        self.assertEqual(Point._fields, ('x', 'y', 'z'))
        self.assertIsInstance(Point._fields, tuple)

        Point = namedlist('Point', 'x y z', 100)
        self.assertEqual(Point._fields, ('x', 'y', 'z'))

        Point = namedlist('Point', [('x', 0), ('y', 0), ('z', 0)])
        self.assertEqual(Point._fields, ('x', 'y', 'z'))

        Point = namedlist('Point', '')
        self.assertEqual(Point._fields, ())
        self.assertIsInstance(Point._fields, tuple)
示例#10
0
    def test_type_has_same_name_as_field(self):
        Point = namedlist('Point',
                           ['Point', ('y', 10), ('z', 20)],
                           [1, 2, 3])
        p = Point()
        self.assertEqual(len(p), 3)
        self.assertEqual(p.Point, [1, 2, 3])

        Point = namedlist('Point', 'Point')
        p = Point(4)
        self.assertEqual(p.Point, 4)

        Point = namedlist('Point', 'x Point')
        p = Point(3, 4)
        self.assertEqual(p.Point, 4)
示例#11
0
 def test_replace_none(self):
     Point = namedlist('Point', 'x y z')
     a = Point(1, 2, 3)
     b = a._replace()
     self.assertIsNot(a, b)
     self.assertEqual((a.x, a.y, a.z), (1, 2, 3))
     self.assertEqual((b.x, b.y, b.z), (1, 2, 3))
示例#12
0
    def test_update_other_self_kwarg(self):
        # make sure 'self' and 'other' work as kwargs
        Point = namedlist('Point', 'self other')

        a = Point(1, 0)
        a._update(self=10, other=20)
        self.assertEqual((a.self, a.other), (10, 20))
示例#13
0
 def test_default_list(self):
     Point = namedlist('Point', 'x y z'.split(), 100)
     self.assertEqual(Point(), Point(100, 100, 100))
     self.assertEqual(Point(10), Point(10, 100, 100))
     self.assertEqual(Point(10, 20), Point(10, 20, 100))
     self.assertEqual(Point(10, 20, 30), Point(10, 20, 30))
     self.assertEqual(Point()._asdict(), {'x':100, 'y':100, 'z':100})
示例#14
0
 def test_assert(self):
     test_list = namedlist('test_list', ['x', 'y'])
     test_list_instance = test_list(1, 2)
     with pytest.raises(KeyError) as e:
         change_namedlist(test_list_instance, {'z': 3})
     assert 'Field with name z is not in list test_list(x=1, y=2)' in str(
         e.value)
def main(anno_file):
    Data = namedlist("Data", "Gene_stable_id refseq_ncrna hgnc_symbol description")
    results = OrderedDict()
    first = ""
    with open(anno_file, 'rt')as fin:
        first = fin.readline()
        for line in fin:
            line = line.strip("\n")
            csv_list = line.split("\t")
            ensembl_id = csv_list[0]
            ncrna = csv_list[1]
            symbol = csv_list[2]
            desc = csv_list[3]

            if ensembl_id in results:
                tmp = results[ensembl_id]
                if ncrna != "":
                    tmp.refseq_ncrna += ncrna + ";"
            else:
                results[ensembl_id] = Data(Gene_stable_id=ensembl_id, refseq_ncrna=ncrna, hgnc_symbol=symbol,
                                           description=desc)

    with open(anno_file + ".pared.tsv", 'wt')as fout:
        fout.write("HGNC symbol\tGene stable ID\tRefSeq ncRNA ID\tdescription\n")
        for i in results:
            tmp = results[i]
            tab = "\t"
            tmp.refseq_ncrna = tmp.refseq_ncrna.rstrip(";")
            wf = tmp.hgnc_symbol + tab + tmp.Gene_stable_id +tab + tmp.refseq_ncrna + tab + tmp.description + "\n"
            fout.write(wf)
示例#16
0
 def test_mapping(self):
     # use a regular dict so testing with 2.6 is still possible
     # do not make any assumptions about field order
     Point = namedlist('Point', {'x': 0, 'y': 100})
     p = Point()
     self.assertEqual(p.x, 0)
     self.assertEqual(p.y, 100)
示例#17
0
def retrieveSearchData(rowID, DB, search_space):
    queryRecordList = [
        "HostName", "FilePath", "FileName", "LastModified", "LastUpdate",
        "Size", "ExecFlag", "RowID", "EntryType", "FirstRun", "SHA1",
        "Search_Space"
    ]
    queryRecordFields = namedlist("queryRecordList",
                                  queryRecordList,
                                  default=None)

    # Grab all fields in the queryRecordList
    selectQuery = ','.join(queryRecordList)
    selectQuery = selectQuery.replace('Search_Space', search_space)
    # Execute the query
    entry = DB.Query("SELECT %s FROM Entries_FilePaths INNER JOIN Hosts \
        ON Entries_FilePaths.HostID = Hosts.HostID WHERE RowID = '%s'" %
                     (selectQuery, rowID))[0]

    # todo: There has to be a more pythonic way to do this
    record = queryRecordFields()
    tmpDict = dict(zip(queryRecordList, entry))
    i = 0
    for field in queryRecordList:
        record[i] = tmpDict[field]
        i += 1
    return record
示例#18
0
class Term(namedlist('Term', 'position label symbol content')):
    '''代数项对象'''
    __slots__ = ()

    def __init__(self,position=None,label=None,symbol=None,content=None):
        self.position = position
        self.label = label
        self.symbol = symbol
        self.content = content

    @property
    def __str__(self):
        return 'Term: position=%s  '\
               'label=$%s  symbol=%s  '\
               'content=%s  ' % (self.position, self.label,
                                 self.symbol,self.content)

    def change_label(self,newlabel):
        self.label = newlabel

    def change_symbol(self):
        self.symbol *= -1

    def change_position(self,newpositon):
        self.position = newpositon

    def change_content(self,newcontent):
        self.content = newcontent
示例#19
0
 def __init__(self, title='DummyTitle', headless=True):
     super().__init__(headless=headless)
     self.__Novel_Site_Data = namedlist('NovelSiteData',
                                        [('SiteLink', ''), ('fix', ''),
                                         ('suffix', ''),
                                         ('AdditionalLinks', []),
                                         ('AdditionalActionNeeded', False)])
     self.__Domains_to_search = {
         'Novel Updates':
         self.__Novel_Site_Data(
             SiteLink='https://www.novelupdates.com/series/',
             fix='-'),  #nie jest na czasie z duza iloscia novelek
         'Webnovel':
         self.__Novel_Site_Data(
             SiteLink='https://www.webnovel.com',
             AdditionalActionNeeded=True
         ),  #trzeba wyszukiwac w search-bar tytul,wybierac pozycje i dopiero sprawdzac
         'ReadLightNovel':
         self.__Novel_Site_Data(SiteLink='https://www.readlightnovel.org/',
                                fix='-'),
         'NovelFull':
         self.__Novel_Site_Data(
             SiteLink='https://novelfull.com/', fix='-', suffix='.html'
         ),  #koncowka z .html chyba trzeba przeklikac na ostatnia strone,zeby znalezc numery tytulu
         'ReadNovelFull':
         self.__Novel_Site_Data(
             SiteLink='https://readnovelfull.com/',
             fix='-',
             suffix='.html#tab-chapters-title'
         ),  # '#tab-chapters-title' trzeba dodac do konca nazwy .html                     
     }
     self.__Formated_domain_titles = {}
     self.title = title
     self.results = []
示例#20
0
def retrieve_genome_and_hash(
    filestem: str,
    suffix: str,
    ftpstem: str,
    outdir: Path,
    timeout: int,
    disable_tqdm: bool = False,
) -> namedlist:
    """Download genome contigs and MD5 hash data from NCBI.

    :param filestem:
    :param suffix:
    :param ftpstem:
    :param outdir:
    :param timeout:
    :param disable_tqdm:  Boolean, show tqdm progress bar?
    """
    DLStatus = namedlist("DLStatus",
                         "url hashurl outfname outfhash skipped error")
    skipped = False  # Flag - set True if we skip download for existing file
    error = None  # Text of last-raised error

    # Construct remote URLs and output filenames
    url, hashurl = compile_url(filestem, suffix, ftpstem)
    outfname, outfhash = construct_output_paths(filestem, suffix, outdir)

    # Download the genome sequence and corresponding hash file
    try:
        download_url(url, outfname, timeout, disable_tqdm)
        download_url(hashurl, outfhash, timeout, disable_tqdm)
    except IOError:
        error = last_exception()

    return DLStatus(url, hashurl, outfname, outfhash, skipped, error)
示例#21
0
def mutabletuple(typename, field_names, default=MtNoDefault):
    """Factory function that creates a class mutabletuple."""
    # Create a namedlist
    mtuple = namedlist.namedlist(typename, field_names, default)

    # Set unique attribute to identify mutabletuple classes
    mtuple.MutableTupleUniqueIdentifier = None

    # Extend namedlist functionality
    (fields, defaults) = namedlist._fields_and_defaults(typename,
                                                        field_names,
                                                        default,
                                                        rename=False)
    mtuple.__init__ = namedlist._make_fn('__init__', _mt_init, fields,
                                         defaults)
    mtuple.__repr__ = _mt_repr
    mtuple._asdict = _mt_asdict
    mtuple.iteritems = _mt_iteritems
    mtuple.merge = _mt_merge
    mtuple.orderedDict = _mt_orderedDict
    mtuple.__getstate__ = _mt_getstate
    mtuple.__setstate__ = _mt_setstate

    # Assign the class as a global under the same name
    # Required for pickle so the class seems declared at global level.
    globals()[typename] = mtuple

    return mtuple
示例#22
0
 def __init__(self, label, *n_assets):
     self.label = label
     n_asset = namedlist('N_Asset', ['n', 'asset'])
     self.c = \
         [n_asset(n=x[0], asset=x[1]) if isinstance(x, (list, tuple))
          else n_asset(n=1, asset=x)
          for x in n_assets]
示例#23
0
 def test_slice(self):
     Point = namedlist('Point', 'x y z color')
     values = [3, 5, -12, 'red']
     p = Point(*values)
     self.assertEqual(values[0:-1], p[0:-1])
     self.assertEqual(values[:3], p[:3])
     self.assertEqual(values[4:1:-1], p[4:1:-1])
示例#24
0
class SimpleNode(namedlist("_", ["word", "postag", "head", "deprel"])):
    @classmethod
    def from_line(cls, line):
        fields = line.split()
        return cls(*fields)

    def to_line(self, sep='\t'):
        return sep.join(six.text_type(i) for i in self)
示例#25
0
 def test_setitem(self):
     Point = namedlist('Point', 'a b')
     p = Point(1, 2)
     p[0] = 10
     self.assertEqual(list(p), [10, 2])
     p[1] = 20
     self.assertEqual(list(p), [10, 20])
     self.assertRaises(IndexError, p.__setitem__, 2, 3)
示例#26
0
 def test_replace_none(self):
     # make sure 'self' and 'other' work as kwargs
     Point = namedlist('Point', 'self other')
     a = Point(1, 2)
     b = a._replace(self=3, other=4)
     self.assertIsNot(a, b)
     self.assertEqual((a.self, a.other), (1, 2))
     self.assertEqual((b.self, b.other), (3, 4))
示例#27
0
 def test_NO_DEFAULT(self):
     # NO_DEFAULT is only really useful with we're using a mapping
     #  plus a default value. it's the only way to specify that
     #  some of the fields use the default.
     Point = namedlist('Point', {'x':0, 'y':NO_DEFAULT}, default=5)
     p = Point()
     self.assertEqual(p.x, 0)
     self.assertEqual(p.y, 5)
示例#28
0
    def test_asdict_vars_ordered(self):
        Point = namedlist('Point', ['x', 'y'])
        p = Point(10, 20)

        # can't use unittest.skipIf in 2.6
        if sys.version_info[0] <= 2 and sys.version_info[1] <= 6:
            self.assertIsInstance(p.__dict__, dict)
        else:
            self.assertIsInstance(p.__dict__, collections.OrderedDict)
示例#29
0
    def test_correct_change(self):
        test_list = namedlist('test_list', ['x', 'y'])
        test_list_instance = test_list(1, 2)
        assert test_list_instance.x == 1
        assert test_list_instance.y == 2

        test_list_instance2 = change_namedlist(test_list_instance, {'x': 3})
        assert test_list_instance2.x == 3
        assert test_list_instance2.y == 2
示例#30
0
    def test_update_other_named_list(self):
        Point = namedlist('Point', ['x', ('y', 10), ('z', 20)], 100)

        a = Point(10)
        b = Point(100, 200, 300)
        a._update(b)

        self.assertEqual((a.x, a.y, a.z), (100, 200, 300))
        self.assertIsNot(a, b)
示例#31
0
    def __init__(self, weights):
        self.bridge = CvBridge()
        self.Data = namedlist('Data', ['pose', 'rgb', 'depth'])
        self.data = self.Data(pose=None, rgb=None, depth=None)
        self.is_start = True

        checkpoint = torch.load(weights, map_location="cpu")
        self.model = Model(**checkpoint['kwargs'])
        self.model.load_state_dict(checkpoint["model_state_dict"])
        self.model.eval()
def makeCover(prelations, successors):
    """
    prelations = {'activity': ['predecesor1', 'predecesor2'...}
    successors = {'activity': ['successor1', 'successor2'...}

    return a dictionary with the improper covers
    work_table_imp = {index: u(improper covers successors), w(improper covers predecessors)}
    """
    # SConstruct improper cover work table
    MinRev = namedlist.namedlist("MinRev", ["u", "w"])
    # [0 Identical successors,   1 Identical Predecessors)

    # Group by Identical Successors
    visited_suc = {}
    work_table_imp = {}
    i = 0

    for act, columns in successors.items():
        u = set()
        pred = frozenset(columns)
        if pred not in visited_suc:
            visited_suc[pred] = act
            u.add(act)
            for act2, columns2 in successors.items():
                if columns2 == columns:
                    u.add(act2)

        if u:
            work_table_imp[i] = MinRev(list(u), [])
            i += 1

    # Group by Identical Predecessors
    visited_pred = {}
    i = 0

    for act, columns in prelations.items():
        u.clear()
        pred = frozenset(columns)
        if pred not in visited_pred:
            visited_pred[pred] = act
            u.add(act)
            for act2 in prelations:
                if pred == columns:
                    u.add(act2)

        if u:
            if work_table_imp.has_key(i):
                work_table_imp[i].w = list(u)
            else:
                work_table_imp[i] = MinRev([], list(u))
            i += 1

    return work_table_imp
示例#33
0
    def make_defaults(self):
        """Make a namedtuple for extracting our wanted keys"""
        if not self.fields:
            return empty_defaults
        else:
            fields = []
            end_fields = []
            for field in self.fields:
                if isinstance(field, (tuple, list)):
                    name, dflt = field
                    if callable(dflt):
                        dflt = dflt()
                    end_fields.append((name, dflt))
                else:
                    fields.append(field)

            joined = fields + end_fields
            identifier = str(joined)
            if identifier not in cached_namedlists:
                cached_namedlists[identifier] = namedlist("Defaults", joined)
            return cached_namedlists[identifier]
示例#34
0
from namedlist import namedlist

empty_defaults = namedlist("Defaults", [])
cached_namedlists = {}

class dictobj(dict):
    fields = None

    def make_defaults(self):
        """Make a namedtuple for extracting our wanted keys"""
        if not self.fields:
            return empty_defaults
        else:
            fields = []
            end_fields = []
            for field in self.fields:
                if isinstance(field, (tuple, list)):
                    name, dflt = field
                    if callable(dflt):
                        dflt = dflt()
                    end_fields.append((name, dflt))
                else:
                    fields.append(field)

            joined = fields + end_fields
            identifier = str(joined)
            if identifier not in cached_namedlists:
                cached_namedlists[identifier] = namedlist("Defaults", joined)
            return cached_namedlists[identifier]

    def __init__(self, *args, **kwargs):
示例#35
0
def sysloOptimal(prelations):
    """
    Build a PERT graph using Syslo algorithm

    return p_graph pert.PertMultigraph()
    """
    # Adaptation to avoid multiple end nodes
    successors = graph.reversed_prelation_table(prelations)
    end_act = graph.ending_activities(successors)
    
    #Kahn1962.check_cycles(successors)
    prela = successors.copy()

    Columns = namedlist.namedlist('Columns', ['pre', 'blocked', 'dummy', 'suc', 'start_node', 'end_node'])
                            # [0 Predecesors,   1 Blocked, 2 Dummy, 3 Successors, 4 Start node, 5 End node]
                           #   Blocked = (False or Activity with same precedents)  

    
    #Step 0.
    grafo = {}
    alt = graph.successors2precedents(successors)
    grafo = graph.successors2precedents(syslo_table.syslo(prela, grafo, alt))

    #Step 1. Save the new prelation table in a work table
    work_table = {}
    for act, pre in grafo.items():
        if not act in prelations:
            work_table[act] = Columns(pre, False, True, None, None, None)
        else:
            work_table[act] = Columns(pre, False, False, None, None, None)


    #Step 2. Identify Dummy Activities And Identical Precedence Constraint of Diferent Activities
    visited_pred = {}
    for act, columns in work_table.items():
        pred = frozenset(columns.pre)
        if pred not in visited_pred:
            visited_pred[pred] = act
        else:
            columns.blocked = visited_pred[pred]


    #Step 3. Creating nodes
    # (a) find start nodes
    node = 0 # instead of 0, can start at 100 to avoid confusion with activities named with numbers when debugging
    for act, columns in work_table.items():
        if not columns.blocked:
            columns.start_node = node
            node += 1
        if columns.blocked:
            columns.start_node = work_table[columns.blocked].start_node
            
        # Associate activities with their end nodes
        for suc, suc_columns in work_table.items():
            if not suc_columns.blocked:
                if act in suc_columns.pre:
                    columns.suc = suc
                    break


    
    # (b) find end nodes
    graph_end_node = node # Reserve one node for graph end 
    node += 1
    for act, columns in work_table.items():
        suc = columns.suc
        if suc:
            columns.end_node = work_table[suc].start_node
        else:
            # Create needed end nodes, avoiding multiple graph end nodes (adaptation)
            if act in end_act:
                columns.end_node = graph_end_node
            else:
                columns.end_node = node 
                node += 1
    
    # Step 4. Remove redundancy of dummy activities
    vis = []
    for act, columns in work_table.items():
        if columns.dummy == False:
            for q in work_table[act].pre:
                    for w in work_table[act].pre:
                        if q in work_table and w in work_table:
                            if q != w and work_table[q].pre == work_table[w].pre and work_table[q].dummy==True and work_table[w].dummy==True:
                                if w not in vis:
                                    del work_table[w]
                                vis.append(q)
                     
    
    #Step 5. Generate the graph
    pm_graph = pert.PertMultigraph()
    for act, columns in work_table.items():
        _, _, dummy, _, start, end = columns
        pm_graph.add_arc((start, end), (act, dummy))

    p_graph = pm_graph.to_directed_graph()
    return p_graph


    return p_graph
示例#36
0
    Grammatical agreement conversion for words in error reporting.

    :copyright: (c) 2015 The Regents of the University of California.
    :license: GNU GPL, see licenses/GNU GPLv3.txt for more details.
'''

# load modules/submodules
from namedlist import namedlist

import six


# OBJECTS
# -------

GrammaticalNumber = namedlist("GrammaticalNumber", "singular plural")


# DATA
# ----

GRAMMATICAL_NUMBERS = {
    '-s': GrammaticalNumber("", "s"),
    '-at': GrammaticalNumber("at", "ose"),
    '-y': GrammaticalNumber("y", "ies"),
}

SINGULAR = {k: v.singular for k, v in GRAMMATICAL_NUMBERS.items()}
PLURAL = {k: v.plural for k, v in GRAMMATICAL_NUMBERS.items()}

def sysloPolynomial(prelations):

    # Adaptation to avoid multiple end nodes
    successors = graph.reversed_prelation_table(prelations)
    end_act = graph.ending_activities(successors)

    # Step 0. Construct work table with Immediate Predecessors
    Columns = namedlist.namedlist("Columns", ["pre", "blocked", "dummy", "suc", "start_node", "end_node"])
    # [0 Predecesors,   1 Blocked, 2 Dummy, 3 Successors, 4 Start node, 5 End node]
    #   Blocked = (False or Activity with same precedents)

    # Step 1. Create the improper covers
    work_table_pol = makeCover(prelations, successors)

    # Step 2. Syslo Polynomial algorithm
    final = successors.copy()
    visited = []

    for act, pred in prelations.items():
        for v in pred:
            for u in pred:
                if u != v and successors[v] != successors[u] and act not in visited:
                    # Find activity in the improper cover table
                    for key, value in work_table_pol.items():
                        if act in value.w:
                            w = value.w

                    # Find each row that belongs to the predecessors of activity
                    for key, value in work_table_pol.items():
                        if set(value.u).issubset(prelations[act]) and value.u:
                            vertex = set(value.u).pop()
                            # Compare successors of a row with the improper cover of the activity
                            if successors[vertex] != w:
                                for q in value.u:
                                    if final.has_key(q):
                                        final[q] = list(
                                            (set(final[q]) - set(w) | set([str(vertex) + separator + str(act)]))
                                            - set([act])
                                        )
                                    else:
                                        final[q] = list(
                                            set(successors[q]) - set(w) | set([str(vertex) + separator + str(act)])
                                        )
                                final[str(vertex) + separator + str(act)] = [act]

                                for l in w:
                                    visited.append(l)

    final = graph.successors2precedents(final)
    work_table = {}

    for act, pred in final.items():
        work_table[act] = Columns(pred, False, False, None, None, None)
        if act not in prelations:
            work_table[act].dummy = True

    # Step 3. Identify Dummy Activities And Identical Precedence Constraint of Diferent Activities
    visited_pred = {}
    for act, columns in work_table.items():
        pred = frozenset(columns.pre)
        if pred not in visited_pred:
            visited_pred[pred] = act
        else:
            columns.blocked = visited_pred[pred]

    # Step 4. Creating nodes
    # (a) find start nodes
    node = 0  # instead of 0, can start at 100 to avoid confusion with activities named with numbers when debugging
    for act, columns in work_table.items():
        if not columns.blocked:
            columns.start_node = node
            node += 1
        if columns.blocked:
            columns.start_node = work_table[columns.blocked].start_node

        # Associate activities with their end nodes
        for suc, suc_columns in work_table.items():
            if not suc_columns.blocked:
                if act in suc_columns.pre:
                    columns.suc = suc
                    break

    # (b) find end nodes
    graph_end_node = node  # Reserve one node for graph end
    node += 1
    pm_graph = pert.PertMultigraph()
    for act, columns in work_table.items():
        suc = columns.suc
        if suc:
            columns.end_node = work_table[suc].start_node
        else:
            # Create needed end nodes, avoiding multiple graph end nodes (adaptation)
            if act in end_act:
                columns.end_node = node
            else:
                columns.end_node = graph_end_node
                node += 1
        # Generate the graph
        _, _, dummy, _, start, end = columns
        pm_graph.add_arc((start, end), (act, dummy))

    p_graph = pm_graph.to_directed_graph()

    return p_graph
示例#38
0
def reactivenamedlist(name, *args, **kwargs):
    nlist = namedlist.namedlist('_nl_' + name, *args, **kwargs)
    rnl = type(str(name), (ReactiveNamedListMixin, nlist,), {})
    return rnl
示例#39
0
import namedlist


Family = namedlist.namedlist('Columns', ['u', 'w', 'est', 'no_est'])
                            # [0 Activities,   1 Successors, 2 Estable, 3 Non-estable,
                            #   Activities = (Activities with same successors) 
    
  

def syslo(temp, pert_graph, alt):
    """
    Steps to build a PERT graph with the minimal number of dummy activities through the Syslo improper cover table
    
    return p_graph dictionary
    """

    # Step 0.1. Topological Sorting
    setfamily = []

    for k in sorted(temp, key = lambda k: len(temp[k]), reverse = True):
        setfamily.append(k)

    for k, v in temp.items():
        for k2, v2 in temp.items():
            if k != k2 and set(v).issubset(set(v2)) and len(v) < len(v2):
                setfamily.remove(k)
                setfamily.insert(setfamily.index(k2), k)
                setfamily.remove(k2)
                setfamily.insert(setfamily.index(k), k2)
                
示例#40
0
文件: utils.py 项目: osakaaa/wuzzer
__author__ = 'osakaaa'
"""Utility module with types difinitions"""
from namedlist import namedlist


FUZZMODES = ["headers", "post-data", "url-data", "whole-request", "poc"]
HTTP_METHODS = ["HEAD", "GET", "POST", "OPTIONS", "PUT", "DELETE", "TRACE", "CONNECT"]
INPUT = ["wuzzer", "custom", "pcap"]

"""HTTP HEADER SPECIFICATION"""
HEADER = namedlist("HEADER", "name delimiter value content default fuzz")
"""HTTP POST DATA SPECIFICATION"""
DATA = namedlist("DATA", "name delimiter value content")
"""HTTP URL SPECIFICATION"""
PATH = namedlist("PATH", "type delimiter name value content")
"""FIRST LINE OF HTTP REQUEST"""
FIRSTLINER = namedlist("FIRSTLINER", "method url version")
"""TASK format"""
HEADER_GEN_MAP = {"Connection": "connection",
                  "Accept-Charset": "acceptcharset",
                  "Accept-Language": "acceptlanguage",
                  "Accept": "accept",
                  "Accept-Encoding": "acceptencoding",
                  "Content-Type": "contenttype",
                  "Range": "range",
                  "Authorization": "basic_auth",
                  "Cookie": "cookie"}

BYTE = 8
WORD = 16
DWORD = 32
示例#41
0
    :copyright: (c) 2015 The Regents of the University of California.
    :license: GNU GPL, see licenses/GNU GPLv3.txt for more details.
'''

# load modules/submodules
import unittest

from namedlist import namedlist

from xldlib.chemical import formula

# OBJECTS
# -------

Formula = namedlist("Formula", "string strict conditions")
Condition = namedlist("Condition", "formula mass")

# ITEMS
# -----

FORMULAS = [
    Formula("C2", False, [
        Condition("C2", 24.0),
        Condition("C4", 48.0),
        ]),
    Formula("Hex", False, [
        Condition('O5 C6 H10', 162.05282347),
        Condition('O10 C12 H20', 324.10564694),
        ]),
    Formula("HexNAc", False, [
示例#42
0
from conn_db import conn_DB
from namedlist import namedlist
from summarizer import summarize
from comment_select import *

import sys
import argparse
import datetime
import math
import nltk
import re

#TODO: reconsider period

CommentInfo = namedlist('CommentInfo','cid,sentence,rating')
SENT_TOKENIZER = nltk.data.load('tokenizers/punkt/english.pickle')
PERCENT = 0.4
LEAST = 5
SHORTEST = 100
SENTIMENT = ['negative','positive']

def summary_update(db, cur, tid, period, portion):
    current = datetime.datetime.now()
    last = current - datetime.timedelta(hours=period)
    last = last.strftime("%Y-%m-%d %H:%M:%S")
    print last
    get_entities = "SELECT eid FROM entity where tid="+tid+" AND updated>'"+last+"';"
    print get_entities
    cur.execute(get_entities)
    entities = cur.fetchall()
    counter = 1
示例#43
0
from xldlib.definitions import re
from xldlib.resources.parameters import defaults

from . import configurations as config


__all__ = [
    'ProteolyticEnzyme'
]


# OBJECTS
# -------

Cleaved = namedlist("Cleaved", "peptide position remaining")


class ProteolyticEnzyme(object):
    '''
    Object definition for an item that mimics a proteolytic enzyme.
    The object is a wrapper around a compiled regex, which then
    provides convenience methods for cleaving a target sequence.
    '''

    def __init__(self, enzyme=None):
        super(ProteolyticEnzyme, self).__init__()

        self.enzyme = self._enzymechecker(enzyme)
        self.cut_regex = re.compile(self.enzyme.cut_regex)
示例#44
0
from xldlib.utils import decorators, logger

from . import lineedit, spinbox


# ERRORS
# ------

ERROR = 'Invalid value entered, value must match {}'


# OBJECTS
# -------

Storage = namedlist("Storage", [
    ("key", NO_DEFAULT),
    ("data", defaults.DEFAULTS)]
)


class BaseStorage(views.ViewObject):
    '''Inheritable property definitions for connecting change state/saves'''

    @property
    def store(self):
        return self._store

    @property
    def data(self):
        return self.store.data

    @property
示例#45
0
from datetime import date

from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import SIGNAL

import web_scraper
from collections import namedtuple
from namedlist import namedlist

Subject = namedlist("Subject",
    ["active", "nr", "name", "req", "exam_type", "semester", "grade",
    "status", "credits", "note", "attempt", "date"])

# TODO: translate
Subject.header = ["Count", "Nr", "Name", "Req", "Exam type", "Semester", "Grade",
    "Status", "Credits", "Note", "Attempt", "Date"]

#Subject.visibility = [True, False, True, False, False, False, True,
#    False, True, False, False, False]


class GradesModelProxy(QtGui.QSortFilterProxyModel):
    """This proxy offers column visibility toggling and filtering the data
    from GradesModel.
    """
    def __init__(self, parent=None):
        QtGui.QSortFilterProxyModel.__init__(self, parent)
        self.col_visibility = [True, False, True, False, False, False, True,
            False, True, False, False, False]
        self.setDynamicSortFilter(True)
示例#46
0

@sequence.serializable("SpectralFormatVersion")
class Version(namedlist("Version", "name major minor revision "
    "distiller format defaults")):

    #     PUBLIC

    def tostr(self):
        '''String representation of the version'''

        return "{0}.{1}.{2}, {3}".format(self.major, self.minor,
            self.revision, self.distiller)


MgfDefaults = namedlist("MgfDefaults", "regexp start end skip")
MzmlDefaults = namedlist("MzmlDefaults", "regexp")
MzxmlDefaults = namedlist("MzxmlDefaults", "regexp")
LinkDefaults = namedlist("LinkDefaults", "regexp")


@serialization.register("SpectralFormat")
class SpectralFormat(dicttools.EngineDict):
    '''Method definitions for spectral format objects'''

    #     PUBLIC

    def matchfile(self, fileobj):
        '''Matches a given fileobj to a spectral database format'''

        fileformat = _fileformat(fileobj)
示例#47
0
# load modules/submodules
import atexit
import os

from namedlist import namedlist

from PySide import QtCore

from xldlib.general import mapping
from xldlib.resources import paths

# OBJECTS
# -------

MinimumScore = namedlist("MinimumScore", "protein peptide")
MaximumEV = namedlist("MaximumEV", "protein peptide")


# PATHS
# -----
DEFAULT_PATH = os.path.join(paths.DIRS['preferences'], 'defaults.json')


# DATA
# ----

DEFAULTS = mapping.Configurations(DEFAULT_PATH, [
    # SYSTEM
    # ------
    # Updates
示例#48
0
from namedlist import namedlist

A = namedlist("A", "x y")
B = namedlist("B", "x y")
C = namedlist("C", "i j")

print(A(x=10, y=20) == A(x=10, y=20))
print(A(x=10, y=20) == B(x=10, y=20))
print(A(x=10, y=20) == C(i=10, j=20))

print(A(x=10, y=20) < A(x=20, y=10))
示例#49
0
__all__ = [
    'TAXA'
]


# OBJECTS
# -------


Species = namedlist("Species", [
    'id',
    'species',
    'genus',
    ('family', None),
    ('order', None),
    ('class_', None),
    ('phylum', None),
    ('kingdom', None),
    ('domain', None),
])


# DATA
# ----

TAXA = OrderedDict([
    ('M. musculus', Species(id='10090',
        species='musculus',
        genus='Mus',
        family='Muridae',
示例#50
0
    :license: GNU GPL, see licenses/GNU GPLv3.txt for more details.
'''

# load modules/submodules
from namedlist import namedlist

__all__ = [
    'INPUT_TABLE_BAR',
    'TABLE_BAR',
    'TRANSITIONS_BAR'
]

# OBJECTS
# -------

Shortcut = namedlist("Shortcut", "key sequence description")

# DATA
# ----

#MENU = [
#    Shortcut(key='Ctrl+F4', description='Close Application'),
#    Shortcut(key='Ctrl+s', description='Save Settings')
#]
#

TABLE_BAR = [
    Shortcut(key='A',
        sequence='Ctrl + A',
        description='Select All'),
    Shortcut(key='B',
示例#51
0
    :copyright: (c) 2015 The Regents of the University of California.
    :license: GNU GPL, see licenses/GNU GPLv3.txt for more details.
'''

# load modules/submodules
import unittest

from namedlist import namedlist

from xldlib.chemical.proteins.configurations import protease
from xldlib.definitions import re

# OBJECTS
# -------

Test = namedlist("Test", "sequence position")


# ITEMS
# -----

PROTEASES = [
    ('Trypsin', ['K', 'R'], ['P'], protease.TERMINI['C']),
    ('Lys-C', ['K'], [], protease.TERMINI['C']),
    ('Lys-N', ['K'], [], protease.TERMINI['N']),
    ('Fake-TrypsinN', ['K', 'R'], ['P'], protease.TERMINI['N']),
]

TESTS = [
    Test("MKWVTF", [1, 1, 0, 0]),
    Test("PKLKPDPNTLCDEFK", [1, 1, 0, 2]),
示例#52
0
import unittest

from collections import namedtuple

from namedlist import namedlist

import numpy as np

from xldlib.general.mapping import functions, serialize
from xldlib.utils.io_ import high_level


# OBJECTS
# -------

JsonTest = namedlist("JsonTest", "input output")
NamedList = namedlist("NamedList", "field")
NamedTuple = namedtuple("NamedTuple", "field")


class Unserializable(object):
    '''Unserializable object definition'''


class NoSetter(dict):
    '''Dictionary object with an optionally blocked `__setitem__` method'''

    # BLOCKED
    # -------
    blocked = False
示例#53
0
文件: las.py 项目: chookee/lasio
    else:
        from StringIO import StringIO
else:
    from StringIO import StringIO
import traceback

# Third-party packages available on PyPi
from namedlist import namedlist
import numpy


logger = logging.getLogger(__name__)
__version__ = "0.7.7"


HeaderItem = namedlist("HeaderItem", ["mnemonic", "unit", "value", "descr"])
Curve = namedlist("Curve", ["mnemonic", "unit", "value", "descr", "data"])


class LASDataError(Exception):

    '''Error during reading of numerical data from LAS file.'''
    pass


class LASHeaderError(Exception):

    '''Error during reading of header data from LAS file.'''
    pass

示例#54
0
                host.interface)

    def find(self, dst_ip):
        try:
            return next(e for e in self.entries if dst_ip & e.mask == e.net)
        except StopIteration:
            raise KeyError('no matching entry for {}'.format(dst_ip))

    def add(self, net, mask, gateway, interface):
        self.entries.append(Entry(
            IP(net),
            IP(mask),
            IP(gateway),
            interface))

    def __getitem__(self, index):
        return self.entries[index]

    def __iter__(self):
        return iter(self.entries)

    def __repr__(self):
        s = '{:16} {:16} {:16} {:16}\n'.format(
            'Network', 'Mask', 'Gateway', 'Interface')
        for net, mask, gateway, interface in self:
            s += '{:16} {:16} {:16} {:16}\n'.format(
                net, mask, gateway, interface.ip)
        return s

Entry = namedlist('Entry', ['net', 'mask', 'gateway', 'interface'])
示例#55
0
    :copyright: (c) 2015 The Regents of the University of California.
    :license: GNU GPL, see licenses/GNU GPLv3.txt for more details.
'''

# load modules/submodules
from namedlist import namedlist

__all__ = [
    'SCAN_TITLES'
]

# OBJECTS
# -------

ScanTitle = namedlist("ScanTitle", "vendor format distiller regexp")

# DATA
# ----

# Each regex added needs to have a <num> and a <frac>
# capture group. If the fraction is not specified, this
# can capture a null group, but the num is crucial for
# scan linking. Any other capture groups may be additionally defined.


SCAN_TITLES = [
    ScanTitle(vendor='thermo_finnigan',
        format='raw',
        distiller='DTA SuperCharge',
        regexp=r'(?P<frac>\w+)\.(?P<num>\d+)\.\d+\.\d{1,2}\.dta'),
示例#56
0
文件: model.py 项目: matcom/autoexam
- id
- tag_names
- text
- answers

Answer:
- valid
- fixed_position
- text
"""

import json
from namedlist import namedlist

# Project = namedlist('Project', ['name', 'total_questions_per_exam', 'total_exams_to_generate', 'current_page', 'tags', 'questions'])
Project = namedlist('Project', ['name', 'total_questions_per_exam', 'total_exams_to_generate', 'tags', 'questions'])
Tag = namedlist('Tag', ['name', 'min_questions'])
Question = namedlist('Question', ['id', 'tag_names', 'text', 'answers'])
Answer = namedlist('Answer', ['valid', 'fixed_position', 'text'])


def dump_project(proj, path):
    try:
        s = json.dumps(proj)
        with open(path, 'w') as fp:
            fp.write(s)
    except:
        print 'Error saving Project'


def load_project(path):
示例#57
0
# -----

VIEWS = paths.DIRS['views']

SPLASH_PATH = os.path.join(VIEWS, 'splash.json')
CROSSLINK_DISCOVERER_PATH = os.path.join(VIEWS, 'discoverer.json')
TRANSITION_PATH = os.path.join(VIEWS, 'transitions.json')
FINGERPRINT_PATH = os.path.join(VIEWS, 'fingerprint.json')
DIALOGS_PATH = os.path.join(VIEWS, 'dialogs.json')
CONTEXTS_PATH = os.path.join(VIEWS, 'contexts.json')


# OBJECTS
# -------

Dimensions = namedlist("Dimensions", "w h")
Frame = namedlist("Frame", "x y w h")
XlDiscovererMode = namedlist("XlDiscovererMode", "icon title banner")
Thresholds = namedlist("Thresholds", "upper lower")


class ViewConfigurations(mapping.Configurations):
    '''Definitions which defines a view_edited signal back to edit'''

    def __init__(self, *args, **kwds):
        super(ViewConfigurations, self).__init__(*args, **kwds)

        self.edited = signals.Signal()
        self.edited.connect(self.modified)

    #     PUBLIC
示例#58
0
文件: data.py 项目: howardjohn/pyty
"""Stores data structures"""
from enum import Enum
from namedlist import namedlist


class Split(Enum):
    """Enum containing information of how the window is split:
    horizontally or vertically.
    """
    vert = 0
    horz = 1

    def swap(self):
        """Returns the opposite split.
        """
        return Split((self.value + 1) % 2)

Rect = namedlist('Rect', 'x, y, w, h')
Size = namedlist('Size', 'w, h')
示例#59
0
    :license: GNU GPL, see licenses/GNU GPLv3.txt for more details.
'''

# load modules/submodules
import unittest

from namedlist import namedlist

from PySide import QtCore, QtGui

from xldlib.qt.resources import enums

# OBJECTS
# -------

Test = namedlist("Test", "instance key enum")


# ITEMS
# -----

ITEMS = [
    Test(instance=enums.CONNECTION,
        key='Queued',
        enum=QtCore.Qt.QueuedConnection),
    Test(instance=enums.CURSOR,
        key='Arrow',
        enum=QtCore.Qt.ArrowCursor),
    Test(instance=enums.EDIT_TRIGGER,
        key='No',
        enum=QtGui.QAbstractItemView.NoEditTriggers),
from PySide import QtCore, QtGui

from xldlib.definitions import ZIP
from xldlib.general import mapping
from xldlib.gui.views import widgets
from xldlib.qt.objects import views
from xldlib.qt import resources as qt
from xldlib.resources.parameters import defaults
from xldlib.utils import logger

from . import base_canvas, legends, lines, plots

# OBJECTS
# -------

PeakIndexes = namedlist("PeakIndexes", "start end")


# AXIS
# ----


def tickStrings(values, scale, spacing, str_format = '{:.1e}'):
    return [str_format.format(i) for i in values]


# VIEWBOX
# -------


class CustomViewBox(pg.ViewBox):