예제 #1
0
    def __init__(self, FeatureObject):
        """ initializes chromosome, strand, and Ids from FeatureObject so we don't have to call these every time"""
        self.features = []
        self.exons = RangeFinder()
        self.chr = FeatureObject.chr
        self.strand = FeatureObject.strand
        self.tId = FeatureObject.tId
        self.gId = FeatureObject.gId

        self.features.append(FeatureObject)
예제 #2
0
    def __init__(self, omap_path, sparki):
        self.omap = ObstacleMap(omap_path)
        self.ogrid = OccupancyGrid()

        FrontEnd.__init__(self, self.omap.width, self.omap.height)

        self.sparki = sparki
        self.robot = Robot()
        self.rfinder = RangeFinder(self.ogrid, self.robot)

        # center robot
        self.robot.x = self.omap.width * 0.5
        self.robot.y = self.omap.height * 0.5
    def __init__(self, FeatureObject):
        """ initializes chromosome, strand, and Ids from FeatureObject so we don't have to call these every time"""
        self.features=[]
        self.exons = RangeFinder()
        self.chr = FeatureObject.chr
        self.strand = FeatureObject.strand
        self.tId = FeatureObject.tId
        self.gId = FeatureObject.gId

        self.features.append(FeatureObject)
예제 #4
0
 def __init__(self, Transcript, isEmpty=False):
     """ initializes chromosome, strand, and Ids from transcript so we don't have to call these every time"""
     if isEmpty:
         self.gId = "emptyGene"
         return None
     self.features = []
     self.exons = RangeFinder()
     self.cdsExons = RangeFinder()
     self.chr = Transcript.chr
     self.strand = Transcript.strand
     self.descDict = Transcript.descDict
     self.gId = self.descDict["gene_id"][0]
     self.tId = self.descDict["transcript_id"][0]
     self.geneType = self.descDict["gene_type"][0]
     self.geneStatus = self.descDict["gene_status"][0]
     self.geneSymbol = self.descDict["gene_name"][0]
     self.transcriptType = self.descDict["transcript_type"][0]
     self.transcriptStatus = self.descDict["transcript_status"][0]
     self.transcriptSymbol = self.descDict["transcript_name"][0]
     self.havanaGene = Transcript.havanaGene
     self.havanaTranscript = Transcript.havanaTranscript
     self.gId = Transcript.gId
     self.features.append(Transcript)
예제 #5
0
 def __init__(self, FeatureObject):
     """ initializes chromosome, strand, and Ids from FeatureObject so we don't have to call these every time"""
     self.features = []
     self.exons = RangeFinder()
     self.cdsExons = RangeFinder()
     self.chr = FeatureObject.chr
     self.strand = FeatureObject.strand
     self.descDict = FeatureObject.descDict
     self.gId = self.descDict["gene_id"][0]
     self.tId = self.descDict["transcript_id"][0]
     self.geneType = self.descDict["gene_type"][0]
     self.geneStatus = self.descDict["gene_status"][0]
     self.geneSymbol = self.descDict["gene_name"][0]
     self.transcriptType = self.descDict["transcript_type"][0]
     self.transcriptStatus = self.descDict["transcript_status"][0]
     self.transcriptSymbol = self.descDict["transcript_name"][0]
     self.havanaGene = FeatureObject.havanaGene
     self.havanaTranscript = FeatureObject.havanaTranscript
     self.tId = FeatureObject.tId
     self.gId = FeatureObject.gId
     self.features.append(FeatureObject)
     self.hasStartCodon = True  # unless defined otherwise
     self.hasStopCodon = True
     self.firstFrame = None
