def send_data(self, odrid): try: odr = self.__getodr(odrid) fname = odr.filename odr.close() rconn = pyRserve.rconnect() rconn.r.source("/home/avik/Desktop/yourMatch.R") resp = rconn.r.classifyThis(fname) respreader = csv.reader(open(fname + ".out.csv", 'rb')) resp = {} first = True for row in respreader: if first: first = False continue resp[row[1]] = row[0] self.wfile.write(json.dumps(resp)) del self.opendatarecords[odrid] except IOError: self.send_error(500, 'Unable to send/receive data to Rserve')
from Bio import SeqIO from Bio.Alphabet import generic_dna import subprocess import pyRserve fn = sys.argv[1] times = 1 if len(sys.argv) > 2: times = int(sys.argv[2]) # Start the RServer subprocess.Popen([r"R", "CMD", "Rserve"], stdout=subprocess.PIPE).wait() time.sleep(0.5) conn = pyRserve.rconnect() conn("library(GeneR)") if verbose: print >> sys.stderr, "Biopython translate ", fn, ":", times for i in range(0, times): if verbose: print >> sys.stderr, i + 1 for seq_record in SeqIO.parse(fn, "fasta", generic_dna): print ">", seq_record.id ntseq = str(seq_record.seq) print conn('strTranslate("' + ntseq + '")') # Kill the RServer subprocess.Popen([r"killall", "Rserve"], stdout=subprocess.PIPE)