Here you can find the source of formatProtein(String seq)
Parameter | Description |
---|---|
seq | Sequence to be formated. |
public static String formatProtein(String seq)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { /**//from w w w.java2 s . co m * Format a protein sequence in 6 columns per line, with 10 aa for each column. * * * @param seq Sequence to be formated. * @return Formated proteinSequence. */ public static String formatProtein(String seq) { StringBuilder sb = new StringBuilder(); int count = 0; boolean first = true; List<String> lineList = new ArrayList<>(); for (char c : seq.toCharArray()) { if (count % 60 == 0 && !first) { lineList.add(sb.toString().trim()); sb = new StringBuilder(); } first = false; if (count % 10 == 0) { sb.append(" "); } sb.append(c); count++; } lineList.add(sb.toString().trim()); sb = new StringBuilder(); for (String s : lineList) { sb.append(s).append("\n"); } return sb.toString().substring(0, sb.length() - 1); } /** * Format a protein sequence in 6 columns per line, with 10 aa for each column. * Considering a previous quantity of processed chars. * * @param seq Sequence to be formated. * @param jump How many chars to jump. * @return Formated proteinSequence. */ public static String formatProtein(String seq, int jump) { StringBuilder sb = new StringBuilder(); int count = jump; boolean first = true; List<String> lineList = new ArrayList<>(); for (char c : seq.toCharArray()) { if (count % 60 == 0 && !first) { lineList.add(sb.toString().trim()); sb = new StringBuilder(); } first = false; if (count % 10 == 0) { sb.append(" "); } sb.append(c); count++; } lineList.add(sb.toString().trim()); sb = new StringBuilder(); for (String s : lineList) { sb.append(s).append("\n"); } return sb.toString().substring(0, sb.length() - 1).trim(); } }