def main(): lines = fread(data_dir + "fifties.txt") parsed = [line.strip() for line in lines.split("\n")] S = add(parsed) # is str print str(S)[0:10]
def main_alt(): lines = fread(data_dir + "fifties.txt") # Simple solution taking advantage of python parsed = [int(line.strip()) for line in lines.split("\n")] S = sum(parsed) # is int print str(S)[0:10]
def _token_from_authfile(self): try: filecontents = fread(self.authfile) if filecontents == '': filecontents = '{}' return json.loads(filecontents) except FileNotFoundError: return {}
def main(): data=fread(data_dir+"grid.txt") parsed = [map(int,line.split(' ')) for line in data.split('\n')] # lengths=(list(set(map(len,parsed)))) # if len(lengths)==1: # one length # horiz=lengths[0] # vert = len(parsed) dim,multiplicands=len(parsed),4 maxprod,maxfactors=0,[] # horizontal products for row in xrange(0,dim): for col in xrange(0,dim-(multiplicands-1)): cand,factors=1,[] for i in xrange(col,col+multiplicands): cand=cand*parsed[row][i] factors=factors+[parsed[row][i]] if cand>maxprod: maxprod,maxfactors=cand,factors # vertical products for col in xrange(0,dim): for row in xrange(0,dim-(multiplicands-1)): cand,factors=1,[] for i in xrange(row,row+multiplicands): cand=cand*parsed[i][col] factors=factors+[parsed[i][col]] if cand>maxprod: maxprod,maxfactors=cand,factors # right descending products for row in xrange(0,dim-(multiplicands-1)): for col in xrange(0,dim-(multiplicands-1)): cand,factors=1,[] for i in xrange(0,multiplicands): cand=cand*parsed[row+i][col+i] factors=factors+[parsed[row+i][col+i]] if cand>maxprod: maxprod,maxfactors=cand,factors # right ascending products for row in xrange((multiplicands-1),dim): for col in xrange(0,dim-(multiplicands-1)): cand,factors=1,[] for i in xrange(0,multiplicands): cand=cand*parsed[row-i][col+i] factors=factors+[parsed[row-i][col+i]] if cand>maxprod: maxprod,maxfactors=cand,factors print maxprod#, maxfactors
def cons(fname): fs = util.parseFasta(util.fread(fname)) M = map(lambda x: x.seq, fs) columns = map(lambda c: map(str, c), cols(M)) ncols = len(columns) freqs = {c: zeros(ncols) for c in "ACGT"} for i in range(ncols): for c in columns[i]: freqs[c][i] += 1 return freqs
def main(): data=fread(data_dir+"largenumber.txt") mNum=''.join(line.strip() for line in data) i,length=0,5 mMax,mStr=0,'' for i in xrange(0,len(mNum)-length+1): product=reduce(lambda x,y:int(x)*int(y),mNum[i:i+length],1) if product>mMax: mMax,mStr=product,mNum[i:i+length] print mMax#,'(\''+mStr+'\')'
async def camera_request(state, payload): tmp = temperature.get(state["cfg"]["philipshue"]) if "src" in payload and "dst" in payload: imagefile, objects, ts, snapshots = state["monitor"].get_latest( payload["snapshot"]) if imagefile == "": await camera_request_send(state, payload["src"], payload["dst"], "", 0, 0, 1, snapshots, tmp, "No snapshot found: %s bytes") return ib = util.fread(imagefile, "rb") encoded = base64.b64encode(ib).decode('ascii') await camera_request_send(state, payload["src"], payload["dst"], encoded, objects, ts, 0, snapshots, tmp, "Snapshot sent: %s bytes")
def main(): data=fread("./data/ocr.txt") print "".join(findall("[A-Za-z]", data))
def load(self): try: return json.loads(util.fread(self.dbfile, "r")) except: return {}
import math from util import parseFasta, fread, fact def pmch(S): As = S.count("A") Cs = S.count("C") return fact(As) * fact(Cs) fastas = parseFasta(fread("pmch.in")) S = fastas[0].seq print pmch(S)
from util import parseFasta, fread def sseq(s, t): """ Return a collection of indices into s where symbols of t appear as a subsequence. """ res = [] curr_t = 0 for i in range(len(s)): if s[i] == t[curr_t]: res.append(i + 1) curr_t += 1 if curr_t == len(t): break return res fastas = parseFasta(fread("sseq.in")) s = fastas[0].seq t = fastas[1].seq print " ".join(map(str, sseq(s, t)))
from util import parseFasta, fread, kmp_prefix_fn fastas = parseFasta(fread('kmp.in')) s = fastas[0].seq print " ".join(map(str, kmp_prefix_fn(s)))
def get_config(): filename = "config/skypeernet.cfg" if (len(sys.argv) == 2): filename = sys.argv[1] c = util.fread(filename, "r") return json.loads(c)
from util import transcribe, DNACodonTable, parseFasta, fread import re def splc(S, introns): return transcribe(re.sub(r"|".join(introns), "", S), DNACodonTable) fastas = parseFasta(fread("splc.in")) S = fastas[0].seq introns = map(lambda f: f.seq, fastas[1:]) print splc(S, introns)
from util import parseFasta, fread, transition_p, hamming_errors def tran(s, t): n = len(s) errs = hamming_errors(s, t) ntrans = sum([1 for i in range(len(errs)) if transition_p(errs[i])]) return float(ntrans) / (len(errs) - ntrans) fastas = parseFasta(fread("tran.in")) s = fastas[0].seq t = fastas[1].seq print tran(s, t)
from util import parseFasta, fread, reverse_comp def reverse_pal(S): return S == reverse_comp(S) def revp(S): n = len(S) minlen = 4 maxlen = 12 res = [] for length in range(minlen, maxlen+1): for start in range(n-length+1): if reverse_pal(S[start:start+length]): res.append([start+1, length]) return res S = parseFasta(fread("revp.in"))[0].seq for x in revp(S): print " ".join(map(str, x))
def main(): data=fread("./data/equality.txt") print "".join(findall("[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]+", data))
import re from util import outer_product, parseFasta, fread, occurrences, kmers fastas = parseFasta(fread('kmer.in')) S = fastas[0].seq A = kmers(['A', 'C', 'T', 'G'], [0, 4]) for x in [occurrences(S, kmer) for kmer in A]: print x # print ' '.join(map(str, [occurrences(S, kmer) for kmer in A]))