package fileIO; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import dna.Gene; import shared.Shared; /** For loading UCSC .chain files that convert one genome build to another. */ public class ChainBlock implements Comparable{ public static void main(String args[]){ ChainLine[][] lines=loadChainLines(args[0]); for(int i=1; i<=22; i++){ for(ChainLine line : lines[i]){ System.out.println(line); } System.out.println(); } } public ChainBlock(List list){ String[] head=list.get(0); assert("chain".equals(head[0])); score=Long.parseLong(head[1]); tName=head[2]; tChrom=toChromosome(head[2]); tSize=Integer.parseInt(head[3]); tStrand=Gene.toStrand(head[4]); tStart=Integer.parseInt(head[5]); tStop=Integer.parseInt(head[6]); qName=head[7]; qChrom=toChromosome(head[7]); qSize=Integer.parseInt(head[8]); qStrand=Gene.toStrand(head[9]); qStart=Integer.parseInt(head[10]); qStop=Integer.parseInt(head[11]); chainID=Integer.parseInt(head[12]); chunks=new int[list.size()-1][]; for(int i=1; i1){ tloc=tloc2+chunk[1]+1; qloc=qloc2+chunk[2]+1; } } }else{ int tloc=tStart, qloc=qStop-1; for(int i=0; i1){ tloc=tloc2+chunk[1]+1; qloc=qloc2-chunk[2]-1; } } } return out; } public static ChainLine[][] loadChainLines(String fname){ ArrayList list=loadChainBlocks(fname); ChainBlock[][] blocks=splitChain(list); ChainLine[][] out=new ChainLine[blocks.length][]; ArrayList temp=new ArrayList(); for(int chrom=0; chrom0){ for(ChainBlock block : cblocks){ ChainLine[] blines=block.toLines(); for(ChainLine line : blines){ temp.add(line); } } } if(temp.size()>0){ out[chrom]=temp.toArray(new ChainLine[temp.size()]); Arrays.sort(out[chrom]); } } return out; } public static ArrayList loadChainBlocks(String fname){ TextFile tf=new TextFile(fname, false); String[] lines=tf.toStringLines(); tf.close(); String[][] text=TextFile.doublesplitWhitespace(lines, true); ArrayList out=new ArrayList(); ArrayList current=new ArrayList(40); for(int i=0; i list){ int[] size=new int[Gene.chromCodes.length]; for(ChainBlock cb : list){size[cb.tChrom]++;} ChainBlock[][] out=new ChainBlock[size.length][]; for(int i=0; i