Ejemplo n.º 1
0
    def test_model_sequence(self):
        """Test to make sure that Sequence is working properly.
        """

        sequence = Sequence()
        sequence.save()

        db.session.commit()
Ejemplo n.º 2
0
    def setUpClass(cls):
        database.clean()
        cls.word1 = Word(lemma="bar")
        cls.word2 = Word(lemma="baz")
        cls.word3 = Word(lemma="bar")
        cls.word4 = Word(lemma="qux")

        sequence1 = Sequence(words=[cls.word1, cls.word2])
        sequence2 = Sequence(words=[cls.word4])
        sequence3 = Sequence(words=[cls.word3])
        cls.sequenceset1 = SequenceSet(sequences=[sequence1, sequence2])
        cls.sequenceset2 = SequenceSet(sequences=[sequence3])

        db.session.add_all([
            sequence1, sequence2, sequence3, cls.sequenceset1,
            cls.sequenceset2, cls.word1, cls.word2, cls.word3, cls.word4
        ])
        db.session.commit()
Ejemplo n.º 3
0
    def test_model_sentence(self):
        """Test to make sure that Sentence is working properly.
        """

        text = "hello world"
        sentence = Sentence()
        sentence.text = text

        assert sentence.text == text

        word_1 = Word(lemma="hello")
        word_2 = Word(lemma="world")

        sentence.words.append(word_1)
        sentence.words.append(word_2)

        assert sentence.words == [word_1, word_2]

        sentence.save()

        #Test with Dependencies
        dependency1 = Dependency()
        dependency2 = Dependency()

        sentence.dependencies = [dependency1, dependency2]

        db.session.add_all([dependency1, dependency2])
        db.session.commit()

        #Test with Sequences
        sequence1 = Sequence()
        sequence2 = Sequence()

        sentence.sequences = [sequence1, sequence2]

        db.session.add_all([sequence1, sequence2])
        db.session.commit()

        #Test with Project
        project = Project()
        sentence.project = project
        db.session.add_all([project])
        db.session.commit()
Ejemplo n.º 4
0
 def commit(self, commit='true'):
     if commit =='true':
         for k in list(self.collection.keys()):
             rd_id,seq = k
             count = self.collection[k]
             if count > self.commit_threshold:  # only over 2 count sequence will be committed.
                 # self.collection.pop(k)
                 self.length_count[len(seq)]+=count
                 # self.commit_result[k]+=count
                 self.set_commit_result(rd_id, count)
                 sequence = Sequence.query.filter_by(aptamer_seq=seq).first()
                 if sequence:
                     seqround = SeqRound.query.filter_by(sequence=sequence,rounds_id=rd_id).first()
                     if seqround:
                         seqround.count += count
                     else:
                         seqround = SeqRound(sequence=sequence, rounds_id=rd_id, count=count)
                         db.session.add(seqround)
                 else:
                     sequence = Sequence(aptamer_seq=seq,known_sequence_id=self.ks.get(seq,None))
                     db.session.add(sequence)
                     seqround = SeqRound(sequence=sequence, rounds_id=rd_id, count=count)
                     db.session.add(seqround)
         db.session.commit()
     elif commit=='retract':
         for k in list(self.collection.keys()):
             rd_id, seq = k
             count = self.collection[k]
             if count > self.commit_threshold:
                 # self.collection.pop(k)
                 sequence = Sequence.query.filter_by(
                     aptamer_seq=seq).first()
                 seqround = SeqRound.query.filter_by(
                     sequence=sequence, rounds_id=rd_id).first()
                 if seqround:
                     seqround.count -= count
                     if seqround.count < 1:
                         db.session.delete(seqround)
         db.session.commit()
     else:
         for (rd_id, seq), count in self.collection.items():
             if count > self.commit_threshold:  # only over 2 count sequence will be committed.
                 # self.collection.pop(k)
                 self.length_count[len(seq)] += count
                 # self.commit_result[k] += count
                 self.set_commit_result(rd_id,count)
