def _create_row_position(self, map_position, collapsed_view):
     
     if collapsed_view:
         new_map_position = FeaturesFactory.get_empty_feature(self.get_enricher_type())
         new_map_position.set_mapping_result(map_position)
         new_map_position.set_empty(False)
         
     else:
         feature_mapping = FeaturesFactory.get_empty_feature(self.get_enricher_type())
         
         new_map_position = map_position.clone()
         new_map_position.set_feature(feature_mapping)
     
     return new_map_position
Exemple #2
0
 def retrieve_datasets_by_pos(self, map_intervals, dataset_list, map_config, chrom_dict,
                              multiple_param, map_sort_by, feature_type = DatasetsConfig.DATASET_TYPE_GENETIC_MARKER):
     features = []
     
     map_id = map_config.get_id()
     
     # Look for markers for each dataset
     for dataset in dataset_list:
         
         sys.stderr.write("\t dataset: "+dataset+"\n")
         
         # Check if map and dataset do share databases
         dataset_config = self._datasets_config.get_dataset_config(dataset)
         if not self.common_dbs(dataset_config, map_config):
             continue
         
         dataset_type = dataset_config.get_dataset_type()
         dataset_name = dataset_config.get_dataset_name()#datasets_dict[dataset]["dataset_name"]
         
         ####### If dataset type is the type requested, pass, else (dataset type does not match the one requested) continue
         ###### Note that MAP type is a subtype of ANCHORED and therefore MAP types are accepted with ANCHORED filtering
         if dataset_type == feature_type or (dataset_type == DatasetsConfig.DATASET_TYPE_MAP and feature_type == DatasetsConfig.DATASET_TYPE_ANCHORED):
             pass
         else:
             continue
         
         if self._verbose: sys.stderr.write("\t dataset: "+dataset+"\n")
         
         ########## Retrieve markers within intervals
         ##########
         dataset_map_path = self.get_dataset_path(dataset, map_id, dataset_type)
         
         sys.stderr.write("\t\t path: "+dataset_map_path+"\n")
         
         if os.path.exists(dataset_map_path) and os.path.isfile(dataset_map_path):
             if self._verbose: sys.stderr.write("DatasetsRetriever: loading features from map data: "+dataset_map_path+"\n")
             
             mappings_parser = MappingsParser()
             mapping_results_list = mappings_parser.parse_mapping_file_by_pos(map_intervals, dataset_map_path, chrom_dict, map_config, map_sort_by)
             
             for mapping_result in mapping_results_list:
                 marker_id = mapping_result.get_marker_id()
                 
                 feature_mapping = FeaturesFactory.get_feature(marker_id, dataset, dataset_name, feature_type, mapping_result)
                 features.append(feature_mapping)
             
             #features.extend(dataset_features)
     
     return features
Exemple #3
0
    def parse_mapping_file_on_pos(self, map_intervals, data_path, chrom_dict,
                                  map_config, map_sort_by, dataset,
                                  dataset_name, feature_type):

        map_name = map_config.get_name()
        map_is_physical = map_config.as_physical()
        map_has_cm_pos = map_config.has_cm_pos()
        map_has_bp_pos = map_config.has_bp_pos()

        current_interval_pos = 0
        featured_current_interval = map_intervals[current_interval_pos]
        current_interval = featured_current_interval.get_map_interval()
        current_features = featured_current_interval.get_features()

        #sys.stderr.write("MappingsParser \n")
        #sys.stderr.write("\t"+str(current_interval)+"\n")
        #sys.stderr.write("\t"+str(len(current_features))+"\n")
        #for feature in current_features:
        #    sys.stderr.write("\t\t"+str(feature)+"\n")

        # Find all the hits for this map
        for hit in open(data_path, 'r'):
            if hit.startswith(">") or hit.startswith("#"): continue
            hit_data = hit.strip().split("\t")

            #sys.stderr.write(hit+"\n")
            #sys.stderr.write("\t"+str(current_interval)+"\n")

            mapping_result = MappingResult.init_from_data(
                hit_data, map_name, chrom_dict, map_is_physical,
                map_has_cm_pos, map_has_bp_pos)

            chrom_name = mapping_result.get_chrom_name()

            if chrom_name != current_interval.get_chrom(): continue

            map_end_pos = mapping_result.get_sort_end_pos(map_sort_by)

            if float(map_end_pos) < float(current_interval.get_ini_pos()):
                continue

            marker_id = mapping_result.get_marker_id()
            chrom_order = mapping_result.get_chrom_order()
            map_pos = mapping_result.get_sort_pos(
                map_sort_by)  #float(mapping_result.get_sort_pos(map_sort_by))

            dataset_interval = MapInterval(chrom_name, map_pos, map_end_pos)

            does_overlap = MapInterval.intervals_overlap(
                dataset_interval, current_interval)
            # This if-else could be unnecessary, but hopefully is useful to read the code
            if does_overlap:
                next_interval_pos = current_interval_pos
                next_interval = current_interval
                next_features = current_features
                while (does_overlap):
                    feature = FeaturesFactory.get_feature(
                        marker_id, dataset, dataset_name, feature_type,
                        mapping_result)
                    next_features.append(feature)

                    next_interval_pos += 1
                    if next_interval_pos >= len(map_intervals):
                        break
                    featured_next_interval = map_intervals[next_interval_pos]
                    next_interval = featured_next_interval.get_map_interval()
                    next_features = featured_next_interval.get_features()

                    does_overlap = MapInterval.intervals_overlap(
                        dataset_interval, next_interval)

            else:
                while (float(map_pos) > float(current_interval.get_end_pos())):
                    current_interval_pos += 1
                    if current_interval_pos >= len(map_intervals):
                        break
                    featured_current_interval = map_intervals[
                        current_interval_pos]
                    current_interval = featured_current_interval.get_map_interval(
                    )
                    current_features = featured_current_interval.get_features()

        #sys.stderr.write("MappingsParser generated intervals\n")
        #for featured_map_interval in map_intervals:
        #    map_interval = featured_map_interval.get_map_interval()
        #    sys.stderr.write("\tinterval: "+str(map_interval)+"\n")
        #    features = featured_map_interval.get_features()
        #    for feature in features:
        #        sys.stderr.write("\t\tfeature: "+str(feature)+"\n")

        return map_intervals