Mercurial > repos > rliterman > csp2
diff CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/fileIO/MatrixFile.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/fileIO/MatrixFile.java Tue Mar 18 16:23:26 2025 -0400 @@ -0,0 +1,88 @@ +package fileIO; +import dna.Matrix; + + + +public class MatrixFile extends TextFile{ + + public static void main(String[] args){ + + try { + //Name of mat file + String name=args[0]; + + MatrixFile mat=new MatrixFile(name); + + String s=null; + + for(s=mat.readLine(); s!=null; s=mat.readLine()){ + System.out.println(s); + } + } catch (Exception e) { + throw new RuntimeException(e); + } + + } + + + public MatrixFile(String name){super(name, false);} + + @Override + public String nextLine(){ + String line=readLine(); + + while(line!=null && line.charAt(0)!='{' && line.charAt(0)!='/'){ + line=readLine(); + } + return line; + } + + public Matrix nextMatrix(){ + String line; + String[] split; + + line=nextLine(); + if(line==null || line.startsWith("//end")){return null;} + + assert(line.startsWith("//name: ")) : line; + String name=line.replace("//name: ","").trim(); + + line=nextLine(); + assert(line.startsWith("//size: ")) : line; + line=line.replace("//size: ",""); + split=line.split("x"); + int length=Integer.parseInt(split[0]); + int width=Integer.parseInt(split[1]); + + line=nextLine(); + assert(line.startsWith("//prefix: ")) : line; + line=line.replace("//prefix: ",""); + int prefix=Integer.parseInt(line); + + line=nextLine(); + assert(line.startsWith("//count: ")) : line; + line=line.replace("//count: ",""); + int count=Integer.parseInt(line); + + + float[][] grid=new float[length][width]; + for(int i=0; i<length; i++){ + line=nextLine(); + + while(line.startsWith("//")){line=nextLine();} + + assert(line.startsWith("{")); + if(line.endsWith(",")){line=line.substring(0, line.length()-1);} + assert(line.endsWith("}")); + line=line.replace("{", "").replace("}", "").replace(" ", ""); + split=line.split(","); + assert(split.length==width); + for(int j=0; j<split.length; j++){ + grid[i][j]=Float.parseFloat(split[j]); + } + } + + return new Matrix(grid, prefix, name); + } + +}