Ejemplo n.º 5
0
    def test_add_sequence(self):
        """Test the ``add_sequence()`` method of ``Sentence``.
        """

        project = Project()
        sentence = Sentence(text="foo", project=project)
        sequence = Sequence(lemmatized=False)

        project.save()
        sentence.save()
        sequence.save()

        rel = sentence.add_sequence(sequence, position=1, project=project)

        assert rel.sequence == sequence
        assert rel.sentence == sentence
        assert rel.position == 1
        assert rel.project == project
Ejemplo n.º 6
0
    for k in i.fof1:
        atpase = ATPase(source=i.name,
                        organism=organism,
                        fof1_type=k.type,
                        subunit_list=', '.join(k.subunit_names))
        db.session.add(atpase)
        db.session.commit()
        for j in range(int(k.operon_num)):
            operon = 0
            operon = Operon(enzyme=atpase,
                            organism=organism,
                            operon_type=k.operon_type[j])
            db.session.add(operon)
            db.session.commit()
            for h in k.subunits:
                if int(h.operon) == j + 1:
                    print(h.field_type, h.seq, h.start, h.end)
                    subunit = Sequence(subunit_name=h.field_type,
                                       subunit_id_ncbi=h.id,
                                       sequence=h.seq,
                                       start=h.start,
                                       stop=h.end,
                                       direction=h.direction,
                                       operon=operon)
                    db.session.add(subunit)
                    db.session.commit()
#db.session.commit()

#e = Organism(name = 'lol', taxonomy = 'top kek', org_type = 'bacterial', fof1_number = len(i.fof1), operon_number = int(op_num))
#db.session.add(organism)
#db.session.commit()
Ejemplo n.º 7
0
    return a

get_operon_num(organism_list[6])

for i in organism_list:
    op_num = get_operon_num(i)
    organism = Organism(name = i.name, org_id_ncbi = i.id, taxonomy = i.taxonomy, org_type = 'bacterial', fof1_number = len(i.fof1), operon_number = int(op_num), org_comment = 'No comment yet')
    #db.session.add(organism)
    for k in i.fof1:
        atpase = ATPase(source = i.name, fof1_type = k.type, subunit_list = ", ".join(k.subunit_names), organism = organism)
        #db.session.add(atpase)
        for j in range(int(k.operon_num)):
            operon = 0
            operon = Operon(number = j+1, enzyme = atpase, organism = organism)
            #db.session.add(operon)
            for h in k.subunits:
                if int(h.operon) == j+1:
                    print(h.field_type, h.start, h.end)
                    subunit = Sequence(subunit_name = h.field_type, subunit_id_ncbi = h.id, sequence = h.seq, start = h.start, stop = h.end, seq_operon_number = h.operon, seq_comment = 'No comments yet', operon = operon)
                    #db.session.add(subunit)
#db.session.commit()




# In[11]:


Sequence.query.all()

Ejemplo n.º 8
0
        atpase = ATPase(source=i.name, fof1_type=k.type, organism=organism)
        db.session.add(atpase)
        db.session.commit()
        for j in k.operons:
            sub_li = []
            for sub in j.subunits:
                sub_li.append(sub.field_type)
            operon = 0
            operon = Operon(operon_type=j.type,
                            operon_number=j.number,
                            subunit_list=", ".join(sub_li),
                            enzyme=atpase,
                            organism=organism)
            db.session.add(operon)
            db.session.commit()
            for h in j.subunits:
                subunit = Sequence(subunit_name=h.field_type,
                                   subunit_id_ncbi=h.id,
                                   sequence=h.seq,
                                   start=h.start,
                                   stop=h.end,
                                   seq_comment=h.comment,
                                   operon=operon)
                db.session.add(subunit)
                db.session.commit()
db.session.commit()

# In[19]:

Sequence.query.all()
Ejemplo n.º 9
0
from Bio import SeqIO
from config import Config
from app.models import Sequence
import re
from app.__init__ import db
import sqlalchemy
from app.routes import bonus_one

with open(Config.SEED_DATA_LOCATION, 'rU') as handle:
    for record in SeqIO.parse(handle, 'fasta'):
        sequence = Sequence(name=record.name.split('|')[1],
                            description=record.description,
                            sequence=str(record.seq))
        db.session.add(sequence)
db.session.commit()
db.session.close()