Ejemplo n.º 1
0
def main():
    #print('Getting data')
    #get_data()
    print('Starting examinations')
    # This and other code in this and other modules is sometimes a bit confusing
    # because I use 'seq' for both just the integer of the sequence leader *and*
    # the corresponding SequenceInfo object.
    # data is a dictionary mapping the ints to the SequenceInfo objects.
    data = SequencesManager(CONFIG)
    data.readonly_init()
    targets = []
    derp = []
    for i, seq in enumerate(data.values()):
        #print('looking at seq {}'.format(i))
        ress = filter_seq(seq)
        if ress:
            derp.append((seq, ress))
    print('Getting details for {} seqs'.format(len(derp)))
    for seq, ress in derp:
        res = examine_seq(seq.id, None, *ress, seq)
        if res:
            targets.append((seq, res))
    targets.sort(
        key=lambda tup: (not tup[0].driver, tup[0].klass, tup[0].cofactor)
    )  # Drivers first, then sort by class first, secondary sort by comp size
    for seq, ress in targets:
        for res in ress:
            print("{:>6} ~ {} (class {}) maybe: {}".format(
                seq.seq, seq.guide, seq.klass,
                aq.analyze_composite_tau_to_str(res, 'C' + str(seq.cofactor))))
def filter(filt_expr, sort_expr, N, sep):
    filt = lambda ali: eval(filt_expr)
    sort = lambda ali: eval(sort_expr)
    seqinfo = SequencesManager(CONFIG)
    seqinfo.readonly_init()
    out = [ali for ali in seqinfo.values() if filt(ali)]
    out.sort(key=sort)
    out = out[:N]
    #print('\n'.join("{}: {}, {}".format(ali.seq, filt(ali), sort(ali)) for ali in out))
    print(sep.join(str(ali.seq) for ali in out))
Ejemplo n.º 3
0
def main():
     err = "Error: commands are 'add', 'drop', or 'spider'"
     if len(argv) < 2:
          print(err)
          exit(-1)

     s = SequencesManager(CONFIG)

     with s.acquire_lock(block_minutes=CONFIG['blockminutes']): # reads and inits
          inner_main(s, err)
def main():
    err = "Error: commands are 'add', 'drop', or 'spider'"
    if len(argv) < 2:
        print(err)
        exit(-1)

    s = SequencesManager(CONFIG)

    with s.acquire_lock(
            block_minutes=CONFIG['blockminutes']):  # reads and inits
        inner_main(s, err)
Ejemplo n.º 5
0
def main():
     seqsmanager = SequencesManager(CONFIG, _sequence_class=OldInfo)
     with seqsmanager.acquire_lock(block_minutes=0):
          LOGGER.info("seqsmanager inited, converting seq format...")
          for seq, ali in seqsmanager.items():
               # we use either ali.seq or ali[0], but for constructor use
               # we need the attrs as dictionary keywords instead
               dct = {kw: getattr(ali, kw) for kw in ali._map}
               newali = SequenceInfo(**dct)
               seqsmanager._data[seq] = newali
               # adjust the following for the specifics of the new SequenceInfo
               newali.set_abundance()
Ejemplo n.º 6
0
def main():
    seqsmanager = SequencesManager(CONFIG, _sequence_class=OldInfo)
    with seqsmanager.acquire_lock(block_minutes=0):
        LOGGER.info("seqsmanager inited, converting seq format...")
        for seq, ali in seqsmanager.items():
            # we use either ali.seq or ali[0], but for constructor use
            # we need the attrs as dictionary keywords instead
            dct = {kw: getattr(ali, kw) for kw in ali._map}
            newali = SequenceInfo(**dct)
            seqsmanager._data[seq] = newali
            # adjust the following for the specifics of the new SequenceInfo
            newali.set_abundance()
     def test_auto_lock_unlock(self):
          seqinfo = SequencesManager(self.config)
          self.assertFalse(exists(self.txtfile))

          with seqinfo.acquire_lock(block_minutes=0):
               self.assertTrue(seqinfo._have_lock)
               self.assertTrue(exists(self.lockfile))
               self.assertFalse(exists(self.txtfile))

          self.assertFalse(exists(self.lockfile))
          self.assertTrue(exists(self.txtfile))

          self.assertFilesEqual(seqinfo.file, self.snapshot)
          self.assertFilesEqual(self.txtfile, self.txtsnapshot)
Ejemplo n.º 8
0
    def test_auto_lock_unlock(self):
        seqinfo = SequencesManager(self.config)
        self.assertFalse(exists(self.txtfile))

        with seqinfo.acquire_lock(block_minutes=0):
            self.assertTrue(seqinfo._have_lock)
            self.assertTrue(exists(self.lockfile))
            self.assertFalse(exists(self.txtfile))

        self.assertFalse(exists(self.lockfile))
        self.assertTrue(exists(self.txtfile))

        self.assertFilesEqual(seqinfo.file, self.snapshot)
        self.assertFilesEqual(self.txtfile, self.txtsnapshot)
