Esempio n. 1
0
Entrez.email = "*****@*****.**"

if __name__ == "__main__":
    with open('rosalind_need.txt') as dataset:
        ids = dataset.read().split()

    handle = Entrez.efetch(db='nucleotide', id=ids, rettype="fasta")
    records = list(SeqIO.parse(handle, 'fasta'))

    for i, r in enumerate(records):
        with open(ids[i], 'w') as f:
            SeqIO.write(r, f, 'fasta')

    needle_cline = NeedleCommandline()
    needle_cline.asequence = ids[0]
    needle_cline.bsequence = ids[1]
    needle_cline.outfile = "rosalind_need_output.txt"
    needle_cline.gapopen = 10
    needle_cline.gapextend = 1
    needle_cline.endopen = 10
    needle_cline.endextend = 1
    needle_cline.endweight = True
    needle_cline()

    with open('rosalind_need_output.txt') as f:
        output = f.readlines()

    for line in output:
        if 'Score:' in line:
            print(int(float(line[:-1].split(':')[-1].strip())))
Esempio n. 2
0
if __name__ == "__main__":
    with open(os.path.join('data', 'rosalind_need.txt')) as dataset:
        ids = dataset.read().split()

    handle = Entrez.efetch(db='nucleotide', id=ids, rettype="fasta")
    records = list(SeqIO.parse(handle, 'fasta'))

    for i, r in enumerate(records):
        with open(ids[i], 'w') as f:
            SeqIO.write(r, f, 'fasta')

    needle_cline = NeedleCommandline()
    needle_cline.asequence = ids[0]
    needle_cline.bsequence = ids[1]
    needle_cline.outfile = "need.txt"
    needle_cline.gapopen = 11
    needle_cline.gapextend = 1
    needle_cline.endopen = 11
    needle_cline.endextend = 1
    needle_cline.endweight = True

    needle_cline()

    with open('need.txt') as f:
        output = f.readlines()

    for line in output:
        if 'Score:' in line:
            print(int(float(line[:-1].split(':')[-1].strip())))
Esempio n. 3
0
records = list(SeqIO.parse(handle, 'fasta'))

for i, record in enumerate(records):
    with open(ids[i], 'w') as f:
        SeqIO.write(record, f, 'fasta')

# Following step can be done in command line
# using 'needle'
needle_cl = NeedleCommandline()
needle_cl.asequence = ids[0]
needle_cl.bsequence = ids[1]
needle_cl.outfile = 'need_output.txt'

needle_cl.gapopen = 10
needle_cl.gapextend = 1
needle_cl.endopen = 10
needle_cl.endextend = 1
needle_cl.endweight = True

needle_cl()

# Score
with open('need_output.txt', 'r') as f:
    content = f.readlines()

for line in content:
    if 'Score' in line:
        score = float(line.split()[-1])
        print(score)
        break