class SequenceSerializer(serializers.ModelSerializer): _id = ObjectIdField(read_only=True) owner = serializers.ReadOnlyField(source="owner.username") project__id = serializers.CharField(source='project.id') project__title = serializers.CharField(source='project.title') biosample__id = serializers.CharField(source='biosample.id') biosample__ScientificName = serializers.CharField( source='biosample.ScientificName') seqstat__id = serializers.CharField(source='seqstat.id') seqstat__r_Reads = serializers.IntegerField(source='seqstat.r_Reads') seqstat__r_Yield = serializers.CharField(source='seqstat.r_Yield') seqstat__r_GeeCee = serializers.CharField(source='seqstat.r_GeeCee') seqstat__r_MinLen = serializers.CharField(source='seqstat.r_MinLen') seqstat__r_AvgLen = serializers.CharField(source='seqstat.r_AvgLen') seqstat__r_MaxLen = serializers.CharField(source='seqstat.r_MaxLen') seqstat__r_AvgQual = serializers.CharField(source='seqstat.r_AvgQual') seqstat__r_ErrQual = serializers.CharField(source='seqstat.r_ErrQual') seqstat__r_Ambiguous = serializers.CharField(source='seqstat.r_Ambiguous') seqstat__q_Reads = serializers.CharField(source='seqstat.q_Reads') seqstat__q_Yield = serializers.CharField(source='seqstat.q_Yield') seqstat__q_GeeCee = serializers.CharField(source='seqstat.q_GeeCee') seqstat__q_MinLen = serializers.CharField(source='seqstat.q_MinLen') seqstat__q_AvgLen = serializers.CharField(source='seqstat.q_AvgLen') seqstat__q_MaxLen = serializers.CharField(source='seqstat.q_MaxLen') seqstat__q_AvgQual = serializers.CharField(source='seqstat.q_AvgQual') seqstat__q_ErrQual = serializers.CharField(source='seqstat.q_ErrQual') seqstat__q_Ambiguous = serializers.CharField(source='seqstat.q_Ambiguous') class Meta: model = Sequence fields = "__all__"
class AccountSerializer(serializers.ModelSerializer): _id = ObjectIdField(read_only=True) def create(self, validated_data): password = validated_data.pop('password', None) instance = self.Meta.model(**validated_data) if password is not None: instance.set_password(password) instance.save() return instance def update(self, instance, validated_data): instance.username = validated_data.get('username', instance.username) instance.email = validated_data.get('email', instance.email) password = validated_data.pop('password', None) if password is not None: instance.set_password(password) instance.save() return instance class Meta: model = Account fields = ('email', 'username', 'password', '_id', 'projects', 'biosamples') extra_kwargs = {'password': {'write_only': True}}
class SeqstatSerializer(serializers.ModelSerializer): _id = ObjectIdField(read_only=True) owner = serializers.ReadOnlyField(source="owner.username") class Meta: model = Seqstat fields = "__all__"
class ProjectSerializer(serializers.ModelSerializer): _id = ObjectIdField(read_only=True) owner = serializers.ReadOnlyField(source="owner.username") #sequences = serializers.StringRelatedField(many=True) sequences = serializers.HyperlinkedRelatedField( many=True, read_only=True, view_name='seq:sequence-detail') class Meta: model = Project fields = "__all__"
class BioSampleSerializer(serializers.ModelSerializer): _id = ObjectIdField(read_only=True) project__id = serializers.ReadOnlyField(source='project.id') project__title = serializers.ReadOnlyField(source='project.title') owner = serializers.ReadOnlyField(source="owner.username") sequences = serializers.HyperlinkedRelatedField( many=True, read_only=True, view_name='seq:sequence-detail') class Meta: model = BioSample fields = "__all__"
class StatsSerializer(serializers.ModelSerializer): _id = ObjectIdField(read_only=True) owner = serializers.ReadOnlyField(source='owner.username') assembly__biosample__project__id = serializers.ReadOnlyField( source='assembly.biosample.project.id') assembly__biosample__project__title = serializers.ReadOnlyField( source='assembly.biosample.project.title') biosample__id = serializers.ReadOnlyField(source='assembly.biosample.id') assembly__biosample__sampleType = serializers.ReadOnlyField( source='assembly.biosample.sampleType') class Meta: model = Stats fields = '__all__' read_only_fields = ['owner'] ordering = ['assembly__biosample__project__id']
class AssemblySerializer(serializers.ModelSerializer): _id = ObjectIdField(read_only=True) owner = serializers.ReadOnlyField(source='owner.username') # reterieve fields from the related collection biosample__sampleType = serializers.ReadOnlyField( source='biosample.sampleType') biosample__ScientificName = serializers.ReadOnlyField( source='biosample.ScientificName') biosample__project__id = serializers.ReadOnlyField( source='biosample.project.id') biosample__project__title = serializers.ReadOnlyField( source='biosample.project.title') class Meta: model = Assembly fields = '__all__' read_only_fields = ['owner'] ordering = ['biosample__project__id']
class MlstSerializer(FlattenMixin, serializers.ModelSerializer): _id = ObjectIdField(read_only=True) owner = serializers.ReadOnlyField(source='owner.username') assembly__biosample__project__id = serializers.ReadOnlyField( source='assembly.biosample.project.id') assembly__biosample__project__title = serializers.ReadOnlyField( source='assembly.biosample.project.title') assembly_biosample__id = serializers.ReadOnlyField( source='assembly.biosample.id') assembly__biosample__sampleType = serializers.ReadOnlyField( source='assembly.biosample.sampleType') class Meta: model = Mlst fields = '__all__' ordering = ['assembly__biosample__project__id'] read_only_fields = ['owner'] flatten = ["profile"]
class ResistomeSerializer(FlattenMixin, serializers.ModelSerializer): _id = ObjectIdField(read_only=True) owner = serializers.ReadOnlyField(source='owner.username') #assembly = serializers.ReadOnlyField(source='assembly.id') # reterieve fields from the related collection assembly__biosample__project__id = serializers.ReadOnlyField( source='assembly.biosample.project.id') assembly__biosample__project__title = serializers.ReadOnlyField( source='assembly.biosample.project.title') assembly__biosample__id = serializers.ReadOnlyField( source='assembly.biosample.id') assembly__biosample__sampleType = serializers.ReadOnlyField( source='assembly.biosample.sampleType') class Meta: model = Resistome ordering = ['assembly__biosample__project__id'] fields = '__all__' read_only_fields = ['owner'] flatten = ["profile"]