Ejemplo n.º 9
0
def main():
    global LOOPING

    try:
        special = [int(arg) for arg in sys.argv[1:]]
    except ValueError:
        print('Error: Args are sequences to be run')
        sys.exit(-1)

    if special:
        LOOPING = False
        # de-duplicate while preserving order
        seen = set()
        seen_add = seen.add  # more efficient, tho gain is negligible for small specials
        special = [s for s in special if not (s in seen or seen_add(s))]
    else:
        special = None

    seqinfo = SequencesManager(CONFIG)
    updater = AllSeqUpdater(CONFIG['AllSeqUpdater'])

    # This means you can start it once and leave it, but by setting LOOPING = False you can make it one-and-done
    # This would be a good place for a do...while syntax
    while True:
        quitting = inner_main(updater, seqinfo, special)

        if LOOPING and not quitting:
            LOGGER.info('Sleeping.')
            sleep(SLEEPMINUTES * 60)
        else:
            break
     def test_manual_lock_unlock(self):
          seqinfo = SequencesManager(self.config)

          seqinfo.lock_read_init()

          self.assertTrue(seqinfo._have_lock)
          self.assertTrue(exists(self.lockfile))
          self.assertFalse(exists(self.txtfile))

          seqinfo.write_unlock()

          self.assertFalse(exists(self.lockfile))
          self.assertTrue(exists(self.txtfile))

          self.assertFilesEqual(seqinfo.file, self.snapshot)
          self.assertFilesEqual(self.txtfile, self.txtsnapshot)
Ejemplo n.º 11
0
    def test_readonly(self):
        seqinfo = SequencesManager(self.config)

        seqinfo.readonly_init()

        self.assertFalse(seqinfo._have_lock)
        self.assertFalse(exists(self.lockfile))
        self.assertRaises(LockError, seqinfo.write)
        self.assertRaises(LockError, seqinfo.drop, 276)
        self.assertRaises(LockError, seqinfo.push_new_info, SequenceInfo)
        self.assertRaises(LockError, seqinfo.find_and_drop_merges)
        self.assertRaises(LockError, seqinfo.reserve_seqs, 'mersenneforum',
                          [276])
        self.assertRaises(LockError, seqinfo.unreserve_seqs, 'mersenneforum',
                          [276])

        self.assertFalse(exists(self.txtfile))

        seqinfo.lock_read_init(
        )  # Just verify that we can re-init as we please
        seqinfo.readonly_init()  # ...and that re-init clears all locking state
        self.assertFalse(seqinfo._have_lock)
     def test_readonly(self):
          seqinfo = SequencesManager(self.config)

          seqinfo.readonly_init()

          self.assertFalse(seqinfo._have_lock)
          self.assertFalse(exists(self.lockfile))
          self.assertRaises(LockError, seqinfo.write)
          self.assertRaises(LockError, seqinfo.drop, 276)
          self.assertRaises(LockError, seqinfo.push_new_info, SequenceInfo)
          self.assertRaises(LockError, seqinfo.find_and_drop_merges)
          self.assertRaises(LockError, seqinfo.reserve_seqs, 'mersenneforum', [276])
          self.assertRaises(LockError, seqinfo.unreserve_seqs, 'mersenneforum', [276])

          self.assertFalse(exists(self.txtfile))

          seqinfo.lock_read_init() # Just verify that we can re-init as we please
          seqinfo.readonly_init() # ...and that re-init clears all locking state
          self.assertFalse(seqinfo._have_lock)
Ejemplo n.º 13
0
    def test_manual_lock_unlock(self):
        seqinfo = SequencesManager(self.config)

        seqinfo.lock_read_init()

        self.assertTrue(seqinfo._have_lock)
        self.assertTrue(exists(self.lockfile))
        self.assertFalse(exists(self.txtfile))

        seqinfo.write_unlock()

        self.assertFalse(exists(self.lockfile))
        self.assertTrue(exists(self.txtfile))

        self.assertFilesEqual(seqinfo.file, self.snapshot)
        self.assertFilesEqual(self.txtfile, self.txtsnapshot)
def main():
    seqinfo = SequencesManager(CONFIG)
    with seqinfo.acquire_lock(block_minutes=CONFIG['blockminutes']):
        LOGGER.info("seqinfo inited, updating priorities...")
        for ali in seqinfo.values():
            ali.calculate_priority()
Ejemplo n.º 15
0
    def test_already_locked(self):
        open(self.lockfile, 'w').close()

        seqinfo = SequencesManager(self.config)

        self.assertRaises(LockError, seqinfo.lock_read_init)
def main():
     seqinfo = SequencesManager(CONFIG)
     with seqinfo.acquire_lock(block_minutes=CONFIG['blockminutes']):
          LOGGER.info("seqinfo inited, updating priorities...")
          for ali in seqinfo.values():
               ali.calculate_priority()