def to_comet_parameter(self) -> str:
        """
        Returns the modifications as comet parameter. If the the modification is static, the result is ready to use.
        If the modification is variable or terminus modification, the resulting string contains a placeholder ('|i') for the variable modification index and another one ('|v') for the variable modification maximum.
        Remember Comet allows only 9 variable modifications in total.

        Returns
        -------
        Mostly ready to use Comet configuration string of the modification
        """
        if self.is_static and not self.is_terminus_modification:
            return "add_{}_{} = {}".format(self.amino_acid.one_letter_code, self.amino_acid.name.lower().replace(" ", "_"), mass_to_float(self.delta))
        elif self.is_static and self.is_position_n_terminus:
            return "add_Nterm_peptide = {}".format(mass_to_float(self.delta))
        elif self.is_static and self.is_position_c_terminus:
            return "add_Cterm_peptide = {}".format(mass_to_float(self.delta))
        elif self.is_variable and not self.is_terminus_modification:
            return "variable_mod0|i = {} {} 0 |v -1 2 0 0.0".format(
                mass_to_float(self.delta),
                self.amino_acid.one_letter_code
            )
        elif self.is_variable and self.is_position_n_terminus:
            return "variable_mod0|i = {} {} 0 |v 0 2 0 0.0".format(
                mass_to_float(self.delta),
                self.amino_acid.one_letter_code
            )
        elif self.is_variable and self.is_position_c_terminus:
            return "variable_mod0|i = {} {} 0 |v 0 3 0 0.0".format(
                mass_to_float(self.delta),
                self.amino_acid.one_letter_code
            )
    def to_csv_row(self) -> Iterator[ByteString]:
        """
        Yields the peptide as CSV row

        Yields
        ------
        Iterator[ByteString]
            CSV row with 2 or 7 columns, depending if the peptide was queried with metadata
        """
        yield str(mass_to_float(self.mass)).encode("utf-8")
        # At this point only string values are added to the cssv, so we quote them for better compatibility
        yield b",\""
        yield self.sequence.encode("utf-8")
        yield b"\","
        yield str(self.number_of_missed_cleavages).encode("utf-8")
    def __str__(self):
        result = ""
        for combination in self.__modification_collection_list:
            mass = ""
            amino_acid_counts = []

            for condition in combination.where_conditions:
                if not self.__with_partition and condition.column_name == "partition":
                    continue
                output = f"{condition.column_name} {condition.operator}"
                if condition.column_name == "mass":
                    mass = output % tuple(
                        [mass_to_float(mass) for mass in condition.values])
                else:
                    amino_acid_counts.append(output % condition.values)
            amino_acid_counts.sort()
            result += f"{mass} ({' & '.join(amino_acid_counts)})"
            result += "\n"
        return result.replace(" BETWEEN", ":").replace("AND", "-")
    def to_json(self, close: bool = True) -> Iterator[ByteString]:
        """
        Generator which yields the peptides as a json formatted string

        Arguments
        ---------
        close : bool
            If true a closing bracket is added, default True

        Yields
        ------
        Iterator[ByteString]
            JSON formatted string.
        """
        yield b"{\"mass\":"
        yield str(mass_to_float(self.mass)).encode("utf-8")
        yield b",\"sequence\":\""
        yield self.sequence.encode("utf-8")
        yield b"\",\"length\":"
        yield str(self.length).encode("utf-8")
        yield b",\"number_of_missed_cleavages\":"
        yield str(self.number_of_missed_cleavages).encode("utf-8")  #
        if close:
            yield b"}"
Example #5
0
    def sequence_mass(sequence):
        peptide = Peptide(sequence, 0)

        return jsonify({'mass': mass_to_float(peptide.mass)})