Exemple #1
0
def main():
    Support.log(msg="# Parsing and checking the input arguments\n", level="STEP")
    args = Argparser.parse_mascotte_arguments()
    logArgs(args)
    if args['rndseed'] != None:
        random.seed(args['rndseed'])

    Support.log(msg="# Setting up for simulating human diploid genome\n", level="STEP")
    human = Genomics.HumanGenome(reference=args['reference'], snplist=args['snplist'], snpratio=args['snpratio'], HEHOratio=args['HEHOratio'], ignorelist=args['ignore'])
    maternalhuman = os.path.join(args['xdir'], 'human.maternal.fa')
    paternalhuman = os.path.join(args['xdir'], 'human.paternal.fa')
    Support.log(msg="# Simulating human diploid genome\n", level="STEP")
    human.buildGenome(maternalout=maternalhuman, paternalout=paternalhuman)
    Support.log('Chromosomes: {}\n'.format(', '.join(human.chromosomes)), level='INFO')
    Support.log('Number of simulated SNPs: {}\n'.format(human.numsnps), level='INFO')
    Support.log('Number of heterozygous SNPs: {}\n'.format(human.hetsnps), level='INFO')
    Support.log('Maternal chromosome of human genome written in {}\n'.format(maternalhuman), level='INFO')
    Support.log('Maternal chromosome of human genome written in {}\n'.format(paternalhuman), level='INFO')

    Support.log(msg="# Simulating tumor clones and their evolution through specified CNAs\n", level="STEP")
    tumor = Mutation.simulateEvolution(numclones=args['numclones'], humanGenome=human, binsize=args['binsize'], mutations=args['mutations'])
    Support.log('Simulated tumor clones: {}\n'.format(', '.join([clone.label for clone in tumor.clones])), level='INFO')
    Support.log('Founder tumor clone: {}\n'.format(tumor.root.label), level='INFO')
    with open(os.path.join(args['xdir'], 'tumor.dot'), 'w') as o: o.write("{}\n".format(tumor.draw()))
    Support.log('The resulting tumor evolution of clones and related CNAs have been drawn in {} as dot format\n'.format(os.path.join(args['xdir'], 'tumor.dot')), level='INFO')
    Support.log('Genome length of the various tumor clones:\n\t{}\n'.format('\n\t'.join(['{}: {}'.format(clone.label, clone.genomeLength()) for clone in tumor.clones])), level='INFO')
    Support.log('Computing and segmenting the copy-number profiles jointly for all tumor clones\n', level='INFO')
    segments = segmentation(evolution=tumor)
    Support.log('Total number of resulting segments= {}\n'.format(sum(len(segments[chro]) for chro in tumor.human.chromosomes)), level='INFO')
    segout = os.path.join(args['xdir'], 'copynumbers.csv')
    with open(segout, 'w') as o:
        o.write('\t'.join(['#CHR', 'START', 'END'] + [clone.label for clone in tumor.clones]) + '\n')
        o.write('\n'.join(['\t'.join(map(str, [chro, seg[0], seg[1]]+['{}|{}'.format(segments[chro][seg][clone.idx]['m'], segments[chro][seg][clone.idx]['p']) for clone in tumor.clones])) for chro in tumor.human.chromosomes for seg in sorted(segments[chro], key=(lambda x : x[0]))]))
        o.write('\n')
    Support.log('The allele-specific copy number profiles for every tumor clone has been written in {}\n'.format(segout), level='INFO')
    Support.log('Writing the FASTA-format genomes of tumor clones\n', level='INFO')
    if args['jobs'] == 1:
        for clone in tumor.clones:
            maternalout = os.path.join(args['xdir'], '{}.maternal.fa'.format(clone.label))
            paternalout = os.path.join(args['xdir'], '{}.paternal.fa'.format(clone.label))
            clone.buildGenome(maternalout, paternalout)
    else:
        builder = Builder.CloneGenomeBuilder(tumor, args['xdir'])
        builder.parallelbuild(args['jobs'])
    Support.log('Tumor-clone genomes wrote in:\n{}\n'.format('\n'.join(['\t{}: maternal > {} and paternal > {}'.format(clone.label, os.path.join(args['xdir'], '{}.maternal.fa'.format(clone.label)), os.path.join(args['xdir'], '{}.paternal.fa'.format(clone.label))) for clone in tumor.clones])), level='INFO')
    Support.log('KTHXBY!\n', level='STEP')
Exemple #2
0
def main():
    global ARGS
    ARGS = Argparser.parse_args()

    if ARGS.passive:
        global PASSIVE_MODE
        PASSIVE_MODE = True

    addr = None
    if ARGS.address is not None:
        addr = (ARGS.address, ARGS.port)
    else:
        address = input("Input address: ")
        port = input('Input port: ')
        if port != '':
            addr = (address, port)
        else:
            addr = (address, ARGS.port)
    print('Connecting to ' + str(addr[0]) + ':' + str(addr[1]))

    sock = socket.socket()
    sock.settimeout(TIMEOUT)
    data_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    try:
        sock = connect(addr)
        print(receive_full_reply(sock))

        data_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        data_sock.settimeout(TIMEOUT)
        data_sock.close()

        if ARGS.get or ARGS.put:
            batch_mode(sock, data_sock)

        login(sock, None, None, None)
        run(sock, data_sock)

    except ConnectionError as error:
        print(error)
        sys.exit(1)

    except Exception as error:
        print(error)
        run(sock, data_sock)
Exemple #3
0
import Argparser

if __name__ == '__main__':
    args = Argparser.parse_args()
    args.func(args)
import sudokuPuzzles
import SudokuSolver
import Argparser

argparser = Argparser.Argparser()
find_all = argparser.find_all
puzzle_number = argparser.puzzle_number

puzzles = sudokuPuzzles.puzzle_dict


def show_solutions(solutions):
    if solutions:
        print(f'The following {len(solutions)} solutions where found:')
        for i, board in enumerate(solutions, 1):
            print(f'#{i}\n{board} \n')
    else:
        print('no possible solutions for this puzzle')


if puzzle_number == 'generate':
    sudoku = SudokuSolver.Sudoku(None)
    sudoku.show_board()
    sudoku.solve(find_all)
    show_solutions(sudoku.solutions)
else:
    puzzle = puzzles[puzzle_number]
    sudoku = SudokuSolver.Sudoku(puzzle)
    print(f'The original puzzle looks like:\n{sudoku.board}\n')
    sudoku.solve(find_all)
    show_solutions(sudoku.solutions)
Exemple #5
0
import numpy as np
from matplotlib import pyplot as plt
import argparse

import RootUtils
import SystemUtils
import Argparser


def getUVFromTitle(title):
    u, v, N, rest = title.split(',')
    return u, v, N, rest


parser = argparse.ArgumentParser()
FLAGS, _ = Argparser.add_args(parser)
Argparser.print_args(FLAGS)

ROOT.gROOT.SetBatch(ROOT.kTRUE)
ROOT.gStyle.SetOptStat(ROOT.kFALSE)
maind = 'outpath'
layers = [x for x in range(1, FLAGS.nlayers + 1)]
subd_names = ['layer' + str(layers[x]) for x in range(len(layers))]
histo_names_rechits = [[] for _ in range(len(layers))]
histo_names_geom = [[] for _ in range(len(layers))]
for il, l in enumerate(layers):
    with open('data/HistoNamesRecHitsLayer' + str(l) + '_mask' +
              str(FLAGS.mask) + '.txt') as f:
        for line in f:
            histo_names_rechits[il].append(line[:-1])
    with open('data/HistoNamesGeomLayer' + str(l) + '_mask' + str(FLAGS.mask) +