コード例 #1
0
def save_references(request):
    """
    SGD_features.tab format looks like this:
         0) Primary SGDID (mandatory)
         1) Feature type (mandatory)
         2) Feature qualifier (optional)
         3) Feature name (optional)
         4) Standard gene name (optional)
         5) Alias (optional, multiples separated by |)
         6) Parent feature name (optional)
         7) Secondary SGDID (optional, multiples separated by |)
         8) Chromosome (optional)
         9) Start_coordinate (optional)
        10) Stop_coordinate (optional)
        11) Strand (optional)
        12) Genetic position (optional)
        13) Coordinate version (optional)
        14) Sequence version (optional)
        15) Description (optional)
    """
    featuresFile = request.FILES['features_file']
    features = [x.split('\t') for x in featuresFile.read().splitlines()]
    for line in features:
        reference = Reference()
        reference.sgdid = line[0]
        reference.feature_type = line[1]
        if line[2]:
            reference.qualifier = line[2]
        if line[3]:
            reference.feature_name = line[3]
        if line[4]:
            reference.standard_name = line[4]
        if line[5]:
            reference.aliases = line[5]
        if line[6]:
            reference.parent_name = line[6]
        if line[7]:
            reference.secondary_sgdid = line[7]
        if line[15]:
            reference.description = line[15]

        reference.createdDate = datetime.datetime.now()
        reference.modifiedDate = datetime.datetime.now()

        reference.save()
    return HttpResponseRedirect('/strains/')