⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genomeimage.java

📁 实现了基因组的显示功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
									send=feature.getLocation().getRangeList().get(0).getEnd();
									if(sstart > positionStart && send < positionEnd)
									{
										drawOperon(g2,sstart,send);
									}
									hasOperon = false;
								}							
							}
						}
						
					/*	if(q.getName() == "pmap")
						{
							
							pmapvalue = q.getValue(); 
							String wuzhongname;
							String pathwayname;
							String genename;
							StringTokenizer stringtokenizer = new StringTokenizer(pmapvalue,":");
							wuzhongname = stringtokenizer.nextToken();
							pathwayname = stringtokenizer.nextToken();
							genename = stringtokenizer.nextToken();
							System.out.print(genename);
							System.out.print(";");
							if(wuzhongname.equals(pathway.getOrganismName())&&pathwayname.equals(pathway.getName()))
							{
								System.out.print(wuzhongname);
								System.out.print(";");
								System.out.print(pathwayname);
								System.out.print(";");
								int x2 = findPoint(pathway,genename);
								System.out.print(x2);
								System.out.print(";");
								g2.setColor(Color.BLACK);
								//g2.drawLine(x1, y1, x2, y2)
								g2.drawLine(x1, 50, x2, 77);
							}
						}*/
						if(q.getName().equals("pmap"))
						{
							Iterator itrrrr = pathway.getNodes().iterator();
							if(itrrrr.hasNext())
							{
								pmapvalue = q.getValue();
								StringTokenizer stringtokenizer = new StringTokenizer(pmapvalue,":");
								stringtokenizer.nextToken();
								//stringtokenizer.nextToken();
								int x2 = findPoint(pathway,stringtokenizer.nextToken());
								//System.out.print(q.getValue());
								//System.out.print(";");
								//System.out.print(x2);
								//System.out.print(";");
								g2.setColor(Color.BLACK);
								//g2.drawLine(x1, y1, x2, y2)
								if((x1>positionStart)&&(x1<=positionEnd))
								{
									g2.drawLine(x1, 50, x2, 120);
								}
							}
						}
					}
				}
			if(hasOperon)
			{
				//drawOperon(g2,sstart,send);
			}
		}
		
		File f = new File(fileName);
		try {
			ImageIO.write(image, "jpg", f);
		} catch (Exception e) {
			System.out.println ("filename" + fileName);
			e.printStackTrace();
		}
		}
		return ratio;
	}
	public int findPoint(Pathway pathway,String genename)
	{
		int p = 0;
		List <PathwayNode> nodes = pathway.getNodes();
		PathwayNode node;
		Iterator itr = nodes.iterator();
		int numberofnode = 0;
		long eachlong = 0;
		while(itr.hasNext())
		{
			numberofnode++;
			itr.next();
		}
		Iterator itrr = nodes.iterator();
		if(numberofnode != 0)
		{
			eachlong = (int)(new Double(maxLength) / new Double(numberofnode));
			for(int i = 0;i<numberofnode;i++)
			{
				node = (PathwayNode)itrr.next();
				if(node.getGeneName().equals(genename))
				{
					p = (int)(i * eachlong + eachlong*3/4);
				}
			}
		}
		return p+20;
	}
	public void drawPathway(Graphics2D g,Pathway pathway,long pStart,long pEnd)
	{
		List <PathwayNode> nodes = pathway.getNodes();
		Iterator itr = nodes.iterator();
		int numberofnode = 0;
		long eachlong = 0;
		while(itr.hasNext())
		{
			numberofnode++;
			itr.next();
		}
		if(numberofnode != 0)
		{
			eachlong = (int)(new Double(pEnd) / new Double(numberofnode));
		}
		//itr = nodes.iterator();
		Font fcb25 = new Font("Courier",Font.BOLD,10);
	    g.setColor(Color.BLACK);
		g.setFont(fcb25);
		g.drawString("PathwayName:"+pathway.getName()+" OrganismName:"+pathway.getOrganismName(), pStart, 160);
		for(int i = 0;i<numberofnode;i++)
		{
			g.setColor(Color.BLACK);
			g.drawLine((int)(pStart+(long)i*eachlong), 125, (int)((pStart+(long)i*eachlong)+new Double(eachlong)/2), 125);
			g.setColor(Color.GREEN);
			g.drawRect((int)((pStart+(long)i*eachlong)+new Double(eachlong)/2), 120, (int)(eachlong/2), 10);
			g.fillRect((int)((pStart+(long)i*eachlong)+new Double(eachlong)/2), 120, (int)(eachlong/2), 10);
			Font fcb24 = new Font("Courier",Font.BOLD,10);
		    g.setColor(Color.BLACK);
			g.setFont(fcb24);
			g.drawString(pathway.getNodes().get(i).getGeneName(),(int)((pStart+(long)i*eachlong)+new Double(eachlong)/2), 140);
		}
		
		//g.drawLine((int)(pStart+20), 52, (int)(pEnd-20), 52);
	}
	public void drawOperon(Graphics2D g,long pStart,long pEnd)
	{
		g.setColor(Color.BLACK);
		g.drawRect((int)(Math.round(ratio*pStart)+20), 35, (int)(Math.abs(Math.round(ratio*pEnd)-Math.round(ratio*pStart)+1)), 20);
	}
	public void putScales (Graphics2D g, int start) {
		int numberOfIntervals = (int)Math.round(new Double(maxLength).doubleValue() / new Double(intervalLength).doubleValue());
		
		int i= 0;
		int y= 20; 
	    
		while (i <= numberOfIntervals) {
			Font fcb24 = new Font("Courier",Font.BOLD,10);
		    g.setFont(fcb24);
			g.drawString(String.valueOf(Math.round((y-20)/ratio)+start),y,10+6*(i-Math.round(i/2)*2));
			g.drawRect(y, 21, 1, 3);
			y += intervalLength;
			i++;
		}
	}
	
	public int drawFeature (Feature f, Graphics2D g, long pStart, long pEnd) {
		Location location = f.getLocation();
		//TODO handle other types of Locations (join etc.), and multiple Ranges
		Range range = location.getRangeList().get(0);
		long s = range.getStart();
		long e = range.getEnd();
		
		int x = 0;
		long numPointY = f.getFrame();
		
		if (numPointY == -1) {
			numPointY = 4;
		}
		else if (numPointY == -2) {
			numPointY = 5;
		}
		else if (numPointY == -3) {
			numPointY = 6;
		}
		
		//int direction;
		
		//if (s<e){
		if (!f.isComplement()) {
			g.setColor(Color.BLUE);
			//numPointY = (s - (int)(s/3)*3)+1;
			//direction = 1;
		}
		else{
			g.setColor(Color.RED);
			//numPointY = (s - (int)(s/3)*3)+4;
			//direction = -1;
		}
		
		// make sure feature is within the current segment
		if (isInside (s, e, pStart, pEnd)) {
			if (s < pStart) {
				//s = 0;
				s = pStart;
			}
			if (pEnd > 0 && e > pEnd) {
				//e = maxLength;
				e=pEnd;
			}
			System.out.print(s);
			System.out.print(";");
			System.out.print(e);
			System.out.print(";");
			long startPoint =Math.round(s*ratio);
			long endPoint = Math.round(e*ratio);
			long length = Math.abs(endPoint - startPoint + 1);
		//	long startPointY = 30*numPointY + 20; // for frames, put this line
			long startPointY = 40;  // no frames, put this line
			startPoint=startPoint-Math.round(pStart*ratio);
			startPoint = startPoint + 20;
			g.drawRect((int)startPoint, (int)startPointY, (int)length, 10);
			g.fillRect((int)startPoint, (int)startPointY, (int)length, 10);
			
			/*Polygon poly2= new Polygon();
			
			poly2.addPoint((int)startPoint,(int)startPointY + 5);
		    poly2.addPoint((int)startPoint + 6*direction,(int)startPointY - 2);
		    poly2.addPoint((int)startPoint + 6*direction,(int)startPointY);
		    poly2.addPoint((int)startPoint + ((int)length-7)*direction,(int)startPointY);
		    poly2.addPoint((int)startPoint + ((int)length-7)*direction,(int)startPointY + 10);
		    poly2.addPoint((int)startPoint + 6*direction,(int)startPointY + 10);
		    poly2.addPoint((int)startPoint + 6*direction,(int)startPointY + 12);
		    
		    g.drawPolygon(poly2);
		    g.fillPolygon(poly2);*/
			
			g.setFont(new Font("Serif", Font.PLAIN, 10));	
			x = (int)(startPoint+length/2);
		}		
		return x;
	}
	
	boolean isInside (long start, long end, long positionStart, long positionEnd) {
		boolean inside = true;
		/*if (positionStart > 0 || positionEnd > 0) {
			if (start < positionStart && end < positionStart) {
				inside = false;
			} else if (positionEnd != -1 && start > positionEnd) {
				inside = false;
			} else if (positionStart != -1 && end < positionStart) {
				inside = false;
			}
		}*/
		
			if (start < positionStart && end < positionStart)
			{inside = false;}
			else if(start>positionEnd && end>positionEnd)
			{inside = false;}
		
		return inside;
	}
	
	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public int getMaxLength() {
		return maxLength;
	}

	public void setMaxLength(int maxLength) {
		this.maxLength = maxLength;
	}

	public int getIntervalLength() {
		return intervalLength;
	}

	public void setIntervalLength(int intervalLength) {
		this.intervalLength = intervalLength;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -