示例#1
0
    def __init__(self, Sound=None):

        self.spritesheet = Image.SpriteSheet(path="res\\testSheet.png",
                                             spriteSize=32)
        self.OffsetX, self.OffsetY = 0, 0
        self.animTiles = []
        self.backRendered = False
        self.playerInputs = Constants.PlayerControls

        self.Entities = []

        super().__init__()

        self.TileMap, caverns = Mapper.generateCellularAutomata()
        self.entitypositions = Mapper.placeEnemiesCellular(caverns)

        for position in self.entitypositions:
            self.Entities.append(
                Entities.TestEnemy(x=position[1],
                                   y=position[0],
                                   Map=self.TileMap))

        playerPos = choice(caverns[0])
        while playerPos in self.entitypositions:
            playerPos = choice(caverns[0])

        self.player = Entities.Player(x=playerPos[1],
                                      y=playerPos[0],
                                      map=self.TileMap)
        self.graph = Pathfinding.Graph(self.TileMap)

        self.Sound = SoundHandler.Sound()
        self.Sound.PlayMusic('res/SFX/music.wav')

        self.offsetScene()
示例#2
0
def run(input_):
    operator = ''
    a = Stack()
    # Stack Excution Test
    count = 0
    for i in input_:
        if i[0] == 'L':
            a.Loader(i[1])
            a.StackViewer()

        elif i[0] == 'T':
            temp = []
            temp.append(operator)
            temp.append(a.getStack())
            temp.append(i[1])

            print(Mapper.Mapper(temp))
            a.ClearStack()
        else:
            a.StackViewer()
            print(i)
            if len(a.stack) == 0:
                print(Mapper.Mapper(i))
            else:
                a.StackViewer()
                print(i)
                operator = i[0]

    a.ClearStack()
    a.StackViewer()
示例#3
0
def main():
    """Funcion principal, donde interactuamos con las 
       demas clases pasandoles los ficheros necesarios e 
       instanciando las clases del MapReduce"""

    num_cores = 4
    files = getArgs()

    file_manager = FileManager(files)
    lines_files = file_manager.split_in_lines()

    num_lines = len(lines_files)
    partialPart = num_lines / num_cores
    difference = num_lines - (partialPart * num_cores)

    mapper = Mapper("")
    for i in range(partialPart, (num_lines - partialPart) + 1, partialPart):
        t = threading.Thread(mapper.mapping(lines_files[i - partialPart:i]))
        t.start()

    t = threading.Thread(
        mapper.mapping(lines_files[num_lines -
                                   (partialPart + difference):num_lines]))
    t.start()

    shuffleDict = mapper.shuffle(mapper.wordsMap)

    reducer = Reducer()

    result = reducer.reduce(shuffleDict)

    dirToTxt(result)
示例#4
0
def calcColor(radlvl):
	"""
	Determines color based on Mapper.py's color 
	calculation functions.
	"""
	red 	= Mapper.calcRed(radlvl)
	green 	= Mapper.calcGreen(radlvl)
	blue 	= Mapper.calcBlue(radlvl)
	return "#" + red + green + blue
示例#5
0
class Earcon(object):
    mapper = Mapper.Mapper()

    def __init__(self, mapped_values):
        scale = self.retrieve_scale()
        self.earcon = self.create_motive(scale, mapped_values)

    def retrieve_scale(self):
        scale = Scale.Scale(self.mapper.degree, self.mapper.octave,
                            self.mapper.type).scale
        return scale

    def create_motive(self, scale, mapped_values):

        for item in mapped_values:
            for key, value in item.items():
                if key == "frequency":
                    if value is not None:
                        new_value = scale[value]
                    else:
                        new_value = scale[0]
                else:
                    if value is not None:
                        new_value = self.mapper.durations[value]
                    else:
                        new_value = self.mapper.durations[-1]

                item[key] = new_value

        return mapped_values
    def __init__(self):

        self.provider = DocumentProvider.DocumentProvider()
        self.jsonMod = JsonModifier.JsonModifier()
        self.mngCollCreator = MongoCollectionCreator.MongoCollectionCreator().create_collections()
        self.mapper = Mapper.Mapper()
        tc = TailableCursor.TailableCursor(self).watch_collection_changes()
示例#7
0
    def calculate_aggregate_loans(self):
        # Mapper object
        aggregator_map = Mapper.Mapper(self.input_path)
        data = aggregator_map.create_data_frame()

        # Reducer object
        reducer = Reducer.Reducer(data)
        reducer.reduce()
        reducer.print_to_csv(self.output_path)
示例#8
0
    def __init__(self, frame, size):
        self.size = size
        # make a new camera based on the size of the frame, then create the frame and add a start button.
        self.camera = Camera((0, 0), self.size[0] // Unit.UNIT,
                             self.size[1] // Unit.UNIT, Unit.UNIT)
        self.player = Player(100, 100, Unit.UNIT, Unit.UNIT)
        self.keyboard = Keyboard()
        self.result = States.STATES[1]

        frame.set_keydown_handler(self.keyboard.key_down)
        frame.set_keyup_handler(self.keyboard.key_up)

        sound = Sound()
        self.tiles = Mapper.get_start_tiles(self.camera)
        sound.play_death()
示例#9
0
    def __init__(self, width, height, mapFile):
        super().__init__(width, height)
        self.logger = Logger.Logger(pos = Main.WIDTH, width = Main.LOGWIDTH, height = Main.SCREEN_HEIGHT)
        path1 = Main.getPath("res/TileSheet.png")
        path2 = Main.getPath("res/AnimTileSheet.png")
        self.map = Mapper.Map(mapFile, path1, path2)

        self.CELLMAP = True

        if self.CELLMAP:
            self.tileMap, caverns = self.map.getCavernTileMap()
            playerLocationY, playerLocationX = random.choice(caverns[0])
            playerLocation = (playerLocationX, playerLocationY)
            self.player = Entities.Player(playerLocation[0],playerLocation[1],"res/playerSheet.png",self.tileMap,3,10, self.logger)
            enemyLocations = self.calculateEnemyPlacements(caverns, playerLocation)
            self.Entities = [self.player]
            for each in enemyLocations:
                seed = random.randint(0,3)
                if not seed == 1:
                    self.Entities.append(Entities.TestEnemy(each[0],each[1],self.tileMap))
                else:
                    self.Entities.append(Entities.Goblin(each[0], each[1], self.tileMap))
        else:
            self.tileMap = self.map.getTileMap()
            playerLocationY, playerLocationX = (2,2)
            playerLocation = (playerLocationY, playerLocationX)
            self.player = Entities.Player(playerLocationY,playerLocationX, "res/playerSheet.png", self.tileMap, 3, 10, self.logger)
            self.Entities = [self.player]
            #Will need to make a system of entity placement that isn't hard coded, but Im not entirely sure how other than random generation or messing around with alpha channels.
            # ^ IGNORE ALREADY DONE WITH RANDOM GEN
            self.DummyEnemies = [Entities.TestEnemy(5,5,self.tileMap, 100),
                                Entities.TestEnemy(5,7,self.tileMap, 100),
                                Entities.TestEnemy(4,6,self.tileMap, 100),
                                Entities.TestEnemy(6,6,self.tileMap, 100)]
            self.Entities.extend(self.DummyEnemies)
        self.graph = Pathing.Graph(self.tileMap)

        self.animTiles = []
        self.renderedBack = False
        self.CameraX = -(playerLocation[0] * Tiles.TILESIZE - Main.WIDTH/2)
        self.CameraY = -(playerLocation[1] * Tiles.TILESIZE - Main.HEIGHT/2)
示例#10
0
    def __init__(self, sg=None, Grange=None, org='mmu', name='SGPlot.eps'):

        if not sg is None and not isinstance(
                sg, SpliceGraph.SpliceGraph) and os.path.exists(sg):
            sg = SpliceGraph.SpliceGraph(filename=sg)
            if not isinstance(sg, SpliceGraph.SpliceGraph):
                sys.stderr.write(
                    "ERROR: not a splice graph received in SpliceGraphPlot.")
                sys.exit(1)
        elif not Grange is None:
            # get splice graphs within genomic range
            pass
        else:
            sys.exit(1)

        self.sg = sg
        self.file_name = name
        self.target_type = name.split('.')[1]

        # load a splice graph mapper
        self.mapper = Mapper.Mapper(verbose=0)
        self.initCanvas()
 def analyze_tables(self):
     for table in self.tables_list:
         print("Section:" + str(table['section_title']) +
               " ... Trying to analyze this table: " + str(table))
         self.set_table(table)
         self.find_rows()
         if self.table_rows_list:
             logging.info("1. rows found")
             print("1. Rows FOUND")
             self.find_headers()
             if self.table_headers:
                 logging.info("2. headers found")
                 print("2. Headers FOUND")
                 self.extract_data()
                 self.refine_data()
                 if self.data_rows:
                     logging.info("3. Data extracted")
                     logging.debug("DATA: " + str(self.data_rows))
                     print("3. Data extracted")
                     map_tool = Mapper.Mapper(self.chapter, self.graph,
                                              self.topic, self.resource,
                                              self.data_rows, 'json',
                                              table['section_title'])
                     map_tool.map()
                 else:
                     logging.debug(
                         "e3 - UNABLE TO EXTRACT DATA - resource: " +
                         str(self.resource) + "table : " + str(table))
                     print("e3 UNABLE TO EXTRACT DATA")
             else:
                 logging.debug(
                     " e2 Unable to find headers - resource: " + str(self.resource) + " under section : " \
                     + str(table['section_title']))
                 print("e2 UNABLE TO FIND HEADERS")
         else:
             logging.debug(" e1 Unable to rows - resource: " +
                           str(self.resource) + " table : " + str(table))
             print(" e1 UNABLE TO FIND ROWS")
         self.erase_table_data()
示例#12
0
def main():
    start_time = datetime.now()

    # Get the parameters
    parameters = get_args()
    Mapper.parameters_verification(parameters)
    typein = parameters.features_include
    typeout = parameters.features_exclude
    kmer = parameters.kmer
    output_name = parameters.o
    reads_thr = parameters.thr
    options = list(parameters.options)
    for input_file in range(len(parameters.fastq)):
        start_time_input = datetime.now()
        if len(parameters.fasta) == 1:
            genome_file = parameters.fasta[0]  #path to genome file
        else:
            genome_file = parameters.fasta[input_file]
        genome_name = os.path.basename(genome_file)
        genome_name = os.path.splitext(genome_name)[0]  #name of the genome

        riboseq_file = parameters.fastq[input_file]  #path of the fastq file
        riboseq_name = os.path.basename(riboseq_file)
        riboseq_name = os.path.splitext(riboseq_name)[
            0]  #name of the riboseq experience

        if len(parameters.gff) == 1:
            gff_file = parameters.gff[0]
        else:
            gff_file = parameters.gff[input_file]
        with open("ORFribomap_{}_{}_log.txt".format(riboseq_name, output_name),
                  "w") as log:
            # 1. Annotation of the ORFs with ORFtrack
            mapping_gff = "mapping_orf_{}.gff".format(genome_name)
            if os.path.exists(
                    mapping_gff
            ):  #if the ORFtrack file exists already, ORFtrack is skipped
                print(
                    mapping_gff +
                    " exists, it will be used to extract the intergenic ORFs. If the file doesn't result "
                    "from orftrack, please rename it and launch ORFribomap again"
                    .format(genome_name))
            else:
                orftrack_cmd = "orftrack -fna {} -gff {} -chr_exclude chrmt".format(
                    genome_file, gff_file)
                print("Launch : ", orftrack_cmd)
                process_orftrack = subprocess.run(orftrack_cmd,
                                                  shell=True,
                                                  universal_newlines=True)

            # 3. Potential launch of cutadapt and definition of the directory that will contain all the analysis files
            if not parameters.cutdir:
                cutdir = "."
                if len(parameters.adapt
                       ) == 1:  #the adaptor is used for all the files
                    adapt = parameters.adapt[0]
                else:
                    adapt = parameters.adapt[
                        input_file]  #each file has its adaptor
                print(" The cutadapt process will be launched")
                try:
                    print(
                        "\nNo directory for cutadapt files has been given, the cutadapt process is launching. "
                        "The reads are cut in {}-kmers".format(
                            parameters.kmer))
                    for size in kmer:
                        log.write(
                            Mapper.cut_reads(size, riboseq_file, adapt,
                                             riboseq_name))
                except:
                    print('''cutadapt seems to not be installed''')
            else:  #there exist a directory with the the reads already trimmed and cut
                print(
                    "\nYou entered directory(ies) for cutadapt files. No cutadapt process will be launched"
                )
                time.sleep(1)
                if len(parameters.cutdir) == 1:
                    cutdir = parameters.cutdir[0]
                else:
                    cutdir = parameters.cutdir[input_file]
                for size in kmer:
                    name_dir = "{}/kmer_{}".format(cutdir, size)
                    if not os.path.isdir(name_dir):
                        print(
                            name_dir +
                            " does not exist. The directories need to be named as kmer_x with x the size of "
                            "the kmer. ")
                        exit()

            # 4.Mapping of the reads on the non-translated sequences
            print("We start the mapping")

            # a. Building of the Bowtie index from the orfget output
            if "I" in options:
                cmd_bowtie = 'bowtie-build {} {}_all'.format(
                    genome_file, genome_name)
                print("Command launched: ", cmd_bowtie)
                process_bowtie = subprocess.run(cmd_bowtie,
                                                shell=True,
                                                universal_newlines=True,
                                                stdout=subprocess.PIPE)
                log.write(process_bowtie.stdout)
            else:
                print(
                    "The basename of Bowtie index files are expected to be : {}_all"
                    .format(genome_name))

            # b->f. Mapping of the reads on the Bowtie index
            if "M" in options:
                try:  #verification that pysam and bokeh are installed
                    import pysam
                    import bokeh
                except ImportError:
                    print(
                        "You need to install the python packages pysam and bokeh"
                    )
                for size in kmer:  #mapping of the reads
                    log.write(
                        Mapper.map2bam(cutdir, size, genome_name, riboseq_name,
                                       "all"))
            else:
                print(
                    "The name and path of the bam files are expected to be :"
                    "./kmer_n/{}_kmer_n_all_sorted_mapped.bam with n the size of the reads"
                    .format(riboseq_name))

            # g. Creation of the counting tables and periodicity tables
            if "B" in options:
                print("Counting tables are generated")
                log.write(
                    BAM2Reads(riboseq_name, mapping_gff, kmer, output_name,
                              typein, typeout))
            else:
                print(
                    "The name and path of the counting and periodicity files are expected to be :\n"
                    "./kmer_n/{}_kmer_n_{}_reads.tab with n the size of the reads\n"
                    "./kmer_n/{}_kmer_n_{}_periodicity_start.tab with n the size of the reads\n"
                    "./kmer_n/{}_kmer_n_{}_periodicity_stop.tab with n the size of the reads\n"
                    .format(riboseq_name, output_name, riboseq_name,
                            output_name, riboseq_name, output_name))

            # 5. Plotting of phasing, periodicity of the start and the stop
            if "P" in options:
                for size in kmer:
                    tab = pd.read_table(
                        "./kmer_{}/{}_kmer_{}_{}_reads.tab".format(
                            size, riboseq_name, size, output_name),
                        sep='\t')
                    # Plot of the reads phase and periodicity
                    Mapper.reads_phase_plot(tab, size, riboseq_name, reads_thr,
                                            output_name)
                    Mapper.reads_periodicity(size, riboseq_name, output_name,
                                             "start")
                    Mapper.reads_periodicity(size, riboseq_name, output_name,
                                             "stop")
            end_time_input = datetime.now()
            log.write("Duration for {} :{}".format(
                riboseq_name, end_time_input - start_time_input))
    end_time = datetime.now()
    print("\n\n")
    print('Duration: {}'.format(end_time - start_time))
示例#13
0
Equalize_bol = True
BINS_int = 4
OVERLAP_flt = 0.9
Clust_str = 'CompleteLinkage'
ClusterArguments_array = [1]  #The epsilon value

RightWrong_npArray = np.load('../../Mapper_Data_Files/filter_files/\
Synonyms/rightwrongfilter.npy')

while BINS_int < 21:

    TestObject_ma = ma.Mapper(Cloud_npArray,
                              MetricName_str,
                              LensName_str,
                              LensArguments_array,
                              Equalize_bol,
                              BINS_int,
                              OVERLAP_flt,
                              Clust_str,
                              ClusterArguments_array,
                              DebugMode_bol=False)
    #TestObject_ma.save_filter_values('../../Mapper_Data_Files/filter_files/',
    # 'easygoing_neighborsfilters')

    TestObject_ma.add_mean_properties('RightWrong', RightWrong_npArray)

    TestObject_ma.load_filter_values(
        '../../Mapper_Data_Files/filter_files/Synonyms/',
        'SynonymsAverageFilter')

    TestObject_ma.add_filter_to_graph()
    TestObject_ma.add_labels('Labels', LabelData_npArray)
    def analyze_tables(self):
        """
        Method used to analyze tables structure, compose a simple data structure containing data cells and the
         corresponding headers and give it to a Mapper object.

        Principal method of a HtmlTableParser object, it finds out headers and data, refines them, and finally join
         each others in order to be mapped by a Mapper object.

        :return:nothing
        """
        # Iterates over tables list
        for html_table in self.tables:

            # Update the analyzed table count
            self.tables_analyzed += 1

            # Instantiating statistics for this table
            self.headers_found_num = 0
            self.rows_extracted_num = 0
            self.data_extracted_num = 0

            # set as a class attribute the current html table
            self.current_html_table = html_table

            # create a Table object to contain data structures and statistics for a table
            tab = Table.Table()
            # set tab.n_rows as a result of count_rows()
            tab.n_rows = self.count_rows()
            # set other table properties, such as table attributes
            tab.table_attributes = html_table.attrib
            # find out the table section using find_table_section()
            tab.table_section = self.find_table_section()
            self.logging.info("Table under section: %s" % tab.table_section)

            # find headers for this table
            self.find_headers(tab)

            # Chose to not use this method as it resolves users' made errors but create problems with correctly
            #  written table
            # self.check_miss_subheaders(tab)

            # if headers have been found
            if tab.headers:
                self.logging.info("Headers Found")

                # Refine headers found
                self.refine_headers(tab)

                # Once the headers are refined, start to extract data cells
                self.extract_data(tab)

                # Refine data cells found
                self.refine_data(tab)

                # If data are correctly refined
                if tab.data_refined:
                    # Count data cells and data rows using table.count_data_cells_and_rows()
                    tab.count_data_cells_and_rows()
                    self.logging.info("Rows extracted: %d" % tab.data_refined_rows)
                    self.logging.info("Data extracted for this table: %d" % tab.cells_refined)

                    # update data cells extracted in order to make a final report
                    self.utils.data_extracted += tab.cells_refined
                    self.utils.rows_extracted += tab.data_refined_rows

                    # Create a MAPPER object in order to map data extracted
                    mapper = Mapper.Mapper(self.chapter, self.graph, self.topic, self.resource, tab.data_refined,
                                           'html', self.utils, tab.table_section)

                    # Start the mapping process
                    mapper.map()

                    # Compose headers not mapped for this resource
                    for header in mapper.headers_not_mapped:
                        if header not in self.headers_not_mapped:
                            # Compose a list  with the name of the current resource [0] and with values in [1]
                            support_list = [self.resource, mapper.headers_not_mapped[header]]
                            '''
                            result Eg in self.headers_not_mapped = {'header1': ['resource1',[value0,value1...]], \
                                                                'header2': ['resource2',[value0, value1, value2...]]...}
                            '''
                            self.headers_not_mapped[header] = support_list

                # If no data have been found for this table report this condition with tag E3
                else:
                    self.logging.debug("E3 - UNABLE TO EXTRACT DATA - resource: %s" % self.resource)
                    print("E3 UNABLE TO EXTRACT DATA")
                    # Update the count of tables with this condition (no data found)
                    self.no_data += 1

            # if no headers have been found report this critical condition with the tag E2
            else:
                self.logging.debug(
                    " E2 Unable to find headers - resource: " + str(self.resource))
                print("E2 UNABLE TO FIND HEADERS")
                # Update the count of tables with this condition (no headers found)
                self.no_headers += 1

        # Adding statistics values and errors to the extraction errors, in order to print a final report
        self.utils.tot_tables_analyzed += self.tables_analyzed
        self.utils.headers_errors += self.no_headers
        self.utils.not_resolved_header_errors += self.headers_not_resolved
        self.utils.data_extraction_errors += self.no_data
        exoutFile6.write("#exon match mode: bothSS\n")
        exoutFile6.write("#gnId\tgnId\texId\tensemblGnId\tensemblExId\n")

        exoutFile7.write(
            "#vega exons for SpliceGraph exons, generated by do_gene_associations.py, indir: %s\n"
            % options.indir)
        exoutFile7.write("#exon match mode: singleSS\n")
        exoutFile7.write("#gnId\tgnId\texId\tensemblGnId\tensemblExId\n")

        exoutFile8.write(
            "#vega exons for SpliceGraph exons, generated by do_gene_associations.py, indir: %s\n"
            % options.indir)
        exoutFile8.write("#exon match mode: overlap\n")
        exoutFile8.write("#gnId\tgnId\texId\tensemblGnId\tensemblExId\n")

        mapper = Mapper.Mapper(verbose=1)

        sg = sg_iter.next_sg()
        while (sg):

            print >> sys.stderr, "doing %s (%i of %i)\r" % (
                sg.name, sg_iter.current_index(), sg_iter.number()),

            # ensembl, exon
            (gnIds, exIds) = mapper.map2gene(sg, 'ensembl', 'exon')
            gnInfo = {}
            maxNbEx = 0
            for k in gnIds.iterkeys():
                gnInfo[k] = mapper.getGeneInfo(k, 'ensembl', 'biotype')
                if gnIds[k] > maxNbEx:
                    maxNbEx = gnIds[k]
示例#16
0
def main():
    start_time = datetime.now()

    # Get the parameters
    parameters = get_args()
    Mapper.parameters_verification(parameters)
    kmer = range(parameters.kmer[0], parameters.kmer[1] + 1)
    reads_thr = parameters.thr
    options = list(parameters.options)
    for input_file in range(len(parameters.fastq)):
        start_time_input = datetime.now()
        if len(parameters.fasta) == 1:
            genome_file = parameters.fasta[0]
        else:
            genome_file = parameters.fasta[input_file]
        genome_name = os.path.basename(genome_file)
        genome_name = os.path.splitext(genome_name)[0]

        riboseq_file = parameters.fastq[input_file]
        riboseq_name = os.path.basename(riboseq_file)
        riboseq_name = os.path.splitext(riboseq_name)[0]
        if len(parameters.gff) == 1:
            gff_file = parameters.gff[0]
        else:
            gff_file = parameters.gff[input_file]

        with open("ORFphase_{}_log.txt".format(riboseq_name), "w") as log:
            # 1. Extraction of the non-translated sequences of CDS:
            genome_CDS = genome_name + "_phasing.nfasta"
            if os.path.exists(genome_CDS):
                print(
                    genome_CDS +
                    " exists, it will be used to extract the transcriptome. If the file doesn't result "
                    "from orfget, please rename it and launch ORFphase again".
                    format(genome_name))
            else:
                orfget_cmd = "orfget -fna {} -gff {} -features_include CDS -o {}_phasing -type nucl".format(
                    genome_file, gff_file, genome_name)
                process_orfget = subprocess.run(orfget_cmd,
                                                shell=True,
                                                universal_newlines=True,
                                                stdout=subprocess.PIPE)
                # process_orfget = subprocess.run(orfget_cmd, shell=True)
                log.write(process_orfget.stdout)

            # 2. Generation of pseudo GFF file of the CDS transcriptome
            transcriptome_gff = genome_name + "_transcriptome.gff"
            if os.path.exists(transcriptome_gff):
                print(
                    transcriptome_gff +
                    " exists, it will be used for aligning the reads, if the file does not result "
                    "from ORFphase, please rename it and relaunch ORFphase please"
                )
            else:
                transcriptome = read_multiFASTA(fasta_file=genome_CDS)
                with open(transcriptome_gff, "w") as wgff:
                    for size in transcriptome:
                        wgff.write(
                            '{:20s}\t{}\t{:20s}\t{:d}\t{:d}\t{}\t{}\t{}\t{}\n'.
                            format(size, 'SGD', 'gene', 1,
                                   len(transcriptome[size]), '.', '+', '0',
                                   str('ID=' + size)))

            # 3. Potential launch of cutadapt and definition of cutadapt files directory
            if not parameters.cutdir:
                cutdir = "."
                if len(parameters.adapt) == 1:
                    adapt = parameters.adapt[0]
                else:
                    adapt = parameters.adapt[input_file]
                print("\nThe cutadapt process will be launched")
                try:
                    print(
                        "\nNo directory for cutadapt files has been given, the cutadapt process is launching. "
                        "The reads are cut in {}-kmers".format(
                            parameters.kmer))
                    for size in kmer:
                        log.write(
                            Mapper.cut_reads(size, riboseq_file, adapt,
                                             riboseq_name))
                except ImportError:
                    print('''cutadapt seems to not be installed''')
                # with concurrent.futures.ThreadPoolExecutor(max_workers=None) as executor:
                #     for size in kmer:
                #         executor.submit(Mapper.cut_reads, size, riboseq_file, adapt, riboseq_name)

            else:
                print(
                    "\nYou entered directory(ies) for cutadapt files. No cutadapt process will be launched"
                )
                if len(parameters.cutdir) == 1:
                    cutdir = parameters.cutdir[0]
                else:
                    cutdir = parameters.cutdir[input_file]
                for size in kmer:
                    name_dir = "{}/kmer_{}".format(cutdir, size)
                    if not os.path.isdir(name_dir):
                        print(
                            "The directories need to be named as kmer_x with x the size of the kmer."
                        )
                        exit()

            # 4.Mapping of the reads on the non-translated sequences

            # a. Building of the index
            print("We start the mapping")
            if "I" in options:
                cmd_bowtie = 'bowtie-build {}_phasing.nfasta {}_phasing'.format(
                    genome_name, genome_name)
                print("Command launched: ", cmd_bowtie)
                # process_bowtie = subprocess.run(cmd_bowtie, shell=True)
                process_bowtie = subprocess.run(cmd_bowtie,
                                                shell=True,
                                                universal_newlines=True,
                                                capture_output=True)
                print(process_bowtie.stderr)
                log.write(process_bowtie.stdout)
            else:
                print(
                    "The basename of Bowtie index files are expected to be : {}_phasing"
                    .format(genome_name))

            # b->g. Create count table
            if "M" in options:
                try:
                    import pysam
                    import bokeh
                except ImportError:
                    print(
                        "You need to install the python packages pysam and bokeh"
                    )
                for size in kmer:
                    log.write(
                        Mapper.map2bam(cutdir, size, genome_name, riboseq_name,
                                       "phasing"))
            else:
                print(
                    "The name and path of the bam files are expected to be :"
                    "./kmer_n/{}_kmer_n_sorted_mapped.bam with n the size of the reads"
                    .format(riboseq_name))

            if "B" in options:
                print("Counting tables are generated")
                log.write(
                    BAM2Reads(riboseq_name, transcriptome_gff, kmer,
                              "phasing"))
            else:
                print(
                    "The name and path of the counting file is expected to be :"
                    "./kmer_n/{}_kmer_n_phasing_reads.tab with n the size of the reads"
                    .format(riboseq_name))
            # with concurrent.futures.process.ProcessPoolExecutor(max_workers=None) as executor:
            #     executor.map(map_in_bam_and_count, kmer, [gname] * len(kmer), [rname] * len(kmer), [cutdir] * len(kmer),
            #     [parameters.type]*len(kmer),[gff_to_compare]*len(kmer))
            # 5. Plotting and finding best read size to have a percentage of phase 0 superior to the threshold
            if "P" in options:
                print("The plots of phasing and periodicity are generated")
                for size in kmer:
                    tab = pd.read_table(
                        "./kmer_{}/{}_kmer_{}_phasing_reads.tab".format(
                            size, riboseq_name, size),
                        sep='\t')
                    # Plot of the reads phase and periodicity
                    print("Phasing plot for kmer {}".format(size))
                    Mapper.reads_phase_plot(tab, size, riboseq_name, reads_thr,
                                            "phasing")
                    print("Periodicity plots for kmer {}".format(size))
                    Mapper.reads_periodicity(size, riboseq_name, "phasing",
                                             "start")
                    Mapper.reads_periodicity(size, riboseq_name, "phasing",
                                             "stop")
            phase_decision_mean_median(kmer, riboseq_name, reads_thr)
            end_time_input = datetime.now()
            log.write("Duration for {} :{}".format(
                riboseq_name, end_time_input - start_time_input))
    end_time = datetime.now()
    print("\n\n")
    print('Duration: {}'.format(end_time - start_time))
示例#17
0
import mygame
from pygame.locals import *
from Player import *
import Players
import Mapper
import Obj
from sys import exit

mygame.init()
screen = mygame.screen

player = Player()
player.moveto((3, 89))
players = Players.Players(1, [player])

mp = Mapper.Mapper()
mp.load("./data/map/jungle.tmx")
mp.set_viewer(player)
Obj.Obj.mapper = mp

screen.set_mapper(mp)
screen.set_viewer(player)

default_font = "arial"
font = mygame.font.SysFont(default_font, 20)


cntClock = 0
cntFrame = 0
cntNetwork = 0
lastClock = time.clock() * 1000
示例#18
0
 def __init__(self, player):
     self.platform = Tile.Platform()
     self.player = player
     self.inCollisionDown = False
     self.plat = Mapper.get_platforms()
示例#19
0
文件: App.py 项目: w7374520/Trainning
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import Mapper
import tornado.ioloop
import tornado.web

settings = {
    'template_path': 'Views',
    'static_path': 'Statics',
    'static_url_prefix': '/statics/',
}

application = tornado.web.Application(
    [
        #(r"/index", home.IndexHandler),
    ],
    **settings)

if __name__ == "__main__":
    Mapper.static_mapper()
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
    def test_data_frame_with_invalid_csv_file(self):
        test_mapper = Mapper.Mapper('te3st_loans.csv')

        with self.assertRaises(ValueError):
            test_mapper.create_data_frame('csv')
示例#21
0
# Make sure output file has a proper value. Input file will be handled by the Parser
if outputFile == "":
    """
    Give it the same name as the logFile

    Also, remove the path (if) trailing
    the logFile by splicing from the last
    occurence from '/'
    """
    outputFile = logFile[logFile.rfind("/") + 1:-4] + ".kml"
elif outputFile[-4:] != ".kml":
    outputFile += ".kml"

print "Input :", logFile
print "Output:", outputFile

# Initialize the KML File
if widthText == "":
    KMLWriter.initKML ()
else:
    KMLWriter.initKML (widthText)

# Map the data obtained from the log file
Mapper.mapData (data)

# Write all the data to the KML file
KMLWriter.endKML (outputFile)

""" END - Script Execution """
示例#22
0
 def create_stack(cls, mongo_uri, cache_dao, google_dao):
     import .mapper import Mapper
     return cls(mongo_uri, Mapper(), 'stacks')
示例#23
0
 def create_outra_coisa(cls, mongo_uri):
     import .mapper import Mapper
     return cls(mongo_uri, Mapper(), 'outra_coisa')
示例#24
0
    def analyze_tables(self):
        """
        Method used to analyze tables structure, compose a simple data structure containing data cells and the
         corresponding headers and give it to a Mapper object.

        Principal method of a HtmlTableParser object, it finds out headers and data, refines them, and finally join
         each others in order to be mapped by a Mapper object.

        :return:nothing
        """
        # Iterates over tables list
        for html_table in self.tables:

            # Update the analyzed table count
            self.tables_analyzed += 1

            # Instantiating statistics for this table
            self.headers_found_num = 0
            self.rows_extracted_num = 0
            self.data_extracted_num = 0

            # set as a class attribute the current html table
            self.current_html_table = html_table

            # create a Table object to contain data structures and statistics for a table
            tab = Table.Table()
            # set tab.n_rows as a result of count_rows()
            tab.n_rows = self.count_rows()
            # set other table properties, such as table attributes
            tab.table_attributes = html_table.attrib
            # find out the table section using find_table_section()
            tab.table_section = self.find_table_section()

            print "Section found: ", tab.table_section
            self.logging.info("Table under section: %s" % tab.table_section)

            # find headers for this table
            self.find_headers(tab)

            # if headers have been found
            if tab.headers:
                self.logging.info("Headers Found")

                # Refine headers found
                self.refine_headers(tab)

                if self.mapping:
                    # Once the headers are refined, start to extract data cells
                    self.extract_data(tab)

                    # Refine data cells found
                    self.refine_data(tab)

                    # If data are correctly refined
                    if tab.data_refined:
                        # Count data cells and data rows using table.count_data_cells_and_rows()
                        tab.count_data_cells_and_rows()
                        self.logging.info("Rows extracted: %d" %
                                          tab.data_refined_rows)
                        self.logging.info("Data extracted for this table: %d" %
                                          tab.cells_refined)

                        # update data cells extracted in order to <make a final report
                        self.utils.data_extracted += tab.cells_refined
                        self.utils.data_extracted_to_map += tab.cells_refined
                        self.utils.rows_extracted += tab.data_refined_rows
                        # Start the mapping process
                        self.all_tables.append(tab)
                        # if i have to map table found (HtmlTableParser can be called even by pyDomainExplorer)

                        # Create a MAPPER object in order to map data extracted
                        mapper = Mapper.Mapper(self.chapter, self.graph,
                                               self.topic, self.resource,
                                               tab.data_refined, self.utils,
                                               self.reification_index,
                                               tab.table_section)
                        mapper.map()
                        # update reification index of this resource
                        self.reification_index = mapper.reification_index
                    # If no data have been found for this table report this condition with tag E3
                    else:
                        self.logging.debug(
                            "E3 - UNABLE TO EXTRACT DATA - resource: %s" %
                            self.resource)
                        print("E3 UNABLE TO EXTRACT DATA")
                        # Update the count of tables with this condition (no data found)
                        self.no_data += 1
                else:
                    self.all_tables.append(tab)
            # if no headers have been found report this critical condition with the tag E2
            else:
                self.logging.debug(" E2 Unable to find headers - resource: " +
                                   str(self.resource))
                print("E2 UNABLE TO FIND HEADERS")
                # Update the count of tables with this condition (no headers found)
                self.no_headers += 1

        print "Resource analysis completed \n\n"
        # Adding statistics values and errors to the extraction errors, in order to print a final report
        self.utils.tot_tables_analyzed += self.tables_analyzed
        self.utils.headers_errors += self.no_headers
        self.utils.not_resolved_header_errors += self.headers_not_resolved
        self.utils.data_extraction_errors += self.no_data
示例#25
0
文件: Main.py 项目: ogzhnndrms/som
    formatter.generate_validation_file()

# Train SOM, if there is no weights.
if Path("weights.txt").is_file() is False:

    # Use pandas for loading data using dataframes.
    d = os.path.dirname(os.getcwd())
    file_name = "huge_merged_csv_file.csv"
    data = pd.read_csv(file_name, header=None)
    # Shuffle the data in place.
    data = data.sample(frac=1).reset_index(drop=True)

    # create SOM object
    som = SOM(7, 1)

    # Train with 100 neurons.
    som.train(data)

    # Get output grid
    grid = som.get_centroids()

    # Save the weights in a file.
    result_file = open("weights.txt", "w")
    result_file.writelines(str(grid))
    result_file.close()

# Map data to neurons.
mapped_vectors = mapper.map_vects()
tester.open_test_file()
tester.test_som(mapped_vectors)
 def test_data_frame(self):
     dictionary = self.test_dict
     test_mapper = Mapper.Mapper(dictionary)
     generated_data_frame = test_mapper.create_data_frame('dict')
     expected_data_frame = pd.DataFrame(self.test_dict)
     assert generated_data_frame.equals(expected_data_frame)
    def test_data_frame_with_invalid_mode(self):
        dictionary = self.test_dict
        test_mapper = Mapper.Mapper(dictionary)

        with self.assertRaises(ValueError):
            test_mapper.create_data_frame('csv')
示例#28
0
                                 help='method for mapping [default: overlap]'),                               \
                     make_option('-p','--inprefix', dest='inprefix', default='SpliceGraphsFiltered_',         \
                                 help='iterate over dirs with this prefix [default: SpliceGraphsFiltered_]'), \
                     make_option('-s','--species', dest='species', default='hsa',                             \
                                 help='species [default: hsa]'),                                              \
                     ])
(options, args) = opts.parse_args()

if not os.path.isdir(options.inDir):
    print >> sys.stderr, "ERROR: input directory is not found.\n"
    opts.print_help(sys.stderr)
    sys.exit(0)

else:
    mapper = Mapper.Mapper(
        configFile='/r100/burge/xiao/Tools/splice_graphs/configuration.txt',
        verbose=1,
        species=options.species)
    #mapper  = Mapper.Mapper(verbose=1)

    inDirs = [
        d for d in os.listdir(options.inDir) if d.startswith(options.inprefix)
    ]

    for inDir in inDirs:
        chr = inDir.split(options.inprefix)[-1]
        mapper.mapAllInDir(indir="%s/%s" % (options.inDir, inDir),
                           outfile="%s/Mappings_%s_%s.txt" %
                           (options.inDir, options.type, chr),
                           type=options.type,
                           method=options.method)