예제 #1
0
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]
예제 #2
0
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]
예제 #3
0
 def _token_from_authfile(self):
     try:
         filecontents = fread(self.authfile)
         if filecontents == '':
             filecontents = '{}'
         return json.loads(filecontents)
     except FileNotFoundError:
         return {}
예제 #4
0
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
예제 #5
0
파일: cons.py 프로젝트: mroll/rosalind
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
예제 #6
0
파일: eight.py 프로젝트: rarch/projecteuler
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+'\')'
예제 #7
0
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")
예제 #8
0
def main():
    data=fread("./data/ocr.txt")

    print "".join(findall("[A-Za-z]", data))
예제 #9
0
 def load(self):
     try:
         return json.loads(util.fread(self.dbfile, "r"))
     except:
         return {}
예제 #10
0
파일: pmch.py 프로젝트: mroll/rosalind
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)
예제 #11
0
파일: sseq.py 프로젝트: mroll/rosalind
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)))
예제 #12
0
파일: kmp.py 프로젝트: mroll/rosalind
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)))
예제 #13
0
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)
예제 #14
0
파일: splc.py 프로젝트: mroll/rosalind
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)
예제 #15
0
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)
예제 #16
0
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))
예제 #17
0
def main():
    data=fread("./data/equality.txt")

    print "".join(findall("[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]+", data))
예제 #18
0
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]))