Exemplo n.º 1
0
    def __init__(self, config):
        self._access_token = config.get('twitter','access_token')
        self._access_token_secret = config.get('twitter','access_token_secret')
        self._consumer_key = config.get('twitter','consumer_key')
        self._consumer_secret = config.get('twitter','consumer_secret')

        # Retrieve terms to track
        track_file = open(config.get('track','file'), 'r')
        self._track_terms = [line.rstrip('\n').rstrip('\r') for line in track_file]
        self._start_index = int(config.get('track','offset'))

        # Store tweets temporarily and dump them to file at an interval
        self._tweets_to_insert = []

        # Initialize Kafka or File Writer
        if config.get('output','type') == 'kafka':
          self._writer = kafka.KafkaConnection(brokers=config.get('output','kafka_brokers'),
                                              topic=config.get('output','kafka_topic'))
        else:
          data_dir = 'data/'+datetime.datetime.now().strftime('%Y-%m-%d')+'-'
          self._writer = filewriter.FileWriter(filename=data_dir+config.get('output','filename'))

        #This handles Twitter authetification and the connection to Twitter
        self._auth = tweepy.OAuthHandler(self._consumer_key, self._consumer_secret)
        self._auth.set_access_token(self._access_token, self._access_token_secret,)
        self._connect()

        # Initialize twitter statistics
        self._twitter_stats = {'tweets':0}
        
        self._max_tweet_id = {}
        
        self._twitter_streams = []
def handle_output(puid_type, puid_str, file_no, int_sig_no):

    sigID = 0
    for x in content_list:
        if x[0] == 'Internal Signature ID':
            fr = filewriter.FileWriter(puid_type)  #create file writing object
            if x[1] != sigID:
                sigID = x[1]
                if content_list[1][0] == 'File Extension':
                    ext = content_list[1][1]
                else:
                    ext = 'nul'
                #New internal sig, new file - create
                fr.write_file(puid_type, file_no, sigID, puid_str, ext)
        if x[0] == 'Byte sequence':
            if x[1][0] == 'Absolute from BOF':
                fr.write_header(x[1][0], x[1][1], x[1][2], x[1][3])
            if x[1][0] == 'Absolute from EOF':
                fr.write_footer(x[1][0], x[1][1], x[1][2], x[1][3])
            if x[1][0] == 'Variable':
                fr.write_var(x[1][0], x[1][1], x[1][2], x[1][3])
Exemplo n.º 3
0
def handle_output(puid_type, puid_str, file_no, int_sig_no):

    sigID = 0
    for x in content_list:
        if x[0] == 'Internal Signature ID':
            fr = filewriter.FileWriter(puid_type)  #create file writing object
            if x[1] != sigID:
                sigID = x[1]
                if content_list[1][0] == 'File Extension':
                    ext = content_list[1][1]
                else:
                    ext = 'nul'
                #New internal sig, new file - create
                fr.write_file(puid_type, file_no, sigID, puid_str, ext)
        if x[0] == 'Byte sequence':

            pos = x[1][0]
            min = x[1][1]
            max = x[1][2]
            seq = x[1][3]

            if min == 'null':
                min = 0

            if max == 'null':
                max = 0

            min = int(min)
            max = int(max)

            if pos == 'Absolute from BOF':
                fr.write_header(pos, min, max, seq)
            if pos == 'Absolute from EOF':
                fr.write_footer(pos, min, max, seq)
            if pos == 'Variable':
                if min > 0:
                    print puid_str + " " + str(min)

                fr.write_var(pos, min, max, seq)
Exemplo n.º 4
0
    maxAverageDiameterThreshold = args.maxAverageDiameterThreshold

    # call samplegenerator which calls RNAxplorer (in matrix2d objects) and executes a clustering (2D or DIANA, etc.) only to select
    # new structure representatives for samplegeneration.
    structures = samplegenerator.mainloop(twoDSamplingParameters)

    # call final clusteralg.
    clusters = DIANA.doClustering(structures, maxDiameterThreshold,
                                  maxAverageDiameterThreshold)
    DIANA.printClusters(clusters)
    representatives = selectRepresentatives(seq, clusters)

    # prepare representatives and sort them, to make the comparison of the output easier.
    repsAndEnergies = [(x, RNA.energy_of_struct(seq, x))
                       for x in representatives]
    repsAndEnergies.sort(key=operator.itemgetter(1, 0))

    # rate computation.
    rateMatrix = Rates.arrheniusRates(seq, repsAndEnergies)

    # write files for treekin (matrix and structures)
    fw = filewriter.FileWriter()
    fw.writeMatrixToFile(rateMatrix, param.RatesFilePath)
    fw.writeRepresentativesToFile(seq, repsAndEnergies,
                                  param.StructuresFilePath)

    # run treekin
    to_call = "cat " + param.StructuresFilePath + " | treekin --p0 " + str(param.StartStructureID) + "=1 --ratesfile " + param.RatesFilePath + " --t0 " + \
            str(param.StartTime) + " --t8 " + str(param.EndTime) + " -m I > " + param.KineticFile
    os.system(to_call)