| 1 | package driver; |
| 2 | |
| 3 | import java.util.HashSet; |
| 4 | |
| 5 | import fileIO.TextFile; |
| 6 | |
| 7 | public class GetUniquePrefixes { |
| 8 | |
| 9 | public static void main(String[] args){ |
| 10 | |
| 11 | |
| 12 | String fname=args[0]; |
| 13 | int prefix=Integer.parseInt(args[1]); |
| 14 | TextFile tf=new TextFile(fname); |
| 15 | |
| 16 | HashSet<String> set=new HashSet<String>(); |
| 17 | |
| 18 | String header=null; |
| 19 | StringBuilder sequence=new StringBuilder(); |
| 20 | for(String line=tf.nextLine(); line!=null; line=tf.nextLine()){ |
| 21 | if(line.startsWith(">")){ |
| 22 | if(sequence.length()>0){ |
| 23 | if(sequence.length()>prefix){sequence.setLength(prefix);} |
| 24 | String s=sequence.toString(); |
| 25 | if(set.contains(s)){} |
| 26 | else{ |
| 27 | set.add(s); |
| 28 | System.out.println(header+"\n"+s); |
| 29 | } |
| 30 | } |
| 31 | sequence.setLength(0); |
| 32 | header=line; |
| 33 | }else{ |
| 34 | sequence.append(line); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | |
| 40 | } |