Commit 2657000f authored by Pauline Pommeret's avatar Pauline Pommeret

[database] Tune up and a bit of doc.

parent d396dc2b
#!/usr/bin/env python2.7
#
# Copyright (C) 2014 Pauline Pommeret <pommeret@crans.org>
# Authors : Pauline Pommeret <pommeret@crans.org>,
# Jonas Sénizergues <senizergues@crans.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the Cr@ns nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
# HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
Delete a sequence from database.
"""
import argparse
from argparse import RawDescriptionHelpFormatter
import lib.database
if __name__ == "__main__":
DBCURSOR = lib.database.XylokPGCursor()
# -*- Parsing command-line arguments using argparse -*- #
# TEXT is a string that holds the description of the program
TEXT = """Delete sequence from database."""
# Creates the parser
PARSER = argparse.ArgumentParser(description=TEXT, formatter_class=RawDescriptionHelpFormatter)
# Fills the parser with the program arguments
PARSER.add_argument("seqid", type=int, help="The id of the sequence to remove.", action="store")
# Parses the arguments
ARGS = PARSER.parse_args()
# Prints something
if DBCURSOR.remove_seq(ARGS.seqid) >= 1:
print "Sequence %s has been successfully removed." % (ARGS.seqid,)
else:
print "Sequence %s does not exist." %(ARGS.seqid,)
......@@ -114,10 +114,10 @@ if __name__ == "__main__":
# Creates a Sequence object
seq = sequence.Sequence(fasta_file, md_parameters, alphabet=ARGS.alphabet, trx_scale_path=ARGS.trx_scale_file, sliding=ARGS.sliding, centering=ARGS.centering, alpha=ARGS.alpha, graph=ARGS.graph)
seq_id = DBCURSOR.check_sequence(seq)
seq_id, label = DBCURSOR.check_sequence(seq)
if seq_id:
print "This sequence is already in database (id=%s)." % (seq_id,)
sys.exit(0)
print "This sequence is already in database (id=%s, label=%s)." % (seq_id, label)
sys.exit(42)
# We have to build the DT only if we are certain that the sequence is
# not in the db, as it could alter the result of the DT.
......@@ -131,7 +131,9 @@ if __name__ == "__main__":
seq_id = DBCURSOR.store_sequence(seq)
# Done, moving on to next directory
print "Data stored in %r added to database under id %s" % (cur_dir, seq_id)
print "Data stored in %s added to database under id %s" % (cur_dir, seq_id)
data = DBCURSOR.fetch_averaged_specific_sequence(seq_id)
print PA[DT.predict(data)[0]]
label = PA[DT.predict(data)[0]]
print "Guessed label for sequence %s : %s" % (cur_dir, label)
DBCURSOR.label_sequence(seq_id, label)
This diff is collapsed.
......@@ -145,7 +145,7 @@ A .dat file must me organized this way:
# Creates a Sequence object
seq = sequence.Sequence(fasta_file, md_parameters, label, alphabet=ARGS.alphabet, trx_scale_path=ARGS.trx_scale_file, sliding=ARGS.sliding, centering=ARGS.centering, alpha=ARGS.alpha, graph=ARGS.graph)
seq_id = DBCURSOR.check_sequence(seq)
seq_id, label = DBCURSOR.check_sequence(seq)
if seq_id:
if raw_input("This sequence is already in database. Would you like to recompute its data? [y/n]") != "y":
continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment