#coding:utf-8

from django.db import models
from mongoengine import *

#。db里面的表的命名的方式为：类_表名。例如：WebServer_Template_1，下方只填写表名。
# ID为主键，不需要定义； name 类型为字符串，长度为30，值为唯一 ； selected为布尔值。

class Qc(EmbeddedDocument):
    serial_no = StringField(max_length=200)
    lib_type = StringField(max_length=200)
    project_code = StringField(max_length=200)
    clean_per = FloatField()
    clean_reads = IntField()
    clean_bases = IntField()
    cleanq20 = FloatField()
    cleanq30 = FloatField()
    clean_n = FloatField()
    clean_gc = FloatField()
    raw_gc = FloatField()
    read_length = FloatField()
    adapter = FloatField()
    pool_lib_data = IntField()
    mapped = FloatField()
    paired = FloatField()
    insert = IntField()
    sd = StringField(max_length=100)
    duplication = FloatField()
    # ReferenceField相当于foreign key
    # qc_id = ReferenceField('Sample',reverse_delete_rule=CASCADE)
    # meta = {'allow_inheritance': True}

##
class Algin(EmbeddedDocument):
    clean_reads = IntField()
    mapped_reads = StringField(max_length=200)
    duplicate_reads = StringField(max_length=200)
    unique_reads = StringField(max_length=200)
    reads_unique_target = IntField()
    reads_unique_genome = IntField()
    total_baseson_target = IntField()
    total_basesnear_target = IntField()
    total_seqon_target = FloatField()
    total_seqnear_target = FloatField()
    total_effective_yield = FloatField()
    feb_on_target = StringField(max_length=200)
    feb_onnear_target = StringField(max_length=200)
    fraction_unique_target = StringField(max_length=200)
    avg_seqdepthon_target = FloatField()
    avg_seqdepthnear_target = FloatField()
    avg_insert_size = FloatField()
    base_coveredon_target = IntField()
    coverage_target_region = StringField(max_length=200)
    base_coverednear_target = IntField()
    coverage_near_target = StringField(max_length=200)
    mismatch_in_target = StringField(max_length=200)
    mismatch_in_total = StringField(max_length=200)
    fraction_coveredt_4x = StringField(max_length=200)
    fraction_covered_10x = StringField(max_length=200)
    fraction_covered_20x = StringField(max_length=200)
    fraction_covered_50x = StringField(max_length=200)
    # algin_id = ReferenceField('Sample',reverse_delete_rule=CASCADE)

class Snp(EmbeddedDocument):
    total_snp = IntField()
    genome1000_and_dbsnp150 = StringField(max_length=200)
    genome1000_only = StringField(max_length=200)
    dbsnp150_only = StringField(max_length=200)
    novel = StringField(max_length=200)
    het = StringField(max_length=200)
    homo = StringField(max_length=200)
    synonymous_snv = StringField(max_length=200)
    nonsynonymous_snv = StringField(max_length=200)
    exonic = StringField(max_length=200)
    intergenic = StringField(max_length=200)
    intronic = StringField(max_length=200)
    splicing_predicted = IntField()
    utr3 = IntField()
    utr5 = IntField()
    utr5_utr3 = FloatField()
    downstream = IntField()
    exonic_splicing = FloatField()
    ncrna_exonic = IntField()
    ncrna_exonic_splicing = FloatField()
    ncrna_intronic = IntField()
    ncrna_splicing = IntField()
    splicing = IntField()
    stopgain = IntField()
    stoploss = IntField()
    unknown_info = IntField()
    upstream = IntField()
    upstream_downstream = FloatField()
    ti_tv = FloatField()
    # snp_id = ReferenceField('Sample',reverse_delete_rule=CASCADE)

class Indel(EmbeddedDocument):
    total_indel = IntField()
    genome1000_and_dbsnp150 = StringField(max_length=200)
    dbsnp150_only = StringField(max_length=200)
    novel = StringField(max_length=200)
    het = StringField(max_length=200)
    homo = StringField(max_length=200)
    exonic = StringField(max_length=200)
    intergenic = StringField(max_length=200)
    intronic = StringField(max_length=200)
    utr3 = IntField()
    utr5 = IntField()
    utr5_utr3 = FloatField()
    downstream = IntField()
    exonic_splicing = IntField()
    frameshift_deletion = IntField()
    frameshift_insertion = IntField()
    ncrna_exonic = IntField()
    ncrna_exonic_splicing = FloatField()
    ncrna_intronic = IntField()
    nonframeshift_deletion = IntField()
    nonframeshift_insertion = IntField()
    splicing = IntField()
    stopgain = IntField()
    stoploss = IntField()
    unknown_info = IntField()
    upstream = IntField()
    upstream_downstream = FloatField()
    # indel_id = ReferenceField('Sample',reverse_delete_rule=CASCADE)
class Sample(Document):
    # required为True则必须赋予初始值
    bus_code = StringField(required=True, max_length=200)
    test_item = StringField(max_length=200)
    sample_type = StringField(max_length=100)
    sex = StringField(max_length=20)
    age= StringField(max_length=20)
    clinical_info = StringField(max_length=1000)
    body_check = StringField(max_length=1000)
    other_test_info = StringField(max_length=1000)
    is_ill = StringField(max_length=10)
    path = StringField(default="")
    probe = StringField(max_length=50)
    qc = EmbeddedDocumentListField(Qc)
    algin = EmbeddedDocumentListField(Algin)
    indel = EmbeddedDocumentListField(Indel)
    snp = EmbeddedDocumentListField(Snp)