예제 #6
0
    def update(self,time_delta):
        T_sonar_map = self.robot.get_robot_map_transform()*self.robot.get_sonar_robot_transform()
        
        # Get sonar x and y for center point of sonar in map frame. 
        #print(T_sonar_map)
        #print(T_sonar_map.item(2))
        #print(T_sonar_map.item(5))
        x = T_sonar_map.item(2)
        y = T_sonar_map.item(5)

        if self.sparki.port == '':
            # calculate sonar distance from map
            self.robot.sonar_distance = self.omap.get_first_hit(T_sonar_map)
            
            # Send range finder measurement to RangeFinder class
            #print(self.robot.sonar_distance)
            #print(self.omap.log_odds)
            rangefinder = RangeFinder(self.robot.sonar_distance, self.omap.log_odds, x, y)
            log_odds = rangefinder.update(self.robot.sonar_distance, self.omap.log_odds, x, y)
            self.omap.log_odds = log_odds
            
	else:
            # get current rangefinder reading
            self.robot.sonar_distance = self.sparki.dist
        
        # calculate servo setting
        servo = int(self.robot.sonar_angle*180./math.pi)

        # calculate motor settings
        left_speed, left_dir, right_speed, right_dir = self.robot.compute_motors()

        # send command
        self.sparki.send_command(left_speed,left_dir,right_speed,right_dir,servo)
        
        # update robot position
        self.robot.update(time_delta)
class Gene(object):
    def __init__(self, FeatureObject):
        """ initializes chromosome, strand, and Ids from FeatureObject so we don't have to call these every time"""
        self.features=[]
        self.exons = RangeFinder()
        self.chr = FeatureObject.chr
        self.strand = FeatureObject.strand
        self.tId = FeatureObject.tId
        self.gId = FeatureObject.gId

        self.features.append(FeatureObject)
    def add(self, FeatureObject):
        """adds FeatureObject to Gene object"""
        self.features.append(FeatureObject)
    def makeExons(self):
        """ take features list and create a list of exonstarts and stops. This means merging utr and exon features"""
        self.exonStarts = []
        self.exonEnds= []
        keepStart =''
        keepStop = 0
        for f in self.features:
            if (f.start - 1 > keepStop):         # if it is a new exon
                if(keepStop > 0):
                    self.exonStarts.append(keepStart)
                    self.exonEnds.append(keepStop)
                keepStart = f.start
                    
            keepStop = f.stop
        # now add the last
        self.exonStarts.append(keepStart)
        self.exonEnds.append(keepStop)
    def addExons(self):           # addExons can not be part of add, since the exons must first be created in makeExons under the Gene class
        """ add exons to Gene object """
        for i in xrange(len(self.exonStarts)):
            self.exons.add(self.chr, self.exonStarts[i], self.exonEnds[i], self, self.strand)
    def isIdentical(self, otherGene):
        """ this should only be used after getTranscripts, because it assumes chromosome and strand are identical """
        if not (len(self.features) == len (otherGene.features)):
            return False
        for f in xrange(len(self.features)):
            if not (self.features[f].descriptor == otherGene.features[f].descriptor and self.features[f].start == otherGene.features[f].start and self.features[f].stop == otherGene.features[f].stop):
                return False
        return True    # if the number of exons is the same and the features are all the same
    def justCDS(self):
        """ tests if the gene has UTR features. Returns False if it does"""
        for f in self.features:
            if (f.descriptor == "5UTR" or f.descriptor == "3UTR"):
                return False
        return True
    def cdsIdentical(self, otherGene):
        selfFeatures = []
        otherFeatures = []
        for f in self.features:
            if f.descriptor == "CDS":
                selfFeatures.append(f)
        for f in otherGene.features:
            if f.descriptor == "CDS":
                otherFeatures.append(f)
        # now compare
        if not (len(selfFeatures) == len (otherFeatures)):
            return False
        for f in xrange(len(selfFeatures)):
            if not (selfFeatures[f].descriptor == otherFeatures[f].descriptor and selfFeatures[f].start == otherFeatures[f].start and selfFeatures[f].stop == otherFeatures[f].stop):
                return False
        return True    # if the number of exons is the same and the features are all the same
예제 #8
0
class Gene(object):
    def __init__(self, FeatureObject):
        """ initializes chromosome, strand, and Ids from FeatureObject so we don't have to call these every time"""
        self.features = []
        self.exons = RangeFinder()
        self.chr = FeatureObject.chr
        self.strand = FeatureObject.strand
        self.tId = FeatureObject.tId
        self.gId = FeatureObject.gId

        self.features.append(FeatureObject)

    def add(self, FeatureObject):
        """adds FeatureObject to Gene object"""
        self.features.append(FeatureObject)

    def makeExons(self):
        """ take features list and create a list of exonstarts and stops. This means merging utr and exon features"""
        self.exonStarts = []
        self.exonEnds = []
        keepStart = ''
        keepStop = 0
        for f in self.features:
            if (f.start - 1 > keepStop):  # if it is a new exon
                if (keepStop > 0):
                    self.exonStarts.append(keepStart)
                    self.exonEnds.append(keepStop)
                keepStart = f.start

            keepStop = f.stop
        # now add the last
        self.exonStarts.append(keepStart)
        self.exonEnds.append(keepStop)

    def addExons(
        self
    ):  # addExons can not be part of add, since the exons must first be created in makeExons under the Gene class
        """ add exons to Gene object """
        for i in xrange(len(self.exonStarts)):
            self.exons.add(self.chr, self.exonStarts[i], self.exonEnds[i],
                           self, self.strand)

    def isIdentical(self, otherGene):
        """ this should only be used after getTranscripts, because it assumes chromosome and strand are identical """
        if not (len(self.features) == len(otherGene.features)):
            return False
        for f in xrange(len(self.features)):
            if not (self.features[f].descriptor
                    == otherGene.features[f].descriptor
                    and self.features[f].start == otherGene.features[f].start
                    and self.features[f].stop == otherGene.features[f].stop):
                return False
        return True  # if the number of exons is the same and the features are all the same

    def justCDS(self):
        """ tests if the gene has UTR features. Returns False if it does"""
        for f in self.features:
            if (f.descriptor == "5UTR" or f.descriptor == "3UTR"):
                return False
        return True

    def cdsIdentical(self, otherGene):
        selfFeatures = []
        otherFeatures = []
        for f in self.features:
            if f.descriptor == "CDS":
                selfFeatures.append(f)
        for f in otherGene.features:
            if f.descriptor == "CDS":
                otherFeatures.append(f)
        # now compare
        if not (len(selfFeatures) == len(otherFeatures)):
            return False
        for f in xrange(len(selfFeatures)):
            if not (selfFeatures[f].descriptor == otherFeatures[f].descriptor
                    and selfFeatures[f].start == otherFeatures[f].start
                    and selfFeatures[f].stop == otherFeatures[f].stop):
                return False
        return True  # if the number of exons is the same and the features are all the same
예제 #9
0
def main():
  x = (display_width*0.45)
  y = (display_height*0.6)
  angle = 0
  rangeFinderLength = 70
  car = Car((newCarX, newCarY), newCarAngle)
  env = CarMazeEnv()
  rangefinderSensors = []
  for el in range(sensorCount):
    rangefinderSensors.append(RangeFinder(car, rangeFinderLength, angleOffset+el*angle_between))
  angle_change = 0
  
  game_ext = False
  #env = CarMazeEnv()
  RUNNING, PAUSE = 0, 1 
  state = RUNNING
  action = 0.5
  while not game_ext:
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
        game_ext = True
        #env.close()
      if event.type == pygame.KEYDOWN:
        if event.key == pygame.K_p and state == RUNNING: state = PAUSE
        elif event.key == pygame.K_p and state == PAUSE: state = RUNNING
          
        if event.key == pygame.K_LEFT:
          #angle_change = 2
          action = 0
          #angle_change = -(action*4-2)
        if event.key == pygame.K_RIGHT:
          #angle_change = -2
          action = 1
          #angle_change = -(action*4-2)
        
      if event.type == pygame.KEYUP:
        if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
          angle_change = 0
          action = 0.5
          angle_change = -(action*4-2)
      
#    game_display.fill(white)
    if state == RUNNING:
      env.step(action)
#      angle_change = -(action*4-2)
#      car.updateMovability(walls)
#      car.update(angle_change)
      #env.step(action)
      #print(env.measurements)
#      intensities = []
#      for rangefinder in rangefinderSensors:
#        rangefinder.update()
#        intensities.append(rangefinder.sense(walls))
#      print(intensities)
      
#    env.cars = [car]
#    env.rangeFinders = rangefinderSensors
#    env.measurements = intensities
#    env.clock = clock
    
#    game_display.fill(white)
#    draw_walls(walls)
#    draw_car(car)    
#    pygame.draw.circle(game_display, redcolor, tuple(int(x) for x in car.pos), car.RADIUS, 2)
#    draw_sensors(rangefinderSensors, intensities)
#    
#    pygame.display.flip()
#    clock.tick(30)
    env.render()
예제 #10
0
import subprocess

command1 = 'rm build/lib.linux-armv7l-2.7/RangeFinder_C.so'
command2 = 'python setup.py build'
command3 = 'cp build/lib.linux-armv7l-2.7/RangeFinder_C.so RangeFinder_C.so'
subprocess.call(command1, shell=True)
subprocess.call(command2, shell=True)
subprocess.call(command3, shell=True)
print ""

from RangeFinder import RangeFinder

x = RangeFinder()
for i in range(800):
    dist1 = x.getDistance(1)  #get distance from sensor 1
    dist2 = x.getDistance(2)  #get distance from sensor 2
    dist3 = x.getDistance(3)
    dist4 = x.getDistance(4)
    print 'd1: ', dist1, ' d2: ', dist2, ' d3: ', dist3, ' d4: ', dist4
예제 #11
0
class MyFrontEnd(FrontEnd):
    def __init__(self, omap_path, sparki):
        self.omap = ObstacleMap(omap_path)
        self.ogrid = OccupancyGrid()

        FrontEnd.__init__(self, self.omap.width, self.omap.height)

        self.sparki = sparki
        self.robot = Robot()
        self.rfinder = RangeFinder(self.ogrid, self.robot)

        # center robot
        self.robot.x = self.omap.width * 0.5
        self.robot.y = self.omap.height * 0.5

    def keydown(self, key):
        # update velocities based on key pressed
        if key == pygame.K_UP:  # set positive linear velocity
            self.robot.lin_vel = 20.0
        elif key == pygame.K_DOWN:  # set negative linear velocity
            self.robot.lin_vel = -20.0
        elif key == pygame.K_LEFT:  # set positive angular velocity
            self.robot.ang_vel = 100. * math.pi / 180.
        elif key == pygame.K_RIGHT:  # set negative angular velocity
            self.robot.ang_vel = -100. * math.pi / 180.
        elif key == pygame.K_k:  # set positive servo angle
            self.robot.sonar_angle = 45. * math.pi / 180.
        elif key == pygame.K_l:  # set negative servo angle
            self.robot.sonar_angle = -45. * math.pi / 180.

    def keyup(self, key):
        # update velocities based on key released
        if key == pygame.K_UP or key == pygame.K_DOWN:  # set zero linear velocity
            self.robot.lin_vel = 0
        elif key == pygame.K_LEFT or key == pygame.K_RIGHT:  # set zero angular velocity
            self.robot.ang_vel = 0
        elif key == pygame.K_k or key == pygame.K_l:  # set zero servo angle
            self.robot.sonar_angle = 0

    def draw(self, surface):
        # draw occupancy grid
        self.ogrid.draw(surface)

        # draw robot
        self.robot.draw(surface)

    def update(self, time_delta):
        T_sonar_map = self.robot.get_robot_map_transform(
        ) * self.robot.get_sonar_robot_transform()
        if self.sparki.port == '':
            # calculate sonar distance from map
            self.robot.sonar_distance = self.omap.get_first_hit(T_sonar_map)
        else:
            # get current rangefinder reading
            self.robot.sonar_distance = self.sparki.dist

        # send rangefinde data to RangeFinder class
        self.rfinder.inverse_sensor_model(self.robot.sonar_distance)

        # update the occupancy grid
        self.ogrid.cell_prob_occupancy()

        # calculate servo setting
        servo = int(self.robot.sonar_angle * 180. / math.pi)

        # calculate motor settings
        left_speed, left_dir, right_speed, right_dir = self.robot.compute_motors(
        )

        # send command
        self.sparki.send_command(left_speed, left_dir, right_speed, right_dir,
                                 servo)

        # update robot position
        self.robot.update(time_delta)